CaliCastle / PopMenu

A fully customizable popup style menu for iOS 😎
https://popmenu.cali.so
MIT License
1.6k stars 182 forks source link

Unwanted Results via PopMenuManager #19

Closed CaliCastle closed 5 years ago

CaliCastle commented 5 years ago

✍🏻 Issue Description

There will be some unwanted carryovers in a result of using the PopMenuManager to construct the menu

CaliCastle commented 5 years ago

Quote from LouK in Slack discussion:

it seems that the selected state of an item persists across multiple presentations of a menu... is there a way to deselect a selected item, or to not have the selection latched when the menu is dismissed? Looked at the source but I don't see where the selection is maintained...it almost looks like the completion closure in actionSelected's UIView.animate is not executing.

using the manager... looks like this when presenting the menu after previously selecting the middle item: image

HackShitUp commented 5 years ago

I'm seeing this issue and I thought it was an issue with how I programmed. But after reviewing the documentation countless times and viewing your examples, this bug is getting pretty annoying. Any updates?

CaliCastle commented 5 years ago

@HackShitUp sorry for the inconvenience it had caused you, yeah I am aware of this bug and there will be a patch for all of the issues by the end of month December, thank you for the support!

CaliCastle commented 5 years ago

@HackShitUp for now the easiest way as a workaround would be using the PopMenuViewController instance

HackShitUp commented 5 years ago

