WorkflowView

@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *)
public struct WorkflowView<Content> : View where Content : View

Used to build a Workflow in SwiftUI; Embed WorkflowItems in a WorkflowView to create a SwiftUI view.

Discussion

The preferred method for creating a Workflow with SwiftUI is a combination of WorkflowView and WorkflowItem. Initialize with arguments if your first FlowRepresentable has an input type.

Example

WorkflowView(isLaunched: $isLaunched.animation(), launchingWith: "String in") {
    WorkflowItem(FirstView.self)
        .applyModifiers {
            $0.background(Color.gray)
            .transition(.slide)
            .animation(.spring())
        }
    WorkflowItem(SecondView.self)
        .persistence(.removedAfterProceeding)
        .applyModifiers {
            $0.SecondViewSpecificModifier()
            .padding(10)
            .background(Color.purple)
            .transition(.opacity)
            .animation(.easeInOut)
        }
}
.onAbandon { print("isLaunched is now false") }
.onFinish { args in print("Finished 1: \(args)") }
.onFinish { print("Finished 2: \($0)") }
.background(Color.green)
  • Declaration

    Swift

    public var body: some View { get }
  • Creates a base for proceeding with a WorkflowItem.

    Declaration

    Swift

    public init<WI: _WorkflowItemProtocol>(isLaunched: Binding<Bool> = .constant(true),
                                           @WorkflowBuilder content: () -> WI) where Content == WorkflowLauncher<WI>, WI.FlowRepresentableType.WorkflowInput == Never

    Parameters

    isLaunched

    binding that controls launching the underlying Workflow.

    content

    WorkflowBuilder consisting of WorkflowItems that define your workflow.

  • Creates a base for proceeding with a WorkflowItem.

    Declaration

    Swift

    public init<WI: _WorkflowItemProtocol>(isLaunched: Binding<Bool> = .constant(true),
                                           launchingWith args: WI.FlowRepresentableType.WorkflowInput,
                                           @WorkflowBuilder content: () -> WI) where Content == WorkflowLauncher<WI>

    Parameters

    isLaunched

    binding that controls launching the underlying Workflow.

    launchingWith

    arguments passed to the first loaded FlowRepresentable in the underlying Workflow.

    content

    WorkflowBuilder consisting of WorkflowItems that define your workflow.

  • Creates a base for proceeding with a WorkflowItem.

    Declaration

    Swift

    public init<WI: _WorkflowItemProtocol>(isLaunched: Binding<Bool> = .constant(true),
                                           launchingWith args: AnyWorkflow.PassedArgs,
                                           @WorkflowBuilder content: () -> WI) where Content == WorkflowLauncher<WI>, WI.FlowRepresentableType.WorkflowInput == AnyWorkflow.PassedArgs

    Parameters

    isLaunched

    binding that controls launching the underlying Workflow.

    launchingWith

    arguments passed to the first loaded FlowRepresentable in the underlying Workflow.

    content

    WorkflowBuilder consisting of WorkflowItems that define your workflow.

  • Creates a base for proceeding with a WorkflowItem.

    Declaration

    Swift

    public init<WI: _WorkflowItemProtocol>(isLaunched: Binding<Bool> = .constant(true),
                                           launchingWith args: AnyWorkflow.PassedArgs,
                                           @WorkflowBuilder content: () -> WI) where Content == WorkflowLauncher<WI>

    Parameters

    isLaunched

    binding that controls launching the underlying Workflow.

    launchingWith

    arguments passed to the first loaded FlowRepresentable in the underlying Workflow.

    content

    WorkflowBuilder consisting of WorkflowItems that define your workflow.

  • Creates a base for proceeding with a WorkflowItem.

    Declaration

    Swift

    public init<A, WI: _WorkflowItemProtocol>(isLaunched: Binding<Bool> = .constant(true),
                                              launchingWith args: A,
                                              @WorkflowBuilder content: () -> WI) where Content == WorkflowLauncher<WI>, WI.FlowRepresentableType.WorkflowInput == AnyWorkflow.PassedArgs

    Parameters

    isLaunched

    binding that controls launching the underlying Workflow.

    launchingWith

    arguments passed to the first loaded FlowRepresentable in the underlying Workflow.

    content

    WorkflowBuilder consisting of WorkflowItems that define your workflow.

  • Creates a base for proceeding with a WorkflowItem.

    Declaration

    Swift

    public init<A, WI: _WorkflowItemProtocol>(isLaunched: Binding<Bool> = .constant(true),
                                              launchingWith args: A,
                                              @WorkflowBuilder content: () -> WI) where Content == WorkflowLauncher<WI>, WI.FlowRepresentableType.WorkflowInput == Never

    Parameters

    isLaunched

    binding that controls launching the underlying Workflow.

    launchingWith

    arguments passed to the first loaded FlowRepresentable in the underlying Workflow.

    content

    WorkflowBuilder consisting of WorkflowItems that define your workflow.

  • Creates a base for proceeding with a WorkflowItem.

    Declaration

    Swift

    public init<WI: _WorkflowItemProtocol>(isLaunched: Binding<Bool> = .constant(true),
                                           @WorkflowBuilder content: () -> WI) where Content == WorkflowLauncher<WI>, WI.FlowRepresentableType.WorkflowInput == AnyWorkflow.PassedArgs

    Parameters

    isLaunched

    binding that controls launching the underlying Workflow.

    content

    WorkflowBuilder consisting of WorkflowItems that define your workflow.

  • Creates a base for proceeding with a WorkflowItem.

    Declaration

    Swift

    public init(isLaunched: Binding<Bool> = .constant(true),
                launchingWith startingArgs: AnyWorkflow.PassedArgs = .none,
                workflow: AnyWorkflow) where Content == WorkflowLauncher<WorkflowItemWrapper<AnyWorkflowItem, Never>>

    Parameters

    isLaunched

    binding that controls launching the underlying Workflow.

    startingArgs

    arguments passed to the first loaded FlowRepresentable in the underlying Workflow.

    workflow

    workflow to be launched; must contain FlowRepresentables of type View

  • Creates a base for proceeding with a WorkflowItem.

    Declaration

    Swift

    public init<A>(isLaunched: Binding<Bool> = .constant(true), launchingWith startingArgs: A, workflow: AnyWorkflow) where Content == WorkflowLauncher<WorkflowItemWrapper<AnyWorkflowItem, Never>>

    Parameters

    isLaunched

    binding that controls launching the underlying Workflow.

    startingArgs

    arguments passed to the first loaded FlowRepresentable in the underlying Workflow.

    workflow

    workflow to be launched; must contain FlowRepresentables of type View

  • Adds an action to perform when this Workflow has finished.

    Declaration

    Swift

    public func onFinish<WI>(_ closure: @escaping (AnyWorkflow.PassedArgs) -> Void) -> WorkflowView<Content> where Content == WorkflowLauncher<WI>, WI : _WorkflowItemProtocol
  • Adds an action to perform when this Workflow has abandoned.

    Declaration

    Swift

    public func onAbandon<WI>(_ closure: @escaping () -> Void) -> WorkflowView<Content> where Content == WorkflowLauncher<WI>, WI : _WorkflowItemProtocol
  • Subscribers to a combine publisher, when a value is emitted the workflow will abandon.

    Declaration

    Swift

    public func abandonOn<WI, P>(_ publisher: P) -> WorkflowView<Content> where Content == WorkflowLauncher<WI>, WI : _WorkflowItemProtocol, P : Publisher, P.Failure == Never
  • Wraps content in a NavigationView.

    Declaration

    Swift

    public func embedInNavigationView<WI>() -> WorkflowView<Content> where Content == WorkflowLauncher<WI>, WI : _WorkflowItemProtocol