Skip to content

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