Skip to content

Commit

Permalink
Improvements to FloatingTweakWindow
Browse files Browse the repository at this point in the history
 - hide the "floating button" if none of the tweaks in a TweakGroup are supported by the floating UI
 - made a picture-in-picture icon for the "floating button", and a matching "heavy-stroke x" for dismissing the floating tweak UI
  • Loading branch information
Bryan Clark committed Jul 11, 2018
1 parent 2386c2b commit b18d15f
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 11 deletions.
18 changes: 10 additions & 8 deletions SwiftTweaks/FloatingTweakGroupViewController.swift
Expand Up @@ -27,6 +27,15 @@ internal final class FloatingTweakGroupViewController: UIViewController {
}
}

static func editingSupported(forTweak tweak: AnyTweak) -> Bool {
switch tweak.tweakViewDataType {
case .boolean, .integer, .cgFloat, .double:
return true
case .uiColor, .stringList, .string:
return false
}
}

private let presenter: FloatingTweaksWindowPresenter
fileprivate let tweakStore: TweakStore
private let fullFrame: CGRect
Expand Down Expand Up @@ -294,15 +303,8 @@ extension FloatingTweakGroupViewController: UIGestureRecognizerDelegate {
extension FloatingTweakGroupViewController: UITableViewDelegate {
@objc func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let tweak = tweakAtIndexPath(indexPath) else { return }
let tweakEditingAllowed: Bool
switch tweak.tweakViewDataType {
case .boolean, .integer, .cgFloat, .double:
tweakEditingAllowed = false
case .uiColor, .stringList, .string:
tweakEditingAllowed = false
}

if !tweakEditingAllowed {
if !FloatingTweakGroupViewController.editingSupported(forTweak: tweak) {
let alert = UIAlertController(title: "Can't edit this tweak here.", message: "You can edit it back in the main view, though!", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Dismiss", style: .default, handler: nil))
present(alert, animated: true, completion: nil)
Expand Down
Expand Up @@ -2,17 +2,17 @@
"images" : [
{
"idiom" : "universal",
"filename" : "FloatingPlusButton.png",
"filename" : "floating-plus-button.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "FloatingPlusButton@2x.png",
"filename" : "floating-plus-button@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "FloatingPlusButton@3x.png",
"filename" : "floating-plus-button@3x.png",
"scale" : "3x"
}
],
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions SwiftTweaks/TweakCollectionViewController.swift
Expand Up @@ -233,6 +233,11 @@ fileprivate final class TweakGroupSectionHeader: UITableViewHeaderFooterView {
var tweakGroup: TweakGroup? {
didSet {
titleLabel.text = tweakGroup?.title
guard let tweakGroup = tweakGroup else { return }
let shouldShowFloatingButton = tweakGroup.sortedTweaks.reduce(false) { (accum, tweak) -> Bool in
return accum || FloatingTweakGroupViewController.editingSupported(forTweak: tweak)
}
self.floatingButton.isHidden = !shouldShowFloatingButton
}
}

Expand Down

0 comments on commit b18d15f

Please sign in to comment.