GitHawkApp / ContextMenu

An iOS context menu UI inspired by Things 3.
http://githawk.com/
MIT License
982 stars 51 forks source link

Wrong present and dismiss position #25

Closed marcuswu0814 closed 6 years ago

marcuswu0814 commented 6 years ago

I'm trying to use ContextMenu on rightBarButtonItem like this:

fileprivate func setupFilterButton() {
    let button = UIButton(type: .system)
    button.addTarget(self, action: #selector(filterButtonClicked), for: .touchUpInside)
    button.setTitle("Filter", for: .normal)
    let item = UIBarButtonItem(customView: button)

    navigationItem.rightBarButtonItem = item
}

@objc fileprivate func filterButtonClicked() {
    let viewController = UIViewController()
    viewController.preferredContentSize = CGSize(width: 200, height: 200)

    ContextMenu().show(sourceViewController: self,
                       viewController: viewController,
                       sourceView: navigationItem.rightBarButtonItem?.customView,
                       delegate: nil)
}

Present worked well, but dismiss animation look like had some problem.

And I also used it in IGListKit's method didSelectItem(at:)

override func didSelectItem(at index: Int) {
    guard let cell = collectionContext?.cellForItem(at: index, sectionController: self) else {
        fatalError()
    }

    let viewController = UIViewController()
    viewController.preferredContentSize = CGSize(width: 200, height: 200)

    ContextMenu().show(sourceViewController: self.viewController!,
                       viewController: viewController,
                       sourceView: cell,
                       delegate: nil)
}

Both present and dismiss position weird.

Any tips for me to fix this issue?

ezgif-4-7d370162d8

rnystrom commented 6 years ago

@marcuswu0814 wo! That is weird. Do you have that sample project that I could poke around at?

If you want to help debug that would be so helpful 🙏 It looks like an issue with tracking the source views position on dismiss.

Sent with GitHawk

marcuswu0814 commented 6 years ago

Here is a reproduce project. Maybe I can try to trace the issue but may spend some time. 😅

rnystrom commented 6 years ago

@marcuswu0814 you need to use the singleton menu. You're initializing the ContextMenu() every time and it isn't retained. So when the controller is dismissed there is no dismiss transition delegate. Changing ContextMenu() to ContextMenu.shared will fix it for you.