Using some code in a SwiftUI view that, e.g., uses an @EnvironmentObject injected by Spezi requires the manual annotation in the SwiftUI preview to inject this object:
struct ScheduleView: View {
@EnvironmentObject var scheduler: TemplateApplicationScheduler
var body: some View {
// ...
}
}
struct SchedulerView_Previews: PreviewProvider {
static var previews: some View {
ScheduleView()
.environmentObject(TemplateApplicationScheduler())
}
}
While this is possible for simple components with no @Dependency-annotated components, injecting more complex components that require the injection of dependencies makes this difficult.
Solution
We propose the creation of a .previewComponent(...) or .previewComponents(...) view modifier that injects a specified amount of components in the environment.
The modifier would also require the definition of the associated standard or any generic requirement that are imposed on a component.
Additional context
Input on the design of this preview injection mechanism is greatly welcome. Please leave your thoughts and comments under this issue.
Code of Conduct
[X] I agree to follow this project's Code of Conduct and Contributing Guidelines
Problem
Using some code in a SwiftUI view that, e.g., uses an
@EnvironmentObject
injected by Spezi requires the manual annotation in the SwiftUI preview to inject this object:While this is possible for simple components with no
@Dependency
-annotated components, injecting more complex components that require the injection of dependencies makes this difficult.Solution
We propose the creation of a
.previewComponent(...)
or.previewComponents(...)
view modifier that injects a specified amount of components in the environment.The modifier would also require the definition of the associated standard or any generic requirement that are imposed on a component.
Additional context
Input on the design of this preview injection mechanism is greatly welcome. Please leave your thoughts and comments under this issue.
Code of Conduct