diff --git a/CHANGELOG.md b/CHANGELOG.md index 64b5392..97737b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 2.0.1 +- fix the empty search page shows favourite empty state message +- restore tweak view controller if minimizable exists +- add delay before adding minimize bar button item on the child's navigation bar +- expose restoreTweaks so custom implementation can mutate the state +- bubble from now will be added to window instead of the top viewcontroller's view # 2.0.0 - Minimizable TPTweakViewController with `TPTweakViewController.presentMinimizableTweaks` diff --git a/Sources/TPTweak/TPTweakPickerViewController.swift b/Sources/TPTweak/TPTweakPickerViewController.swift index a540d24..55079c5 100644 --- a/Sources/TPTweak/TPTweakPickerViewController.swift +++ b/Sources/TPTweak/TPTweakPickerViewController.swift @@ -53,6 +53,7 @@ internal final class TPTweakPickerViewController: UIViewController { _data = newValue } } + private let isFavouritePage: Bool // MARK: - Views @@ -77,7 +78,8 @@ internal final class TPTweakPickerViewController: UIViewController { // MARK: - Life Cycle - internal init(data: [Section]) { + internal init(data: [Section], isFavouritePage: Bool = false) { + self.isFavouritePage = isFavouritePage super.init(nibName: nil, bundle: nil) self.data = data @@ -238,7 +240,7 @@ extension TPTweakPickerViewController: UITableViewDataSource, UITableViewDelegat let count = data.count // handling empty state - if count == 0 { + if count == 0 && isFavouritePage { let emptyLabel = UILabel(frame: .zero) emptyLabel.text = "You can Favorite a Tweaks by swipe or long press on the cell" emptyLabel.textAlignment = .center diff --git a/Sources/TPTweak/TPTweakShakeWindow.swift b/Sources/TPTweak/TPTweakShakeWindow.swift index 58db3e5..0a11990 100644 --- a/Sources/TPTweak/TPTweakShakeWindow.swift +++ b/Sources/TPTweak/TPTweakShakeWindow.swift @@ -88,8 +88,14 @@ public class TPTweakShakeWindow: UIWindow { shaking = true guard shouldPresentTweaks == true else { return } - presentTweaks() - + + // TPTweak is minimzed, restore + if UIApplication.shared.keyWindow?.rootViewController == __realViewController && __tweakViewController != nil { + TPTweakViewController.restoreTweaks() + } else { + presentTweaks() + } + super.motionBegan(motion, with: event) } diff --git a/Sources/TPTweak/TPTweakViewController.swift b/Sources/TPTweak/TPTweakViewController.swift index 6302900..4ff62eb 100644 --- a/Sources/TPTweak/TPTweakViewController.swift +++ b/Sources/TPTweak/TPTweakViewController.swift @@ -52,21 +52,28 @@ public final class TPTweakWithNavigatationViewController: UINavigationController public override func pushViewController(_ viewController: UIViewController, animated: Bool) { super.pushViewController(viewController, animated: animated) - - /// automatically add minimizable on every children if enable - if let tptweakviewController = __tweakViewController, - viewController != tptweakviewController.tweakViewController, - tptweakviewController.tweakViewController.minimizable - { - if (viewController.navigationItem.rightBarButtonItems?.count ?? 0) > 0 { - viewController.navigationItem.rightBarButtonItems?.append(tptweakviewController.tweakViewController.minimizeBarButtonItem) - } else { - viewController.navigationItem.rightBarButtonItems = [ - tptweakviewController.tweakViewController.minimizeBarButtonItem - ] - } - + // a hacky way to wait until lifecycle like viewDidLoad, viewWillApper or other to complete + // so the vc will not replace the navigation added by TPTweak. + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + /// automatically add minimizable on every children if enable + if let tptweakviewController = __tweakViewController, + viewController != tptweakviewController.tweakViewController, + tptweakviewController.tweakViewController.minimizable + { + if (viewController.navigationItem.rightBarButtonItems?.count ?? 0) > 0 { + viewController.navigationItem.rightBarButtonItems?.append(tptweakviewController.tweakViewController.minimizeBarButtonItem) + } + else if let existingRightBarButtonItem = viewController.navigationItem.rightBarButtonItem { + viewController.navigationItem.rightBarButtonItem = nil + viewController.navigationItem.rightBarButtonItems = [tptweakviewController.tweakViewController.minimizeBarButtonItem, existingRightBarButtonItem] + } + else { + viewController.navigationItem.rightBarButtonItems = [ + tptweakviewController.tweakViewController.minimizeBarButtonItem + ] + } + } } } } @@ -420,7 +427,7 @@ public final class TPTweakViewController: UIViewController { } let data = convertRowToSection(row: Row(name: "", entries: favouriteEntries)) - let favouriteViewController = TPTweakPickerViewController(data: data) + let favouriteViewController = TPTweakPickerViewController(data: data, isFavouritePage: true) favouriteViewController.title = "Favourites" self.navigationController?.pushViewController(favouriteViewController, animated: true) } @@ -433,18 +440,7 @@ public final class TPTweakViewController: UIViewController { extension TPTweakViewController: UITableViewDataSource, UITableViewDelegate { public func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int { - let count = data.count - - if count <= 0 { - let emptyLabel = UILabel(frame: CGRect(x: 0, y: 0, width: self.view.bounds.size.width, height: self.view.bounds.size.height)) - emptyLabel.text = "No Data" - emptyLabel.textAlignment = NSTextAlignment.center - self.table.backgroundView = emptyLabel - } else { - self.table.backgroundView = nil - } - - return count + data.count } public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { @@ -566,7 +562,7 @@ extension TPTweakViewController { } @objc - private static func restoreTweaks() { + public static func restoreTweaks() { guard let tweakViewController = __tweakViewController else { return } let tweakView = tweakViewController.view! @@ -598,27 +594,13 @@ extension TPTweakViewController { return CGPoint(x: x, y: y) } - private static func getVisibleViewController() -> UIViewController? { - var visibleViewController = UIApplication.shared.keyWindow?.rootViewController - - if visibleViewController?.presentedViewController != nil { - visibleViewController = visibleViewController?.presentedViewController - } - - // prevent double-presenting the tweaks view controller - guard let visibleViewController = visibleViewController, (visibleViewController is TPTweakWithNavigatationViewController) == false else { return nil } - return visibleViewController - } - private static func setupBubble() { - guard let visibleViewController = getVisibleViewController() else { return } - let subview: UIView if #available(iOS 13.0, *) { let image = UIImageView(frame: .init(x: 0, y: 0, width: 50, height: 50)) image.contentMode = .center image.image = UIImage(systemName: "arrow.up.left.and.arrow.down.right", withConfiguration: UIImage.SymbolConfiguration(pointSize: 18)) - image.tintColor = .white + image.tintColor = .systemGray6 subview = image } else { let label = UILabel(frame: .init(x: 0, y: 0, width: 50, height: 50)) @@ -629,11 +611,8 @@ extension TPTweakViewController { let lastPosition = getBubblePosition() let bubble = UIView(frame: .init(x: lastPosition.x, y: lastPosition.y, width: 50, height: 50)) - if #available(iOS 13.0, *) { - bubble.backgroundColor = .secondarySystemBackground - } else { - bubble.backgroundColor = .gray - } + bubble.backgroundColor = .systemGray + bubble.alpha = 0.9 bubble.layer.cornerRadius = 25 bubble.addSubview(subview) @@ -647,7 +626,7 @@ extension TPTweakViewController { bubble.addGestureRecognizer(tap) // show - visibleViewController.view.addSubview(bubble) + UIApplication.shared.keyWindow?.addSubview(bubble) } @objc diff --git a/TPTweak.podspec b/TPTweak.podspec index 20e9e1a..4d23084 100644 --- a/TPTweak.podspec +++ b/TPTweak.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = "TPTweak" - spec.version = "2.0.0" + spec.version = "2.0.1" spec.summary = "TPTweak is a debugging tool to help adjust your iOS app on the fly without recompile" spec.license = { :type => "Apache 2.0", :file => "LICENSE.md" }