https://github.com/honqii/contextmenumodifier
Simply convert UIContextMenuInteraction to SwiftUI Modifier
https://github.com/honqii/contextmenumodifier
context-menu contextmenu modifier swift swiftui swiftui-components
Last synced: 10 months ago
JSON representation
Simply convert UIContextMenuInteraction to SwiftUI Modifier
- Host: GitHub
- URL: https://github.com/honqii/contextmenumodifier
- Owner: HonQii
- License: mit
- Created: 2021-05-27T09:51:43.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-05-30T01:16:32.000Z (almost 5 years ago)
- Last Synced: 2023-08-05T02:37:38.144Z (over 2 years ago)
- Topics: context-menu, contextmenu, modifier, swift, swiftui, swiftui-components
- Language: Swift
- Homepage:
- Size: 6.59 MB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ContextMenuModifier
Simply convert UIContextMenuInteraction to SwiftUI Modifier
## Usage
import the package in the file you would like to use it: `import ContextMenuModifier`
You can use it as system `.contextMenu` modifier
### Display custom view as context menu preview
code:
```swift
Text("Popup custom preview!")
.previewContextMenu(preview: VStack {
Image(systemName: "face.smiling")
.font(.largeTitle)
.foregroundColor(Color(UIColor.systemYellow))
Text("This is another preview content")
}, actions: [
UIAction(title: "Only Title", handler: { _ in }),
UIAction(title: "Title with image", image: UIImage(systemName: "plus"), handler: { _ in }),
UIAction(title: "Desctructive action", attributes: .destructive, handler: { _ in })
])
```
### Display destination as preview
code:
```swift
Text("Popup destination as preview!")
.previewContextMenu(destination: Text("This is destination view"), actions: [
UIAction(title: "Only Title", handler: { _ in }),
UIAction(title: "Title with image", image: UIImage(systemName: "plus"), handler: { _ in }),
UIAction(title: "Desctructive action", attributes: .destructive, handler: { _ in })
])
```
### Custom context preview and destination
code:
```swift
Text("Popup custom preview and destination!")
.previewContextMenu(
destination: Text("This is custom destination view"),
preview: VStack {
Image(systemName: "face.smiling")
.font(.largeTitle)
.foregroundColor(Color(UIColor.systemYellow))
Text("This is another preview content")
},
actions: [
UIAction(title: "Only Title", handler: { _ in }),
UIAction(title: "Title with image", image: UIImage(systemName: "plus"), handler: { _ in }),
UIAction(title: "Desctructive action", attributes: .destructive, handler: { _ in })
]
)
```
### Custom preferred size for preview
```code
Text("Custom Preview and destination with custom size!")
.previewContextMenu(
destination: VStack {
Image(systemName: "face.smiling")
.font(.largeTitle)
.foregroundColor(Color(UIColor.systemYellow))
Text("This is another preview content")
},
preview: Text("This is another preview content"),
preferredContentSize: .init(width: 200, height: 200),
actions: [
UIAction(title: "Only Title", handler: { _ in }),
UIAction(title: "Title with image", image: UIImage(systemName: "plus"), handler: { _ in }),
UIAction(title: "Desctructive action", attributes: .destructive, handler: { _ in })
]
)
```
### Popup destination view as sheet
code:
```swift
Text("Popup destination as sheet")
.previewContextMenu(
destination: VStack {
Image(systemName: "face.smiling")
.font(.largeTitle)
.foregroundColor(Color(UIColor.systemYellow))
Text("This is another preview content")
},
preview: Text("This is another preview content"),
presentAsSheet: true,
actions: [
UIAction(title: "Only Title", handler: { _ in }),
UIAction(title: "Title with image", image: UIImage(systemName: "plus"), handler: { _ in }),
UIAction(title: "Desctructive action", attributes: .destructive, handler: { _ in })
]
)
```