aheze / Popovers

A library to present popovers. Simple, modern, and highly customizable. Not boring!
MIT License
1.93k stars 113 forks source link

Unable to use a MenuButton twice in a row. #75

Open blackboxembedded opened 1 year ago

blackboxembedded commented 1 year ago

I'm having an issue where I'm unable to use a MenuButton twice in a row. Below is a simplified example. You will only see one print if you tap "Test1" more than once in a row. Oddly If you tap "Test2" after, then "Test1" it will print once again.

import UIKit
import Popovers
class TestController: UIViewController {

    private var menuBtn: UIButton?
    lazy var menu = Templates.UIKitMenu(sourceView: menuBtn!) {
        Templates.MenuButton(title: "Test1", systemImage: nil) { print("Test 1")}
        Templates.MenuButton(title: "Test2", systemImage: nil) { print("Test 2")}
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        menuBtn = UIButton()
        menuBtn!.setImage(UIImage(named: "Menu")?.withRenderingMode(.alwaysTemplate), for: .normal)
        let menuButton = UIBarButtonItem(customView: menuBtn!)
        let menuButtonWidth = menuButton.customView?.widthAnchor.constraint(equalToConstant: 30)
        menuButtonWidth?.isActive = true
        let menuButtonHeight = menuButton.customView?.heightAnchor.constraint(equalToConstant: 30)
        menuButtonHeight?.isActive = true
        self.navigationItem.rightBarButtonItems = [menuButton]

        _ = menu /// Create the menu.

    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
    }
}
aheze commented 1 year ago

Hmm... I've come across something similar in testing. It's probably a bug in the library - using the current main branch might fix it.

simonlasslop commented 1 year ago

I have the same problem. I have added the Menu to a BarButtonItem through custom view.

bribar commented 6 months ago

I've seen the same issue. Sad this doesn't seem to maintained @aheze ?, good library. I noticed it will work repeated times but it is random touching different parts of the button and sometimes longer presses trigger it. None the less, not good user experience.