@@ -2,10 +2,12 @@ package com.pureswift.swiftui
22
33import androidx.compose.runtime.Immutable
44import kotlinx.serialization.Serializable
5+ import kotlinx.serialization.json.Json
56import kotlinx.serialization.json.JsonObject
67import kotlinx.serialization.json.JsonPrimitive
78import kotlinx.serialization.json.booleanOrNull
89import kotlinx.serialization.json.doubleOrNull
10+ import kotlinx.serialization.json.jsonObject
911import kotlinx.serialization.json.longOrNull
1012
1113// / One entry in a node's ordered modifier chain. Order is significant: the
@@ -39,6 +41,33 @@ data class ViewNode(
3941 val itemProviderId : Long? = null ,
4042) {
4143
44+ // / Bridge constructor: the Swift materializer builds nodes through this,
45+ // / crossing JNI with flat arrays (one call per node, arrays as single
46+ // / arguments). Prop and modifier-arg values arrive as JSON literals
47+ // / ("\"text\"", "42", "true"), keeping the typed JsonObject model without
48+ // / per-field JNI calls. Negative count/provider mean "absent".
49+ constructor (
50+ type: String ,
51+ id: String ,
52+ propKeys: Array <String >,
53+ propValues: Array <String >,
54+ modifierKinds: Array <String >,
55+ modifierArgs: Array <String >,
56+ children: Array <ViewNode >,
57+ count: Int ,
58+ itemProviderId: Long ,
59+ ) : this (
60+ type = type,
61+ id = id,
62+ props = JsonObject (propKeys.indices.associate { propKeys[it] to Json .parseToJsonElement(propValues[it]) }),
63+ modifiers = modifierKinds.indices.map {
64+ ModifierNode (modifierKinds[it], Json .parseToJsonElement(modifierArgs[it]).jsonObject)
65+ },
66+ children = children.toList(),
67+ count = if (count >= 0 ) count else null ,
68+ itemProviderId = if (itemProviderId >= 0 ) itemProviderId else null ,
69+ )
70+
4271 // Typed prop accessors used by the interpreter.
4372
4473 fun string (key : String ): String? = (props[key] as ? JsonPrimitive )?.content
0 commit comments