Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

34 #35

Merged
merged 2 commits into from
Aug 30, 2019
Merged

34 #35

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Droar.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Droar'
s.version = '1.4.1'
s.version = '1.5.1'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, 1.5.0, but we'll let that slide :P

s.summary = 'A runtime debugging tool for iOS.'

s.description = <<-DESC
Expand Down
5 changes: 5 additions & 0 deletions Droar/Classes/Cells/DroarTextFieldCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public class DroarTextFieldCell : UITableViewCell, DroarCell {
@IBOutlet weak var textField: UITextField!
var onTextChanged: ((String?)-> Void)?

public override func awakeFromNib() {
super.awakeFromNib()
//I imagine that Droar will seldom need autocorrect. We can add a param in the future if needed.
textField.autocorrectionType = .no
}

public var title: String? {
get { return titleLabel.text }
Expand Down
73 changes: 57 additions & 16 deletions Droar/Classes/Droar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//

import Foundation
import UIKit

@objc public enum DroarGestureType: UInt {
case tripleTap, panFromRight
Expand Down Expand Up @@ -36,7 +36,21 @@ import Foundation
Droar.isStarted = true
}
}


@objc public static func setGestureType(_ type: DroarGestureType, _ threshold: CGFloat = 50.0) {
configureRecognizerForType(type, threshold)
}

// For plugins
@objc public static func pushViewController(_ viewController: UIViewController, animated: Bool) {
navController.pushViewController(viewController, animated: animated)
}

}

//Knobs
extension Droar {

@objc public static func register(_ knob: DroarKnob) {
KnobManager.sharedInstance.registerStaticKnob(knob)
viewController?.tableView.reloadData()
Expand All @@ -52,28 +66,55 @@ import Foundation
viewController?.tableView.reloadData()
}

@objc public static func setGestureType(_ type: DroarGestureType, _ threshold: CGFloat = 50.0) {
configureRecognizerForType(type, threshold)
public static func refreshKnobs() {
viewController?.tableView.reloadData()
}

// For plugins
@objc public static func pushViewController(_ viewController: UIViewController, animated: Bool) {
navController.pushViewController(viewController, animated: animated)
}

//Visibility
extension Droar {

//Technically this could be wrong depending on the tx value, but it is close enough.
@objc public static var isVisible: Bool { return !(navController.view.transform == CGAffineTransform.identity) }

@objc public static func openDroar(completion: (()->Void)? = nil) {
UIView.animate(withDuration: 0.25, animations: {
navController.view.transform = CGAffineTransform(translationX: -navController.view.frame.size.width, y: 0)
setContainerOpacity(1)
}) { (completed) in
endDroarVisibilityUpdate(completion)
}
}

@objc public static var isVisible: Bool {
get {
return containerViewController.parent != nil
@objc public static func closeDroar(completion: (()->Void)? = nil) {
UIView.animate(withDuration: 0.25, animations: {
navController.view.transform = CGAffineTransform.identity
setContainerOpacity(0)
}) { (completed) in
endDroarVisibilityUpdate(completion)
}
}

@objc public static func showWindow(completion: (()->Void)? = nil) {
guard !isVisible else { return }
toggleVisibility(completion)
@objc static func toggleVisibility(completion: (()->Void)? = nil) {
if isVisible {
closeDroar(completion: completion)
} else {
openDroar(completion: completion)
}
}

private static func setContainerOpacity(_ opacity: CGFloat) {
containerViewController.view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: defaultContainerAlpha * opacity)
}

}

@objc public static func dismissWindow(completion: (()->Void)? = nil) {
guard isVisible else { return }
toggleVisibility(completion)
//Backwards compatibility
extension Droar {

public static func dismissWindow() {
closeDroar(completion: nil)
}

}
18 changes: 1 addition & 17 deletions Droar/Classes/Extensions/DroarGestureHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal extension Droar {
}

@objc private static func handleTripleTap(sender: UITapGestureRecognizer?) {
toggleVisibility(nil)
toggleVisibility()
}

@objc private static func handlePan(sender: UIPanGestureRecognizer?) {
Expand Down Expand Up @@ -136,22 +136,6 @@ internal extension Droar {
})
}

@objc static func toggleVisibility(_ completion: (()->Void)?) {
guard beginDroarVisibilityUpdate() else { return }

UIView.animate(withDuration: 0.25, animations: {
if navController.view.transform.isIdentity {
navController.view.transform = CGAffineTransform(translationX: -navController.view.frame.size.width, y: 0)
setContainerOpacity(1)
} else {
navController.view.transform = CGAffineTransform.identity
setContainerOpacity(0)
}
}) { (completed) in
endDroarVisibilityUpdate(completion)
}
}

private class GestureDelegate: NSObject, UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
Expand Down
8 changes: 2 additions & 6 deletions Droar/Classes/Extensions/DroarHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,11 @@ internal extension Droar {
}
}

dismissalRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(dismissWindow))
dismissalRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(dismissalRecognizerEvent))
dismissalRecognizer.direction = .right
}

@objc private static func dismissWindow() {
if Droar.isVisible {
toggleVisibility(nil)
}
}
@objc private static func dismissalRecognizerEvent() { closeDroar() } //We can't call closeDroar from the selector because of the optional completion block

static func loadDynamicKnobs() -> [DroarKnob] {
if let activeVC = loadActiveResponder() as? UIViewController {
Expand Down
5 changes: 5 additions & 0 deletions Droar/Classes/Implementation/DroarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class DroarViewController: UITableViewController {
navigationController?.navigationBar.tintColor = UIColor.white
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
tableView.reloadData()
}

override func numberOfSections(in tableView: UITableView) -> Int {
return KnobManager.sharedInstance.visibleSections.count
}
Expand Down