File tree Expand file tree Collapse file tree
Demo/swiftui/src/commonMain/kotlin/com/pureswift/swiftui Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,20 @@ class Props internal constructor(private val json: JsonObject) {
2020 fun bool (key : String ): Boolean? = (json[key] as ? JsonPrimitive )?.booleanOrNull
2121 // / A color passed from Swift as `PropValue.color(_:)` (an ARGB int).
2222 fun color (key : String ): Color ? = (json[key] as ? JsonPrimitive )?.longOrNull?.let { Color (it.toInt()) }
23+
24+ // Actions: a `ComposableView(actions:)` entry arrives as a callback id; each
25+ // accessor returns a typed lambda that dispatches back to Swift, or null if
26+ // the key is absent. The factory never sees the id or the bridge.
27+ fun voidAction (key : String ): (() -> Unit )? =
28+ (json[key] as ? JsonPrimitive )?.longOrNull?.let { id -> { SwiftBridge .sink.invokeVoid(id) } }
29+ fun boolAction (key : String ): ((Boolean ) -> Unit )? =
30+ (json[key] as ? JsonPrimitive )?.longOrNull?.let { id -> { v -> SwiftBridge .sink.invokeBool(id, v) } }
31+ fun doubleAction (key : String ): ((Double ) -> Unit )? =
32+ (json[key] as ? JsonPrimitive )?.longOrNull?.let { id -> { v -> SwiftBridge .sink.invokeDouble(id, v) } }
33+ fun intAction (key : String ): ((Int ) -> Unit )? =
34+ (json[key] as ? JsonPrimitive )?.longOrNull?.let { id -> { v -> SwiftBridge .sink.invokeInt(id, v) } }
35+ fun stringAction (key : String ): ((String ) -> Unit )? =
36+ (json[key] as ? JsonPrimitive )?.longOrNull?.let { id -> { v -> SwiftBridge .sink.invokeString(id, v) } }
2337}
2438
2539// / The library's single extension point: Kotlin registers named composables;
You can’t perform that action at this time.
0 commit comments