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

present/dismiss Peek programatically #66

Closed
wants to merge 2 commits into from
Closed

present/dismiss Peek programatically #66

wants to merge 2 commits into from

Conversation

mshibanami
Copy link

@mshibanami mshibanami commented Oct 28, 2018

This PR is for presenting/dismissing Peek programmatically via UIAlertController or whatever that is presented by a shake gesture.

Honestly, I'm not really sure this is an appropriate approach. Please ask any questions, thanks.

Context of this PR

Not only Peek, but there are other debugging libraries like CocoaDebug or in-house one. To manage all of them in an app, I usually add a debug menu that is shown by a shake gesture.
So I wrote code like this:

extension UIViewController {
    open override func motionBegan(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
        super.motionBegan(motion, with: event)

        let alert = UIAlertController(title: "Debug Mode", message: nil, preferredStyle: .actionSheet)

        alert.addAction(UIAlertAction(title: "Peek", style: .default) { action in
            let window = UIApplication.shared.windows.first
            if Peek.isAlreadyPresented {
                window?.peek.dismiss()
            } else {
                window?.peek.present()
            }
        })
        alert.addAction(UIAlertAction(title: "CocoaDebug", style: .default) { action in
            // present/dismiss CocoaDebug
        })
        alert.addAction(UIAlertAction(title: "Another Debug Tool", style: .default) { action in
            // present/dismiss another debug tool
        })
        alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))

        view.window?.rootViewController?.present(alert, animated: true, completion: nil)
    }
}

This is what I'd like to implement with the above code:

capture

But currently, this doesn't work after presenting PeekViewController once because its motionBegan doesn't call its super method.

So I added code that calls it. Also, I added none to PeekActivationMode not to handle shake gesture and volume controls by Peek.

Checklist

  • Latest changes from develop have been merged
  • Conflicts have been resolved
  • The branch is pointing to develop
  • SwiftLint hasn't reported any issues.

@mshibanami mshibanami changed the title Let to present/dismiss Peek programatically present/dismiss Peek programatically Oct 28, 2018
@shaps80
Copy link
Owner

shaps80 commented Dec 1, 2018

Sorry for the delayed response.

Hmmm... I’ve implemented something similar before myself. However I found it to be project specific most of the time.

There is a protocol for activation, I wonder if this is just a specific implementation of that we should use. I.e. AlertActivationController. Thoughts?

@shaps80 shaps80 closed this Feb 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants