Merge pull request #29 from ServerDriven/debugging-improvements Debugging improvements
Merge pull request #29 from ServerDriven/debugging-improvements
Debugging improvements
ServerDriven SwiftUI Views using ScreenData
import ScreenData import ScreenDataUI
You will need to also import ScreenDataNavigation if you are dealing with ScreenProviding or ScreenStoring.
import ScreenDataNavigation
ScreenProviding
ScreenStoring
SDScreen( screen: SomeScreen( title: "Hello, World!", backgroundColor: SomeColor(red: 1, green: 1, blue: 1), someView: SomeLabel(title: "👋", font: .largeTitle).someView ) )
Note: The title will only show up if there is a NavigationView
import ScreenDataNavigation struct ScreenProvider: ScreenProviding { func screen(forID id: String) -> AnyPublisher<SomeScreen, Error> { Just( SomeScreen( title: "Hello, World!", backgroundColor: SomeColor(red: 1, green: 1, blue: 1), someView: SomeLabel(title: "👋 \(id)", font: .largeTitle).someView ) ) .mapError { Never -> Error in } .eraseToAnyPublisher() } }
class ScreenProviderStore: ObservableObject { private var task: AnyCancellable? @Published var screen: SomeScreen? func fetch(screenID id: String) { task = ScreenProvider().screen(forID: id) .sink( receiveCompletion: { _ in }, receiveValue:{ screen in DispatchQueue.main.async { self.screen = screen } } ) } }
struct ScreenDataContentView: View { @StateObject private var store = ScreenProviderStore() public var baseID: String var body: some View { if let screen = store.screen { NavigationView { SDScreen(screen: screen) } } else { ProgressView() .onAppear { store.fetch(screenID: baseID) } } } }
import SwiftUI import ScreenData import ScreenDataUI struct DividerView: SDCustomizedView { var id: String { "dividerView" } func view(forSomeCustomView customView: SomeCustomView) -> AnyView { AnyView(Divider().background(with: customView.style)) } }
Before showing a SDScreen you can override the ScreenDataUI default values. You can also add your own custom views that conform to SDCustomizedView.
SDScreen
SDCustomizedView
// MARK: SDScreenProvider default SDScreenProvider.default = ScreenProvider() // MARK: SDScreenStore default // FileScreenStore is from ScreenDataNavigation SDScreenStore.default = FileScreenStore(baseKey: "example") // MARK: SDCustomViews // Views that conform to SDCustomizedView SDCustomView.add(customView: DividerView()) // MARK: Default Colors // SDImage.defaultForegroundColor = .white // MARK: SDButton Actions // SDButton.add(actionWithID: "some.id") { print("Button Tapped!") } // MARK: SDFont Values // SDFont.largeTitleFont = Font.custom("Thonburi", size: 34, relativeTo: .largeTitle) SDFont.titleFont = Font.custom("Thonburi", size: 28, relativeTo: .title) SDFont.headlingFont = Font.custom("Thonburi-Bold", size: 17, relativeTo: .headline) SDFont.bodyFont = Font.custom("Thonburi", size: 17, relativeTo: .body) SDFont.footnoteFont = Font.custom("Thonburi", size: 13, relativeTo: .footnote) SDFont.captionFont = Font.custom("Futura-Bold", size: 12, relativeTo: .caption)
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
ScreenDataUI
ServerDriven SwiftUI Views using ScreenData
Usage
You will need to also
import ScreenDataNavigation
if you are dealing withScreenProviding
orScreenStoring
.SDScreen Example
Note: The title will only show up if there is a NavigationView
ScreenProvider Example
ScreenProvider
ScreenProviderStore
ScreenDataContentView
Example SDCustomizedView
Configuration
Before showing a
SDScreen
you can override the ScreenDataUI default values. You can also add your own custom views that conform toSDCustomizedView
.