Skip to content

Commit

Permalink
Allow for simple Spezi configuration within Previews
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Jan 7, 2024
1 parent d56ed07 commit 28b660a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
9 changes: 4 additions & 5 deletions Sources/Spezi/Configuration/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@
/// Defines the ``Standard`` and ``Module``s that are used in a Spezi project.
///
/// Ensure that your standard conforms to all protocols enforced by the ``Module``s. If your ``Module``s require protocol conformances
/// you must add them to your custom type conforming to ``Standard`` and passed to the initializer or extend a prebuild standard.
/// you must add them to your custom type conforming to ``Standard`` and passed to the initializer or extend a prebuilt standard.
///
/// Use ``Configuration/init(_:)`` to use default empty standard instance only conforming to ``Standard`` if you do not use any ``Module`` requiring custom protocol conformances.
///
///
/// The following example demonstrates the usage of an `ExampleStandard` standard and reusable Spezi modules, including the `HealthKit` and `QuestionnaireDataSource` modules:
/// ```swift
/// import Spezi
/// import HealthKit
/// import HealthKitDataSource
/// import Questionnaires
/// import SpeziHealthKit
/// import SpeziOnboarding
/// import SwiftUI
///
///
Expand All @@ -35,7 +34,7 @@
/// )
/// }
/// }
/// QuestionnaireDataSource()
/// OnboardingDataSource()
/// }
/// }
/// }
Expand Down
8 changes: 6 additions & 2 deletions Sources/Spezi/Spezi.docc/Spezi.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ To simplify the creation of modules, a common set of functionalities typically u
### Configuration

- <doc:Initial-Setup>
- ``SwiftUI/View/spezi(_:)``
- ``SpeziAppDelegate``
- ``Configuration``
- ``SwiftUI/View/spezi(_:)-3bn89``

### Essential Concepts

Expand All @@ -87,4 +87,8 @@ To simplify the creation of modules, a common set of functionalities typically u
- ``Spezi/Spezi``
- ``Standard``
- ``Module``


### Previews

- ``SwiftUI/View/spezi(standard:_:)``
- ``SwiftUI/View/spezi(_:)-8giv6``
34 changes: 31 additions & 3 deletions Sources/Spezi/Spezi/View+Spezi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,40 @@ struct SpeziViewModifier: ViewModifier {


extension View {
/// Use the `spezi()` `View` modifier to configure Spezi for your application.
/// - Parameter delegate: The `SpeziAppDelegate` used in the SwiftUI `App` instance.
/// - Returns: A SwiftUI view configured using the Spezi framework
/// Configure Spezi for your application using a delegate.
/// - Parameter delegate: The ``SpeziAppDelegate`` used in the SwiftUI App instance.
/// - Returns: The configured view using the Spezi framework.
public func spezi(_ delegate: SpeziAppDelegate) -> some View {
modifier(SpeziViewModifier(delegate.spezi))
}

/// Configure Spezi for your previews using a Standard and a collection of Modules.
///
/// This modifier can be used to configure Spezi with a Standard a collection of Modules without declaring a ``SpeziAppDelegate``.
///
/// - Important: This modifier is only recommended for Previews. As it doesn't configure a ``SpeziAppDelegate`` lifecycle handling
/// functionality, using ``LifecycleHandler``, of modules won't work.
///
/// - Parameters:
/// - standard: The global ``Standard`` used throughout the app to manage global data flow.
/// - modules: The ``Module``s used in the Spezi project.
/// - Returns: The configured view using the Spezi framework.
public func spezi<S: Standard>(standard: S, @ModuleBuilder _ modules: () -> ModuleCollection) -> some View {
modifier(SpeziViewModifier(Spezi(standard: standard, modules: modules().elements)))
}

Check warning on line 50 in Sources/Spezi/Spezi/View+Spezi.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Spezi/Spezi/View+Spezi.swift#L48-L50

Added lines #L48 - L50 were not covered by tests

/// Configure Spezi for your previews using a collection of Modules.
///
/// This modifier can be used to configure Spezi with a collection of Modules without declaring a ``SpeziAppDelegate``.
///
/// - Important: This modifier is only recommended for Previews. As it doesn't configure a ``SpeziAppDelegate`` lifecycle handling
/// functionality, using ``LifecycleHandler``, of modules won't work.
///
/// - Parameter modules: The ``Module``s used in the Spezi project.
/// - Returns: The configured view using the Spezi framework.
public func spezi(@ModuleBuilder _ modules: () -> ModuleCollection) -> some View {
spezi(standard: DefaultStandard(), modules)
}

Check warning on line 63 in Sources/Spezi/Spezi/View+Spezi.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Spezi/Spezi/View+Spezi.swift#L61-L63

Added lines #L61 - L63 were not covered by tests
}


Expand Down

0 comments on commit 28b660a

Please sign in to comment.