-
Notifications
You must be signed in to change notification settings - Fork 0
SwiftUI Usage
ChiefVenzox edited this page Jun 5, 2026
·
1 revision
Import NotebookFlowKit and render a flow from a JSON file in your app bundle.
import SwiftUI
import NotebookFlowKit
struct OnboardingView: View {
var body: some View {
NotebookFlowView(fileName: "starter_flow") { result in
print(result.answers)
}
}
}By default, NotebookFlowView loads from .main.
NotebookFlowView(fileName: "starter_flow") { result in
print(result.answers)
}You can also pass a bundle explicitly:
NotebookFlowView(
fileName: "starter_flow",
bundle: .main,
onComplete: { result in
print(result.answers)
}
)You can construct a flow directly in Swift:
let flow = NotebookFlow(
name: "StarterFlow",
screens: [
FlowScreen(
id: "welcome",
type: .text,
title: "Welcome",
next: "goal"
),
FlowScreen(
id: "goal",
type: .choice,
title: "What is your goal?",
options: ["Focus", "Learning"],
next: "done"
),
FlowScreen(
id: "done",
type: .completion,
title: "You're ready"
)
]
)
NotebookFlowView(flow: flow) { result in
print(result.answers)
}The completion callback receives a FlowResult.
NotebookFlowView(fileName: "starter_flow") { result in
print(result.flowName)
print(result.answers)
}Use typed helpers when you know the expected answer type.
let name = result.text("name")
let goal = result.choice("goal")
let topics = result.choices("topics")Raw answers are also available:
switch result.answers["goal"] {
case .choice(let value):
print(value)
case .choices(let values):
print(values)
case .text(let value):
print(value)
case nil:
break
}NotebookFlowKit shows progress by default.
Disable it when your app already has its own progress UI:
NotebookFlowView(
fileName: "starter_flow",
showsProgress: false,
onComplete: { result in
print(result.answers)
}
)FlowStateManager owns navigation state and collected answers.
It exposes:
currentScreenanswersisCompletedcanGoBackcanAdvancecurrentStepIndextotalScreensprogressFraction
This keeps navigation logic testable outside SwiftUI.