@CaliCastle Happy New Year (if you'are around the U.S. haha)! So I do use that in our application, but the issue still persists. Do you know why the carryovers occur? I can try and fix it myself if I can understand the problem

CaliCastle commented 5 years ago

@HackShitUp hi, happy New Years to you too!! Actually this fix is already completed in my local environment I just need to make some adjustments before releasing an update, it'll be sometime later this week, thanks for the support and using PopMenu, I appreciate it!

HackShitUp commented 5 years ago

Awesome! Thank you so much!

CaliCastle commented 5 years ago

@HackShitUp fixed in v2.1.2

HackShitUp commented 5 years ago

@CaliCastle I still get this issue whenever I'm presenting it from a UICollectionViewCell.

// Unwrap the 'Capsule' PFObject
        guard capsule != nil else { return }

        // MARK: - UINotificationFeedbackGenerator
        let feedbackGenerator = UINotificationFeedbackGenerator()
        feedbackGenerator.notificationOccurred(.success)

        // MARK: - PopMenu
        let manager = PopMenuManager.default
        manager.popMenuAppearance.popMenuColor.backgroundColor = .solid(fill: .white)
        manager.popMenuAppearance.popMenuFont = UIFont.demibold(size: 14)
        manager.popMenuAppearance.popMenuCornerRadius = 16
        manager.popMenuAppearance.popMenuItemSeparator = .fill(.groupTableViewBackground, height: 1)
        manager.popMenuShouldDismissOnSelection = true

        // Unlock Capsule
        let unlockAction = PopMenuDefaultAction(title: "Unlock", image: UIImage(named: "Unlocked")!, color: UIColor.black) {
            (action: PopMenuAction) in
            // MARK: - PFObject(className: "Capsule")
            self.capsule["isPrivate"] = false
            self.capsule.saveInBackground(block: { (success: Bool, error: Error?) in
                if success {
                    // MARK: - CSAlertManager
                    CSAlertManager.shared.showAlertBanner(title: "✅ Unlocked Album", color: UIColor.black.withAlphaComponent(0.80))

                    DispatchQueue.main.async {
                        // Reset the lockButton
                        self.lockButton.setImage(nil, for: .normal)
                    }

                    // MARK: - NotificationCenter
                    NotificationCenter.default.post(name: GalleryViewController.reloadCapsules, object: nil)

                } else {
                    print(error?.localizedDescription as Any)
                    // MARK: - CSAlertManager
                    CSAlertManager.shared.showAlertBanner(title: "💩 Couldn't Unlock Album", color: UIColor.black.withAlphaComponent(0.80))
                }
            })
        }

        // Lock Capsule
        let lockAction = PopMenuDefaultAction(title: "Lock", image: UIImage(named: "Locked")!, color: UIColor.black) {
            (action: PopMenuAction) in
            // MARK: - PFObject(className: "Capsule")
            self.capsule["isPrivate"] = true
            self.capsule.saveInBackground(block: { (success: Bool, error: Error?) in
                if success {
                    // MARK: - CSAlertManager
                    CSAlertManager.shared.showAlertBanner(title: "✅ Locked Album", color: UIColor.black.withAlphaComponent(0.80))

                    DispatchQueue.main.async {
                        // Reset the lockButton
                        self.lockButton.setImage(UIImage(named: "Locked"), for: .normal)
                        self.lockButton.addTarget(self, action: #selector(self.unlockCapsule(_:)), for: .touchUpInside)
                    }

                    // MARK: - NotificationCenter
                    NotificationCenter.default.post(name: GalleryViewController.reloadCapsules, object: nil)

                } else {
                    print(error?.localizedDescription as Any)
                    // MARK: - CSAlertManager
                    CSAlertManager.shared.showAlertBanner(title: "💩 Couldn't Lock Album", color: UIColor.black.withAlphaComponent(0.80))
                }
            })
        }

        // Edit Capsule
        let editAction = PopMenuDefaultAction(title: "Edit Name", image: UIImage(named: "Pen")!, color: UIColor.black) {
            (action: PopMenuAction) in
            manager.popMenuDidDismiss = { didSelect in
                // MARK: - CSAlertManager
                CSAlertManager.shared.renameCapsule(self.capsule, completionHandler: { (object: PFObject, success: Bool) in
                    if success {
                        // MARK: - NotificationCenter
                        NotificationCenter.default.post(name: GalleryViewController.reloadCapsules, object: nil)
                    }
                })
            }
        }

        // Send Capsule
        let sendAction = PopMenuDefaultAction(title: "Send", image: UIImage(named: "TabChat")!, color: UIColor.black) {
            (action: PopMenuAction) in
            manager.popMenuDidDismiss = { didSelect in
                if didSelect == true {

                    // MARK: - TagUsersViewController
                    let tagUsersVC = TagUsersViewController.init(delegate: self, type: .send, existingUsers: nil, object: self.capsule)
                    // MARK: - CSNavigationController
                    let csNavigationController = CSNavigationController.init(rootViewController: tagUsersVC, type: .pushPop)
                    csNavigationController.presentNavigationFrom(viewController: self.parentViewController!)
                }
            }
        }

        // Delete Capsule
        let leaveAction = PopMenuDefaultAction(title: "Leave Album", image: UIImage(named: "LeaveButton")!, color: UIColor.black) {
            (action: PopMenuAction) in
            manager.popMenuDidDismiss = { didSelect in
                if didSelect == true {

                    // MARK: - UIAlertController
                    let alertController = UIAlertController.init(title: "Leave Album?", message: "Are you sure you would like to leave this album? Your friends would have to add you again to add moments to them.", preferredStyle: .actionSheet)

                    // Leave Action
                    let leaveAction = UIAlertAction.init(title: "Leave Album", style: .destructive, handler: { (action: UIAlertAction) in
                        self.capsule.remove(PFUser.current()!.objectId!, forKey: "collaborators")
                        self.capsule.saveInBackground(block: { (success: Bool, error: Error?) in
                            if success {

                                // Remove the 'Capsule' object id
                                PFUser.current()!.remove(self.capsule.objectId!, forKey: "autoSaveKeys")
                                PFUser.current()!.saveInBackground()

                                // MARK: - CSAlertManager
                                CSAlertManager.shared.showAlertBanner(title: "😢 Sad to see you go...", color: UIColor.black.withAlphaComponent(0.80))

                                // MARK: - NotificationCenter
                                NotificationCenter.default.post(name: GalleryViewController.reloadCapsules, object: nil)

                            } else {
                                print(error?.localizedDescription as Any)
                                // MARK: - CSAlertManager
                                CSAlertManager.shared.showAlertBanner(title: "💩 Couldn't Unlock Album", color: UIColor.black.withAlphaComponent(0.80))
                            }
                        })
                    })

                    // Cancel Action
                    let cancelAction = UIAlertAction.init(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction) in
                        alertController.dismiss(animated: true, completion: nil)
                    })

                    alertController.addAction(leaveAction)
                    alertController.addAction(cancelAction)
                    self.parentViewController?.present(alertController, animated: true, completion: nil)
                }
            }
        }

        if capsule!.value(forKey: "isPrivate") as! Bool == false {
            //
            // Lock
            //
            manager.addAction(lockAction)
        } else {
            //
            // Unlock
            //
            manager.addAction(unlockAction)
        }
        manager.addAction(editAction)
        manager.addAction(sendAction)
        manager.addAction(leaveAction)
        manager.present(sourceView: self)