We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a8a0c0c commit 744e443Copy full SHA for 744e443
1 file changed
Sources/AndroidSwiftUI/SwiftUIHostView.swift
@@ -6,6 +6,7 @@
6
//
7
8
import AndroidKit
9
+import JavaLang
10
import AndroidSwiftUIBridge
11
import AndroidSwiftUICore
12
@@ -36,7 +37,13 @@ public enum AndroidSwiftUIApp {
36
37
assertionFailure("host view has no tree store")
38
return
39
}
- let runtime = BridgeRuntime(root: root, store: store)
40
+ // marshal re-renders onto the main looper: JNI object creation and
41
+ // Compose state writes must run there, not on a Swift Task's thread
42
+ let handler = AndroidOS.Handler(try! JavaClass<AndroidOS.Looper>().getMainLooper())
43
+ let runtime = BridgeRuntime(root: root, store: store) { block in
44
+ let runnable = Runnable { block() }
45
+ _ = handler.post(runnable.as(JavaLang.Runnable.self))
46
+ }
47
Self.runtime = runtime
48
runtime.start()
49
activity.setRootView(host)
0 commit comments