SwiftyContextMenu
SwiftyContextMenu copied to clipboard
Context Menu not dismissing
Thanks for your library.
I facing one critical issue. I using this library on the collection view. when the context menu presents, after tapping the menu actions, I am trying to push another controller or tapped outside to dismiss the context menu. still, the context menu presents on the window. refer the screenshots
private func setupContext(with indexPath: IndexPath) -> ContextMenu {
let favoriteAction = ContextMenuAction(title: "Select Address", image: UIImage(named: "icon_context_select"),
action: { [weak self] _ in
guard let strongSelf = self else { return }
strongSelf.selectAddressTapped(with: indexPath)
})
let shareAction = ContextMenuAction(title: "Edit", image: UIImage(named: "icon_context_edit"),
action: { [weak self] _ in
guard let strongSelf = self else { return }
guard let cell = strongSelf.savedAddressCollectionView.cellForItem(at: indexPath) as? SavedAddressCollectionViewCell else { return }
cell.removeContextMenu()
cell.dismissContextMenu(completion: nil)
strongSelf.editAddressTapped(with: indexPath)
})
let deleteAction = ContextMenuAction(title: "Delete", image: UIImage(named: "icon_context_delete"), tintColor: UIColor.red,
action: { [weak self] _ in
guard let strongSelf = self else { return }
strongSelf.deleteAddressTapped(with: indexPath)
})
let actions = [favoriteAction, shareAction, deleteAction]
let layout = ContextMenuLayout(width: 120, spacing: 10, padding: 0, sourceViewCornerRadius: 0)
let animation = ContextMenuAnimation(sourceViewBounceRange: 0.9...1.0)
let contextMenu = ContextMenu(title: nil, actions: actions, layout: layout, animation: animation, delegate: self)
return contextMenu
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: SavedAddressCollectionViewCell.identifier, for: indexPath) as! SavedAddressCollectionViewCell
cell.addContextMenu(setupContext(with: indexPath), for: .longPress(duration: 0.3), .tap(numberOfTaps: 1))
return cell
}
check the above code I add a context menu to the collectionView Cell.
check the above screen last one, I'm trying to dismiss on tap outside its not dismissing still it there. also if I push to another controller it still remains there.
Hello there, can you try to call
cell.dismissContextMenu(completion: nil)
before cell.removeContextMenu()
?
yes, I did. still, issues remain there. kindly refer to the screenshots. It's not dismissing. after selecting the context menu action
cell.dismissContextMenu(completion: nil)
cell.removeContextMenu()
Sorry, i didn't really have the time to look into this issue until now.
As a general rule, you shouldn't call removeContextMenu
or dismissContextMenu
within a ContextMenuAction
closure. Everything should automatically be dismissed when the user taps one of the options.
Can you try to remove that or at least try to reproduce the issue using the demo project in this repository?