Skip to main content
Version: 12.10.0

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,

  1. isPresented, a binding bool to show/ hide the actionSheet
  2. items, protocol array of items.
  3. actions, a view builder that accepts the buttons to be shown for the actionSheet

Installation

  1. Copy the ContextMenu component folder into your Xcode project.

  2. Use the OCContextMenu view 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

}
}
}