diff --git a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/runtime/SupportedFlowRuntimeGenerator.kt b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/runtime/SupportedFlowRuntimeGenerator.kt index a36b176e..d4aaa2bb 100644 --- a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/runtime/SupportedFlowRuntimeGenerator.kt +++ b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/runtime/SupportedFlowRuntimeGenerator.kt @@ -53,7 +53,7 @@ object SupportedFlowRuntimeGenerator { SirClass( baseName = "SkieSwiftFlowProtocol", kind = SirClass.Kind.Protocol, - superTypes = listOf(sirBuiltins._Concurrency.AsyncSequence.defaultType), + superTypes = listOf(sirBuiltins._Concurrency.AsyncSequence.defaultType, sirBuiltins.Swift.AnyObject.defaultType), ).apply { val elementTypeParameter = SirTypeParameter( name = "Element", diff --git a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/runtime/SwiftUIFlowObservingGenerator.kt b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/runtime/SwiftUIFlowObservingGenerator.kt index 87a99559..eae3d6f8 100644 --- a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/runtime/SwiftUIFlowObservingGenerator.kt +++ b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/runtime/SwiftUIFlowObservingGenerator.kt @@ -634,7 +634,7 @@ object SwiftUIFlowObservingGenerator { type = skieSwiftFlowObserver.defaultType, visibility = SirVisibility.Private, attributes = listOf( - "SwiftUI.ObservedObject" + "SwiftUI.StateObject" ), isMutable = true, ) @@ -659,7 +659,10 @@ object SwiftUIFlowObservingGenerator { bodyBuilder.add { addStatement("self.content = content") - addStatement("self.observer = %T(flows: flows)", skieSwiftFlowObserver.defaultType.evaluate().swiftPoetTypeName) + addStatement( + "self._observer = SwiftUI.StateObject(wrappedValue: %T(flows: flows))", + skieSwiftFlowObserver.defaultType.evaluate().swiftPoetTypeName, + ) } } @@ -780,6 +783,11 @@ object SwiftUIFlowObservingGenerator { type = sirBuiltins.Swift.Array.toType(sirBuiltins.Skie.SkieSwiftFlowProtocol.defaultType.toExistential()), ) + SirProperty( + identifier = "flowIds", + type = sirBuiltins.Swift.Array.toType(sirBuiltins.Swift.ObjectIdentifier.defaultType), + ) + SirProperty( identifier = "initialContent", type = initialContentFactoryType.copy(isEscaping = false), @@ -812,6 +820,11 @@ object SwiftUIFlowObservingGenerator { type = sirBuiltins.Swift.Array.toType(sirBuiltins.Skie.SkieSwiftFlowProtocol.defaultType.toExistential()), ) + SirValueParameter( + name = "flowIds", + type = sirBuiltins.Swift.Array.toType(sirBuiltins.Swift.ObjectIdentifier.defaultType), + ) + SirValueParameter( name = "initialContent", type = initialContentFactoryType, @@ -832,6 +845,7 @@ object SwiftUIFlowObservingGenerator { bodyBuilder.add { addCode(""" self.flows = flows + self.flowIds = flowIds self.initialContent = initialContent self.content = content self.extractValues = extractValues @@ -852,6 +866,7 @@ object SwiftUIFlowObservingGenerator { initialContent() } } + .id(flowIds) """.trimIndent()) } } @@ -950,6 +965,7 @@ object SwiftUIFlowObservingGenerator { +"self.init(" indented { +"flows: [${flowValueParameters.joinToString { it.name }}],\n" + +"flowIds: [${flowValueParameters.joinToString { "Swift.ObjectIdentifier(${it.name})" }}],\n" +"initialContent: initialContent,\n" +"content: content\n" } @@ -1054,6 +1070,7 @@ object SwiftUIFlowObservingGenerator { +"self.init(" indented { +"flows: [${flowValueParameters.joinToString { "${it.name}.flow" }}],\n" + +"flowIds: [${flowValueParameters.joinToString { "Swift.ObjectIdentifier(${it.name}.flow)" }}],\n" +"initialContent: SwiftUI.EmptyView.init,\n" +"content: content\n" } diff --git a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/sir/builtin/SirBuiltin.kt b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/sir/builtin/SirBuiltin.kt index 7e988b52..900f52fd 100644 --- a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/sir/builtin/SirBuiltin.kt +++ b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/sir/builtin/SirBuiltin.kt @@ -84,6 +84,7 @@ class SirBuiltins( val Void by Struct() val Never by Struct() + val ObjectIdentifier by Struct() val UnsafeMutableRawPointer by Struct(superTypes = listOf(Hashable.defaultType))