Skip to content

Commit c1901a6

Browse files
author
bryanjclark
committed
Add "reopen tweaks" button to Floating Tweak Window
Previously, once you were in the "floating tweak window" state, you couldn't get right back into SwiftTweaks' main interface. Now there's a new button on the floating tweak window that pops you back into SwiftTweaks' interface.
1 parent e765cdc commit c1901a6

7 files changed

+97
-46
lines changed

SwiftTweaks/FloatingTweakGroupViewController.swift

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import UIKit
1414
internal protocol FloatingTweaksWindowPresenter {
1515
func presentFloatingTweaksUI(forTweakGroup tweakGroup: TweakGroup)
1616
func dismissFloatingTweaksUI()
17+
func resumeDisplayingMainTweaksInterface()
1718
}
1819

1920
// MARK: - FloatingTweakGroupViewController
@@ -85,7 +86,7 @@ internal final class FloatingTweakGroupViewController: UIViewController {
8586
internal static let margins: CGFloat = 5
8687
private static let minimizedWidth: CGFloat = 30
8788

88-
private static let closeButtonSize = CGSize(width: 42, height: 32)
89+
private static let navBarButtonSize = CGSize(width: 42, height: 32)
8990
private static let navBarHeight: CGFloat = 32
9091
private static let windowCornerRadius: CGFloat = 5
9192

@@ -116,6 +117,14 @@ internal final class FloatingTweakGroupViewController: UIViewController {
116117
return button
117118
}()
118119

120+
private let reopenButton: UIButton = {
121+
let button = UIButton()
122+
let buttonImage = UIImage(swiftTweaksImage: .floatingReopenButton).withRenderingMode(.alwaysTemplate)
123+
button.setImage(buttonImage.imageTintedWithColor(AppTheme.Colors.controlTinted), for: UIControl.State())
124+
button.setImage(buttonImage.imageTintedWithColor(AppTheme.Colors.controlTintedPressed), for: .highlighted)
125+
return button
126+
}()
127+
119128
fileprivate let tableView: UITableView = {
120129
let tableView = UITableView(frame: .zero, style: .plain)
121130
tableView.backgroundColor = .clear
@@ -152,7 +161,9 @@ internal final class FloatingTweakGroupViewController: UIViewController {
152161

153162
// The "fake nav bar"
154163
closeButton.addTarget(self, action: #selector(self.closeButtonTapped), for: .touchUpInside)
164+
reopenButton.addTarget(self, action: #selector(self.reopenButtonTapped), for: .touchUpInside)
155165
navBar.addSubview(closeButton)
166+
navBar.addSubview(reopenButton)
156167
navBar.addSubview(titleLabel)
157168
view.addSubview(navBar)
158169

@@ -192,7 +203,13 @@ internal final class FloatingTweakGroupViewController: UIViewController {
192203
return mask
193204
}()
194205

195-
closeButton.frame = CGRect(origin: .zero, size: FloatingTweakGroupViewController.closeButtonSize)
206+
closeButton.frame = CGRect(origin: .zero, size: FloatingTweakGroupViewController.navBarButtonSize)
207+
reopenButton.sizeToFit()
208+
reopenButton.frame = CGRect(
209+
origin: CGPoint(
210+
x: navBar.bounds.width - FloatingTweakGroupViewController.navBarButtonSize.width,
211+
y: 0),
212+
size: FloatingTweakGroupViewController.navBarButtonSize)
196213
titleLabel.frame = CGRect(
197214
origin: CGPoint(
198215
x: closeButton.frame.width,
@@ -215,6 +232,10 @@ internal final class FloatingTweakGroupViewController: UIViewController {
215232

216233
// MARK: Actions
217234

235+
@objc private func reopenButtonTapped() {
236+
self.presenter.resumeDisplayingMainTweaksInterface()
237+
}
238+
218239
@objc private func closeButtonTapped() {
219240
presenter.dismissFloatingTweaksUI()
220241
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "floating-ui-open-tweaks.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"filename" : "floating-ui-open-tweaks@2x.png",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"filename" : "floating-ui-open-tweaks@3x.png",
16+
"scale" : "3x"
17+
}
18+
],
19+
"info" : {
20+
"version" : 1,
21+
"author" : "xcode"
22+
}
23+
}
Loading
Loading
Loading

SwiftTweaks/TweakWindow.swift

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -173,57 +173,56 @@ extension TweakWindow: FloatingTweaksWindowPresenter {
173173

174174
/// Presents a floating TweakGroup over your app's UI, so you don't have to hop in and out of the full-modal Tweak UI.
175175
internal func presentFloatingTweaksUI(forTweakGroup tweakGroup: TweakGroup) {
176-
if (floatingTweakGroupUIWindow == nil) {
177-
let window = HitTransparentWindow()
178-
window.frame = UIScreen.main.bounds
179-
window.backgroundColor = UIColor.clear
180-
181-
var originY = window.frame.size.height - FloatingTweakGroupViewController.height - FloatingTweakGroupViewController.margins
182-
if #available(iOS 11.0, *) {
183-
originY = originY - self.safeAreaInsets.bottom
184-
}
176+
guard floatingTweakGroupUIWindow == nil else { return }
185177

186-
let floatingTweakGroupFrame = CGRect(
187-
origin: CGPoint(
188-
x: FloatingTweakGroupViewController.margins,
189-
y: originY
190-
),
191-
size: CGSize(
192-
width: window.frame.size.width - FloatingTweakGroupViewController.margins*2,
193-
height: FloatingTweakGroupViewController.height
194-
)
195-
)
178+
let window = HitTransparentWindow()
179+
window.frame = UIScreen.main.bounds
180+
window.backgroundColor = UIColor.clear
196181

197-
let floatingTweaksVC = FloatingTweakGroupViewController(frame: floatingTweakGroupFrame, tweakStore: tweakStore, presenter: self)
198-
floatingTweaksVC.tweakGroup = tweakGroup
199-
window.rootViewController = floatingTweaksVC
200-
window.addSubview(floatingTweaksVC.view)
201-
202-
window.alpha = 0
203-
let initialWindowFrame = window.frame.offsetBy(dx: 0, dy: floatingTweaksVC.view.bounds.height)
204-
let destinationWindowFrame = window.frame
205-
window.makeKeyAndVisible()
206-
floatingTweakGroupUIWindow = window
207-
208-
window.frame = initialWindowFrame
209-
UIView.animate(
210-
withDuration: TweakWindow.presentationDuration,
211-
delay: 0,
212-
usingSpringWithDamping: TweakWindow.presentationDamping,
213-
initialSpringVelocity: TweakWindow.presentationVelocity,
214-
options: .beginFromCurrentState,
215-
animations: {
216-
window.frame = destinationWindowFrame
217-
window.alpha = 1
218-
},
219-
completion: nil
220-
)
182+
var originY = window.frame.size.height - FloatingTweakGroupViewController.height - FloatingTweakGroupViewController.margins
183+
if #available(iOS 11.0, *) {
184+
originY = originY - self.safeAreaInsets.bottom
221185
}
186+
187+
let floatingTweakGroupFrame = CGRect(
188+
origin: CGPoint(
189+
x: FloatingTweakGroupViewController.margins,
190+
y: originY
191+
),
192+
size: CGSize(
193+
width: window.frame.size.width - FloatingTweakGroupViewController.margins*2,
194+
height: FloatingTweakGroupViewController.height
195+
)
196+
)
197+
198+
let floatingTweaksVC = FloatingTweakGroupViewController(frame: floatingTweakGroupFrame, tweakStore: tweakStore, presenter: self)
199+
floatingTweaksVC.tweakGroup = tweakGroup
200+
window.rootViewController = floatingTweaksVC
201+
window.addSubview(floatingTweaksVC.view)
202+
203+
window.alpha = 0
204+
let initialWindowFrame = window.frame.offsetBy(dx: 0, dy: floatingTweaksVC.view.bounds.height)
205+
let destinationWindowFrame = window.frame
206+
window.makeKeyAndVisible()
207+
floatingTweakGroupUIWindow = window
208+
209+
window.frame = initialWindowFrame
210+
UIView.animate(
211+
withDuration: TweakWindow.presentationDuration,
212+
delay: 0,
213+
usingSpringWithDamping: TweakWindow.presentationDamping,
214+
initialSpringVelocity: TweakWindow.presentationVelocity,
215+
options: .beginFromCurrentState,
216+
animations: {
217+
window.frame = destinationWindowFrame
218+
window.alpha = 1
219+
},
220+
completion: nil
221+
)
222222
}
223223

224224
/// Dismisses the floating TweakGroup
225225
func dismissFloatingTweaksUI() {
226-
227226
guard let floatingTweakGroupUIWindow = floatingTweakGroupUIWindow else { return }
228227

229228
UIView.animate(
@@ -240,4 +239,11 @@ extension TweakWindow: FloatingTweaksWindowPresenter {
240239
}
241240
)
242241
}
242+
243+
func resumeDisplayingMainTweaksInterface() {
244+
guard floatingTweakGroupUIWindow != nil else { return }
245+
246+
self.dismissFloatingTweaksUI()
247+
self.presentTweaks()
248+
}
243249
}

SwiftTweaks/UIImage+SwiftTweaks.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ internal extension UIImage {
1414
case disclosureIndicator = "disclosure-indicator"
1515
case floatingPlusButton = "floating-plus-button"
1616
case floatingCloseButton = "floating-ui-close"
17+
case floatingReopenButton = "floating-ui-open-tweaks"
1718
case floatingMinimizedArrow = "floating-ui-minimized-arrow"
1819
}
1920

0 commit comments

Comments
 (0)