diff --git a/Documentation/DemoApps/GRDBDemo/GRDBDemo/GRDBDemoApp.swift b/Documentation/DemoApps/GRDBDemo/GRDBDemo/GRDBDemoApp.swift index e9c5dc94c..f52b183f4 100644 --- a/Documentation/DemoApps/GRDBDemo/GRDBDemo/GRDBDemoApp.swift +++ b/Documentation/DemoApps/GRDBDemo/GRDBDemo/GRDBDemoApp.swift @@ -11,15 +11,8 @@ struct GRDBDemoApp: App { // MARK: - Give SwiftUI access to the database -private struct AppDatabaseKey: EnvironmentKey { - static var defaultValue: AppDatabase { .empty() } -} - extension EnvironmentValues { - var appDatabase: AppDatabase { - get { self[AppDatabaseKey.self] } - set { self[AppDatabaseKey.self] = newValue } - } + @Entry var appDatabase = AppDatabase.empty() } extension View { diff --git a/Documentation/DemoApps/GRDBDemo/GRDBDemo/Resources/Localizable.xcstrings b/Documentation/DemoApps/GRDBDemo/GRDBDemo/Resources/Localizable.xcstrings index 5ddcf3495..8d20dbef0 100644 --- a/Documentation/DemoApps/GRDBDemo/GRDBDemo/Resources/Localizable.xcstrings +++ b/Documentation/DemoApps/GRDBDemo/GRDBDemo/Resources/Localizable.xcstrings @@ -20,6 +20,12 @@ "state" : "new", "value" : "%lld Players" } + }, + "zero" : { + "stringUnit" : { + "state" : "translated", + "value" : "No Player" + } } } } diff --git a/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerCreationSheet.swift b/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerCreationSheet.swift index 88a798a24..95508c221 100644 --- a/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerCreationSheet.swift +++ b/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerCreationSheet.swift @@ -30,3 +30,9 @@ struct PlayerCreationSheet: View { dismiss() } } + +// MARK: - Previews + +#Preview { + PlayerCreationSheet() +} diff --git a/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerEditionView.swift b/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerEditionView.swift index 15508682f..a8ffabf40 100644 --- a/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerEditionView.swift +++ b/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerEditionView.swift @@ -33,9 +33,10 @@ struct PlayerEditionView: View { } } +// MARK: - Previews + #Preview { NavigationStack { PlayerEditionView(player: .makeRandom()) - .appDatabase(.empty()) } } diff --git a/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerFormView.swift b/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerFormView.swift index b3836d2c7..d3b64687a 100644 --- a/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerFormView.swift +++ b/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerFormView.swift @@ -43,10 +43,20 @@ struct PlayerForm { var score: Int? } -#Preview { +// MARK: - Previews + +#Preview("Prefilled") { @Previewable @State var form = PlayerForm(name: "John", score: 100) Form { PlayerFormView(form: $form) } } + +#Preview("Empty") { + @Previewable @State var form = PlayerForm(name: "", score: nil) + + Form { + PlayerFormView(form: $form) + } +} diff --git a/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerListView.swift b/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerListView.swift index 57d77ddb8..1d4df467f 100644 --- a/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerListView.swift +++ b/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerListView.swift @@ -1,16 +1,7 @@ import SwiftUI -struct PlayerListView: View { +struct PlayerListView: View { @Bindable var model: PlayerListModel - var emptyListActions: EmptyListActions - - init( - model: PlayerListModel, - @ViewBuilder emptyListActions: () -> EmptyListActions = { EmptyView() } - ) { - self.model = model - self.emptyListActions = emptyListActions() - } var body: some View { List { @@ -52,10 +43,24 @@ struct PlayerRow: View { } } +// MARK: - Previews + #Preview { struct Preview: View { - @State var model = PlayerListModel(appDatabase: .random()) + @Environment(\.appDatabase) var appDatabase + var body: some View { + ContentView(appDatabase: appDatabase) + } + } + + struct ContentView: View { + @State var model: PlayerListModel + + init(appDatabase: AppDatabase) { + _model = State(initialValue: PlayerListModel(appDatabase: appDatabase)) + } + var body: some View { NavigationStack { PlayerListView(model: model) @@ -64,5 +69,5 @@ struct PlayerRow: View { } } - return Preview() + return Preview().appDatabase(.random()) } diff --git a/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerNavigationView.swift b/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerNavigationView.swift index 14653c3d9..8b4ce9bf8 100644 --- a/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerNavigationView.swift +++ b/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerNavigationView.swift @@ -165,7 +165,14 @@ private struct ToggleOrderingButton: View { } } -#Preview { +// MARK: - Previews + +#Preview("Populated") { PlayerNavigationView() .appDatabase(.random()) } + +#Preview("Empty") { + PlayerNavigationView() + .appDatabase(.empty()) +}