UI Components
Components can have UI which gets rendered by the platform
Last updated
Components can have UI which gets rendered by the platform
Last updated
import CloneableCore
import CloneablePlatformiOS
struct ExampleView : View, ComponentView { // <- conform to ComponentView
var staticComponentID: String // required: provided by SDK
var dynamicComponentID: String // required: provided by SDK
var component: DeployedWorkflow_components // required: provided by SDK
// The following view model is not required by the protocol, but it is assumed
// that you will have a model which conforms to `ComponentSubscriber` and
// subscribes to the workflow framework on initialization
@StateObject var exampleModel: ExampleModel
// Currently in order to initialize the model, we must use an init in the SwiftUI view
init(staticComponentID: String, dynamicComponentID: String, component: DeployedWorkflow_components) {
self.staticComponentID = staticComponentID
self.dynamicComponentID = dynamicComponentID
self.component = component
// initialize the ExampleModel as a wrapped StateObject so that it only get's initialized
// on the first rendering of the view and will not get re-rendered on subsequent renders
// this is recommended usage by apple
_exampleModel = StateObject(wrappedValue: ExampleModel(dynamicComponentID: dynamicComponentID, staticComponentID: staticComponentID, component: component))
}
var body: some View {
VStack {
HStack {
Spacer()
Button(action: {self.exampleModel.triggerNavigationOutput()}) { // <- custom function in the model to send an output for the navigation
Text("Click to navigate")
}
}
}
}
}