Skip to content

Commit

Permalink
Fix UI and Interaction (#15)
Browse files Browse the repository at this point in the history
* improve

* bump version and update changelog
  • Loading branch information
wendyliga authored Feb 22, 2024
1 parent a1ed10a commit 68935ff
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 54 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
6 changes: 4 additions & 2 deletions Sources/TPTweak/TPTweakPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ internal final class TPTweakPickerViewController: UIViewController {
_data = newValue
}
}
private let isFavouritePage: Bool

// MARK: - Views

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions Sources/TPTweak/TPTweakShakeWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
77 changes: 28 additions & 49 deletions Sources/TPTweak/TPTweakViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
}
}
}
}
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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!

Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -647,7 +626,7 @@ extension TPTweakViewController {
bubble.addGestureRecognizer(tap)

// show
visibleViewController.view.addSubview(bubble)
UIApplication.shared.keyWindow?.addSubview(bubble)
}

@objc
Expand Down
2 changes: 1 addition & 1 deletion TPTweak.podspec
Original file line number Diff line number Diff line change
@@ -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" }
Expand Down

0 comments on commit 68935ff

Please sign in to comment.