Git Product home page Git Product logo

inappviewdebugger's Introduction

InAppViewDebugger

License CocoaPods Carthage compatible

InAppViewDebugger

InAppViewDebugger is a library that implements a view debugger with a 3D snapshot view and a hierarchy view, similar to Reveal and Xcode's own view debugger. The key distinction is, as the project title suggests, that this can be embedded inside the app and used on-device to debug UI issues without needing to be tethered to a computer.

Features

  • 3D snapshot view implemented in SceneKit: Gesture controls for zooming, panning, and rotating.
  • Hierarchy (tree) view that synchronizes its selection with the 3D view: This is a feature I really wanted in Xcode, to be able to visually find a view and see where it is in the hierarchy view
  • Support for iPad and iPhone: Layouts are designed specifically for each form factor.
  • Extensible: The base implementation supports UIView hierarchies, but this is easily extensible to support any kind of UI framework (e.g. CoreAnimation or SpriteKit)

Requirements

  • iOS 11.0+
  • Xcode 10.1+ (framework built for Swift 4.2)

Installation

CocoaPods

Add the following line to your Podfile:

pod 'InAppViewDebugger', '~> 1.0.3'

Carthage

Add the following line to your Cartfile:

github "indragiek/InAppViewDebugger" "1.0.3"

Usage

Swift

import InAppViewDebugger

@IBAction func showViewDebugger(sender: AnyObject) {
  InAppViewDebugger.present()
}

Objective-C

@import InAppViewDebugger;

// alternative import (they're the same):
// #import <InAppViewDebugger/InAppViewDebugger-Swift.h>

- (IBAction)showViewDebugger:(id)sender {
  [InAppViewDebugger present];
}

lldb

(lldb) expr -lswift -- import InAppViewDebugger
(lldb) expr -lswift -- InAppViewDebugger.present()

The present function shows the UI hierarchy for your application's key window, presented over the top view controller of the window's root view controller. There are several other methods available on InAppViewDebugger for presenting a view debugger for a given window, view, or view controller.

Controls

Focusing on an Element

To focus on the subhierarchy of a particular element, long press on the element to bring up the action menu and tap "Focus". The long press can be used both in the hierarchy view and the 3D snapshot view. The "Log Description" action will log the description of the element to the console, so that if you're attached to Xcode you can copy the address of the object for further debugging.

Focusing on an Element

Adjusting Distance Between Levels

The slider on the bottom left of the snapshot view can be used to adjust the spacing between levels of the hierarchy:

Adjusting Distance Between Levels

Adjusting Visible Levels

The range slider on the bottom right of the snapshot view can be used to adjust the range of levels in the hierarchy that are visible:

Adjusting Visible Levels

Showing/Hiding Headers

Each UI element has a header above it that shows its class name. These headers can be hidden or shown by long pressing on an empty area of the snapshot view to bring up the action menu:

Showing/Hiding Headers

Showing/Hiding Borders

Similarly to the headers, the borders drawn around each element can also be shown or hidden:

Showing/Hiding Borders

Customization

Colors, fonts, and other attributes for both the snapshot view and the hierarchy view can be changed by creating a custom Configuration. The configuration is then passed to a function like InAppViewDebugger.presentForWindow(:configuration:completion:).

Extending for Other UI Frameworks

The current implementation only supports UIView hierarchies, but this can easily be extended to support other UI frameworks by conforming to the Element protocol. See ViewElement to see what an example implementation looks like โ€” by providing a the frame, a snapshot image, and a few other pieces of information, all of the features described above will work for your own framework.

A Snapshot instance represents a recursive snapshot of the current state of a UI element hierarchy, and is constructed using an Element. The snapshot can then be passed to

InAppViewDebugger.presentWithSnapshot(:rootViewController:configuration:completion:)

to show the view debugger.

Credits

  • Kyle Van Essen for this tweet picturing Square's implementation that inspired me to build this
  • AudioKit SynthOne, an amazing open-source audio synthesizer app for the iPad that made for a great demo as pictured above

Contact

License

InAppViewDebugger is licensed under the MIT License. See LICENSE for more information.

inappviewdebugger's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

inappviewdebugger's Issues

Support for macOS?

Hey there! I use AppCode to develop and would love to get rid of Xcode entirely, but View Debugging is still a sticking point. Is there any way for you to also support macOS apps in this debugger?

Fix for iOS 13 modal presentation style interfering with the `RangeSlider`

I'm too lazy to make a PR for such a simple change, but if you add this to RangeSlider it will fix the issue. Basically, modal sheets are presented with a new style now instead of fullscreen, and this new style allows you to drag anywhere on the sheet to dismiss the sheet. Custom controls need to abort this gesture or the control will not always receive touches.

override func gestureRecognizerShouldBegin(_ gesture: UIGestureRecognizer) -> Bool {
    return false
}

To see this bug in action, run the demo app on iOS 13 in the simulator. Try to drag the UISlider, then your RangeSlider. It is harder to drag the RangeSlider. Now, apply the fix and try again.

OMG, my brother!

I just ready to refactor the XYDebugView in swift and integrate with VerticalTree, and then I see your open source project here. ๐Ÿ˜ญ๐Ÿ˜ฐ๐Ÿ˜ฅ๐Ÿ˜”๐Ÿ˜‘๐Ÿ˜…๐Ÿ˜‚

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.