Swiftpack.co -  ServerDriven/ScreenDataUI-ios as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
ServerDriven/ScreenDataUI-ios
SwiftUI Views for ScreenData
.package(url: "https://github.com/ServerDriven/ScreenDataUI-ios.git", from: "0.7.0")

ScreenDataUI

ServerDriven SwiftUI Views using ScreenData

Usage

import ScreenData
import ScreenDataUI

You will need to also import ScreenDataNavigation if you are dealing with ScreenProviding or ScreenStoring.

SDScreen Example

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

ScreenProvider Example

ScreenProvider

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()
    }
}

ScreenProviderStore

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
                    }
                }
            )
    }
}

ScreenDataContentView

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)
                }
        }
    }
}

Example SDCustomizedView

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))
    }
}

Configuration

Before showing a SDScreen you can override the ScreenDataUI default values. You can also add your own custom views that conform to SDCustomizedView.

// MARK: SDScreenProvider default

SDScreenProvider.default = ScreenProvider()

// MARK: SDScreenStore default
// UserDefaultScreenStorer is from ScreenDataNavigation

SDScreenStore.default = UserDefaultScreenStorer(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)

GitHub

link
Stars: 2
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

0.7.0
1 week ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API