-
Notifications
You must be signed in to change notification settings - Fork 58
Open
Description
Current problem:
the use of subscript(dynamicMember member: String) obfuscates which properties are available.
this makes it hard to get started with theming.
SwiftUI's Environment provides a nice solution to that exact problem. The result is a type safe key that is easy to implement in custom nodes and easy to use when theming.
I think it would be relatively easy adapting it to this library (I was able to do naive refactor in just a few minutes)
protocol ThemeKey {
static var defaultValue: AttributedDict { get }
}
struct Theme {
private var attributes: [ObjectIdentifier: AttributeDict] = [:]
public subscript<Key: ThemeKey>(_ key: Key.Type) -> AttributeDict {
get {
return attributes[ObjectIdentifier(key)] ?? Key.defaultValue
}
set {
attributes[ObjectIdentifier(key)] = newValue
}
}
}An implementation for the link node could look like this:
fileprivate struct LinkThemeKey {
static let defaultValue: AttributedDict = [.foregroundColor: UIColor.blue]
}
extension Theme {
var link: AttributedDict {
get {
self[LinkThemeKey.self]
}
set {
self[LinkThemeKey.self] = newValue
}
}
}Is there an interest in moving the library towards a more typed approach like this?
I would be willing to work on this myself
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels