Skip to main content
Version: Next

OCActionSheet: UI Component

Introduction

OCActionSheet component can be used to show action sheet information from users. It appears as an overlay to the content it was added to.

OCActionSheet

OCActionSheet is developed as a view modifier and can be configured to show array of items like normal options and delete options. The actions in actionSheet can be given using actions view builder. OCActionSheet 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 ActionSheet component folder into your Xcode project.

  2. Use the OCActionSheet view in your SwiftUI code:

import SwiftUI

struct ContentView: View {
@State private var isActionEnabled = false
var actionSheetItems: [any OCActionSheetItemProtocol] = [
OCActionSheetItems(title: "option 1", isDestructive: false),
OCActionSheetItems(title: "option 2", isDestructive: false),
OCActionSheetItems(title: "option 3", isDestructive: false),
OCActionSheetItems(title: "option 4", isDestructive: false),
OCActionSheetItems(title: "Destructive action", isDestructive: true)]

var body: some View {
VStack {
Text("Show/hide ActionSheet")
.onTapGesture {
isActionEnabled.toggle()
}
.ocActionSheetView(isActionEnabled: $isActionEnabled, items: actionSheetItems) { item in

}
}
}
}