Skip to content

Commit 1a214af

Browse files
committed
Add literal conveniences to PropValue
1 parent f0ca64f commit 1a214af

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

AndroidSwiftUICore/Sources/AndroidSwiftUICore/RenderNode.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@ public enum PropValue: Equatable, Sendable {
1616
case array([PropValue])
1717
}
1818

19+
// Literal conveniences so custom-composable props read as a plain dictionary:
20+
// `["url": "https://…", "zoom": 1.5, "stars": 3, "on": true]`.
21+
extension PropValue: ExpressibleByStringLiteral {
22+
public init(stringLiteral value: String) { self = .string(value) }
23+
}
24+
extension PropValue: ExpressibleByFloatLiteral {
25+
public init(floatLiteral value: Double) { self = .double(value) }
26+
}
27+
extension PropValue: ExpressibleByIntegerLiteral {
28+
public init(integerLiteral value: Int) { self = .int(value) }
29+
}
30+
extension PropValue: ExpressibleByBooleanLiteral {
31+
public init(booleanLiteral value: Bool) { self = .bool(value) }
32+
}
33+
extension PropValue: ExpressibleByArrayLiteral {
34+
public init(arrayLiteral elements: PropValue...) { self = .array(elements) }
35+
}
36+
37+
public extension PropValue {
38+
/// A color as its 0xAARRGGBB integer, for passing to a custom composable.
39+
static func color(_ color: Color) -> PropValue { color.propValue }
40+
}
41+
1942
/// One entry in a node's ordered modifier chain. Order is significant:
2043
/// `.padding().background()` folds to a Compose `Modifier` in the same order.
2144
public struct ModifierNode: Equatable, Sendable {

0 commit comments

Comments
 (0)