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

Context menu improvements #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ddanilyuk
Copy link

Hi! I really like your framework and I found a case where it doesn't quite work. I use it for creating chat and I needed to create a context menu for the message bubble. But in this version of the framework this cannot be done.
I add some methods from UITableViewDelegate to select view from cell which will be used by the context menu.

Added methods from UITableViewDelegate:

  • previewForHighlightingContextMenuWithConfiguration
  • previewForDismissingContextMenuWithConfiguration

Some code example how to use new functionality:

let row = TableRow<MessageTableViewCell>(item: message)
  .on(.showContextMenu) { item -> UIContextMenuConfiguration in
      
      // Here you need to path indexPath to identifier.
      return UIContextMenuConfiguration(identifier: item.indexPath as NSIndexPath, previewProvider: nil) { _ in
          
          let copyAction = UIAction(title: R.string.chat.copy(), image: R.image.messageCopy())
          let deleteAction = UIAction(title: R.string.chat.delete(), image: R.image.messageDelete(), attributes: .destructive) 
          return UIMenu(children: [copyAction, deleteAction])
      }
  }
  // !New methods!
  .on(.previewForHighlightingContextMenu) { item -> UITargetedPreview in
      
      // Choosing view to use in contextMenu
      let view = cell.messageBackgroundView ?? UIView()
  
      // Choosing parameters
      let parameters = UIPreviewParameters()
      parameters.backgroundColor = .clear
      parameters.visiblePath = UIBezierPath(roundedRect: view.bounds, cornerRadius: 10))
  
      return UITargetedPreview(view: view, parameters: parameters)
  }
  .on(.previewForDismissingContextMenu) { item -> UITargetedPreview in
      
      let view = cell.messageBackgroundView ?? UIView()
      
      // Choosing parameters
      let parameters = UIPreviewParameters()
      parameters.backgroundColor = .clear
      parameters.visiblePath = UIBezierPath(roundedRect: view.bounds, cornerRadius: 10))
  
      return UITargetedPreview(view: view, parameters: parameters)
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant