OCContextMenu: UI Component
Introduction
OCContextMenu component can be used to show OCContextMenu information from users. It appears as an overlay to the content it was added to.
OCContextMenu
OCContextMenu is developed as a view modifier and can be configured to show array of items like normal options and delete options.
The actions in ContextMenu can be given using actions view builder. OCContextMenu init takes 3 parameters,
- isPresented, a binding bool to show/ hide the actionSheet
- items, protocol array of items.
- actions, a view builder that accepts the buttons to be shown for the actionSheet
Installation
-
Copy the
ContextMenucomponent folder into your Xcode project. -
Use the
OCContextMenuview in your SwiftUI code:
import SwiftUI
struct ContentView: View {
@State var isPresented: Bool = true
var contextMenuItems: [OCContextMenuItems] = [
OCContextMenuItems(title: "Label", icon: .local(image: Image.iconImage), isDestructive: false),
OCContextMenuItems(title: "Label", icon: .local(image: Image.iconImage), isDestructive: false),
OCContextMenuItems(title: "Label", icon: .local(image: Image.iconImage), isDestructive: false),
OCContextMenuItems(title: "Copy", icon: .local(image: Image.iconImage), isDestructive: false),
OCContextMenuItems(title: "Paste", icon: .local(image: Image.iconImage), isDestructive: false),
OCContextMenuItems(title: "Cut", icon: .local(image: Image.iconImage), isDestructive: false),
OCContextMenuItems(title: "Delete", icon: .local(image: Image.iconImage), isDestructive: true)
]
var body: some View {
Text("show")
.onTapGesture {
isPresented.toggle()
}
.ocContextMenu(isPresented: $isPresented, contextMenuItems: contextMenuItems) { _ in
}
}
}