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,
- 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
ActionSheet
component folder into your Xcode project. -
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
}
}
}
}