KeyValueView

0.1.0

A Color and String KeyValue SwiftUI View
0xLeif/KeyValueView

What's New

0.1.0

2021-06-16T18:04:12Z

Usage

import KeyValueView

Example

public enum SomeColors: String, Hashable {
    case textColor, backgroundColor, iconColor
}

public enum SomeStrings: String, Hashable {
    case usageDescription
}

public struct SomeView<
    ColorDictionary: ColorProviding,
    StringDictionary: StringProviding
>: KeyValueView where ColorDictionary.ColorKey == SomeColors,
                    StringDictionary.StringKey == SomeStrings {
                    
    public var colorDictionary: ColorDictionary
    public var stringDictionary: StringDictionary
    
    public init(
        colorDictionary: ColorDictionary,
        stringDictionary: StringDictionary
    ) {
        self.colorDictionary = colorDictionary
        self.stringDictionary = stringDictionary
    }
    
    public var body: some View {
        Text(string(forKey: .usageDescription, defaultString: "👋"))
            .foregroundColor(color(forKey: .textColor, defaultColor: .white))
            .background(color(forKey: .backgroundColor, defaultColor: .clear))
    }
}

Using a KeyValueView

Define Colors and Strings

struct SomeColorDictionary: ColorProviding {
    var colors: [SomeColors : UIColor] = [
        .backgroundColor: .orange,
        .textColor: .blue
    ]
}

struct SomeStringDictionary: StringProviding {
    var strings: [SomeStrings : String] = [
        .usageDescription: "import KeyValueView"
    ]
}

Create a KeyValueView

SomeView(
    colorDictionary: SomeColorDictionary(),
    stringDictionary: SomeStringDictionary()
)

KeyValueView

A Color and String KeyValue SwiftUI View

Usage

import KeyValueView

Example

public enum SomeColors: String, Hashable {
    case textColor, backgroundColor, iconColor
}

public enum SomeStrings: String, Hashable {
    case usageDescription
}

public struct SomeView<
    ColorDictionary: ColorProviding,
    StringDictionary: StringProviding
>: KeyValueView where ColorDictionary.ColorKey == SomeColors,
                    StringDictionary.StringKey == SomeStrings {
                    
    public var colorDictionary: ColorDictionary
    public var stringDictionary: StringDictionary
    
    public init(
        colorDictionary: ColorDictionary,
        stringDictionary: StringDictionary
    ) {
        self.colorDictionary = colorDictionary
        self.stringDictionary = stringDictionary
    }
    
    public var body: some View {
        Text(string(forKey: .usageDescription, defaultString: "👋"))
            .foregroundColor(color(forKey: .textColor, defaultColor: .white))
            .background(color(forKey: .backgroundColor, defaultColor: .clear))
    }
}

Using a KeyValueView

Define Colors and Strings

struct SomeColorDictionary: ColorProviding {
    var colors: [SomeColors : UIColor] = [
        .backgroundColor: .orange,
        .textColor: .blue
    ]
}

struct SomeStringDictionary: StringProviding {
    var strings: [SomeStrings : String] = [
        .usageDescription: "import KeyValueView"
    ]
}

Create a KeyValueView

SomeView(
    colorDictionary: SomeColorDictionary(),
    stringDictionary: SomeStringDictionary()
)

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Oct 18 2024 20:05:48 GMT-0900 (Hawaii-Aleutian Daylight Time)