The OnboardingStack identifies the individual views via the type name of the respective view (required for ordered navigation operations).
For trivial use cases, this identification method is sufficient. However, for more advanced onboarding flows that contain multiple instances of the same View, this mechanism begins to fall apart.
Solution
We envision a custom ViewModifier in combination with a protocol that can be applied to Views within the OnboardingStack. This enables to customize the identifier of the onboarding Views, enabling more complex onboarding flows. The default identifier should still be inferred from the type of the View.
The protocol enforces a get computed property (e.g., var viewIdentifier) that is able to fetch the identifier of a View set via a custom ViewModifier (e.g. .onboardingIdentifier(_: String) on a View used in the OnboardingStack.
The public API would then look similar to this:
struct OnboardingFlow: View {
var view: some View {
OnboardingStack {
TestView1()
.onboardingIdentifier("...")
TestView2()
TestView1()
.onboardingIdentifier("...")
}
}
}
struct TestView1: OnboardingView {
var viewIdentifier: ID = "..."
var view: some View {
// ...
}
}
Additional context
It might be a good idea to utilize the Identifiable protocol from Swift for the custom protocol enabling to get the View identifier.
Problem
The
OnboardingStack
identifies the individual views via the type name of the respective view (required for ordered navigation operations). For trivial use cases, this identification method is sufficient. However, for more advanced onboarding flows that contain multiple instances of the same View, this mechanism begins to fall apart.Solution
We envision a custom
ViewModifier
in combination with a protocol that can be applied toView
s within theOnboardingStack
. This enables to customize the identifier of the onboardingView
s, enabling more complex onboarding flows. The default identifier should still be inferred from the type of the View. The protocol enforces aget
computed property (e.g.,var viewIdentifier
) that is able to fetch the identifier of aView
set via a customViewModifier
(e.g..onboardingIdentifier(_: String)
on aView
used in theOnboardingStack
.The public API would then look similar to this:
Additional context
It might be a good idea to utilize the
Identifiable
protocol from Swift for the custom protocol enabling to get theView
identifier.Sadly, there seems to be no way to utilize existing SwiftUI infrastructure like https://developer.apple.com/documentation/swiftui/view/id(_:) or https://developer.apple.com/documentation/swiftui/view/tag(_:), as one cannot access these data points on a
View
. The only option might be something like https://github.com/siteline/swiftui-introspect, but this would require significant further investigation.Code of Conduct