expo-modules-core 58.0.22 → 58.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/android/build.gradle +2 -2
- package/android/prebuilt/metadata.json +2 -2
- package/android/prebuilt/native-libs.tar.xz +0 -0
- package/android/src/compose/expo/modules/kotlin/views/ExpoComposeView.kt +11 -0
- package/common/cpp/JSI/JSIUtils.cpp +17 -5
- package/common/cpp/JSI/JSIUtils.h +5 -0
- package/common/cpp/SharedObject.cpp +21 -0
- package/ios/Benchmarks/FunctionBenchmarks.swift +41 -0
- package/ios/Benchmarks/SharedObjectBenchmarks.swift +34 -6
- package/ios/Core/AppContext.swift +15 -20
- package/ios/Core/Classes/ClassDefinition.swift +4 -3
- package/ios/Core/Classes/ClassRegistry.swift +14 -18
- package/ios/Core/Coding/JavaScriptCodable+Record.swift +3 -12
- package/ios/Core/Conversions.swift +3 -15
- package/ios/Core/DynamicTypes/DynamicSharedObjectType.swift +3 -10
- package/ios/Core/ExpoModulesMacros.swift +24 -6
- package/ios/Core/ExpoRuntime.swift +28 -0
- package/ios/Core/SharedObjects/SharedObject.swift +6 -0
- package/ios/Core/SharedObjects/SharedObjectRegistry.swift +44 -29
- package/ios/Core/SharedObjects/SharedRef.swift +4 -0
- package/ios/Core/Views/SwiftUI/SwiftUIHostingView.swift +38 -0
- package/ios/Core/Views/SwiftUI/SwiftUIViewHost.swift +8 -0
- package/package.json +4 -4
- package/prebuilds/output/debug/xcframeworks/ExpoModulesCore.tar.gz +0 -0
- package/prebuilds/output/debug/xcframeworks/ExpoModulesWorklets.tar.gz +0 -0
- package/prebuilds/output/headers/xcframeworks/ExpoModulesCoreHeaders.tar.gz +0 -0
- package/prebuilds/output/release/xcframeworks/ExpoModulesCore.tar.gz +0 -0
- package/prebuilds/output/release/xcframeworks/ExpoModulesWorklets.tar.gz +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 58.0.24
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [iOS] Reduce the overhead of creating shared objects in JavaScript and of returning them from native functions. ([#51730](https://github.com/expo/expo/pull/51730) by [@tsapeta](https://github.com/tsapeta))
|
|
8
|
+
- [iOS] Fix shared objects that native code returns to JavaScript again after their earlier JavaScript object was garbage-collected. Their members could throw "Unable to find the native shared object associated with given JavaScript object", or the returned object could belong to another shared object. ([#51854](https://github.com/expo/expo/pull/51854) by [@tsapeta](https://github.com/tsapeta))
|
|
9
|
+
- [iOS] Update `expo-modules-macros` to 0.22.0. `@Record` types now read and write their JavaScript properties with less overhead. The new `@JS` option `.withAsync("name")` also binds a synchronous function under that name, as a function that returns a promise and runs on the concurrent thread pool. A `@Record` can now be a `final class`, and a class that isn't `final` or has an inheritance clause gets a build error that says how to fix it. A `@JS init` now reports an argument type that can't be converted from JavaScript at the initializer. ([#51905](https://github.com/expo/expo/pull/51905) by [@tsapeta](https://github.com/tsapeta))
|
|
10
|
+
- [iOS] Fix a SwiftUI `Host` that mounts during a repeated modal presentation having no safe area. ([#51923](https://github.com/expo/expo/pull/51923) by [@expo-tuft](https://github.com/apps/expo-tuft))
|
|
11
|
+
- [iOS] Fix hosted React Native content going blank or keeping a stale size after its child view is remounted, for example by a `key` change in an `RNHostView`. ([#51906](https://github.com/expo/expo/pull/51906) by [@expo-tuft](https://github.com/apps/expo-tuft))
|
|
12
|
+
- Updated dependencies. ([#51588](https://github.com/expo/expo/pull/51588), [#51835](https://github.com/expo/expo/pull/51835), [#51905](https://github.com/expo/expo/pull/51905))
|
|
13
|
+
- expo-modules-jsi@58.0.17
|
|
14
|
+
|
|
15
|
+
## 58.0.23
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [iOS] Reduce the overhead of returning `Data` and shared objects to JavaScript. ([#51728](https://github.com/expo/expo/pull/51728) by [@tsapeta](https://github.com/tsapeta))
|
|
20
|
+
- [Android] Fix a Jetpack Compose `Host` that stays blank when it mounts in a visible list row with `removeClippedSubviews` enabled, for example in a `FlatList`. The `Host` now measures its content when it is attached for the first time. ([#51780](https://github.com/expo/expo/pull/51780) by [@expo-bot](https://github.com/expo-bot))
|
|
21
|
+
- [iOS] Update `expo-modules-macros` to 0.21.0. `@Record` types now convert between JavaScript and native code with less overhead and no longer need an app context. `@ExpoModule` and `@SharedObject` now report a build error when two `@JS` members of one object have the same JavaScript name, because JavaScript could reach only one of them. ([#51716](https://github.com/expo/expo/pull/51716) by [@tsapeta](https://github.com/tsapeta))
|
|
22
|
+
- Shared objects now report their class name from `Object.prototype.toString`, for example `[object VideoPlayer]`. React in development builds no longer deep-compares shared objects in props, which threw `ERR_NATIVE_SHARED_OBJECT_NOT_FOUND` when the previous props held a released shared object. `Blob` from `expo-blob` and `File` from `expo-file-system` now report `[object Blob]` and `[object File]`, as on the web. Libraries that detect these types by this tag now treat them as a `Blob` and a `File`. ([#51743](https://github.com/expo/expo/pull/51743) by [@tsapeta](https://github.com/tsapeta))
|
|
23
|
+
- Updated dependencies. ([#51728](https://github.com/expo/expo/pull/51728), [#51739](https://github.com/expo/expo/pull/51739), [#51577](https://github.com/expo/expo/pull/51577))
|
|
24
|
+
- expo-modules-jsi@58.0.16
|
|
25
|
+
|
|
3
26
|
## 58.0.22
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
package/android/build.gradle
CHANGED
|
@@ -46,7 +46,7 @@ if (shouldIncludeCompose) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
group = 'host.exp.exponent'
|
|
49
|
-
version = '58.0.
|
|
49
|
+
version = '58.0.24'
|
|
50
50
|
|
|
51
51
|
def isExpoModulesCoreTests = {
|
|
52
52
|
Gradle gradle = getGradle()
|
|
@@ -175,7 +175,7 @@ android {
|
|
|
175
175
|
defaultConfig {
|
|
176
176
|
consumerProguardFiles 'proguard-rules.pro'
|
|
177
177
|
versionCode 1
|
|
178
|
-
versionName "58.0.
|
|
178
|
+
versionName "58.0.24"
|
|
179
179
|
buildConfigField "String", "EXPO_MODULES_CORE_VERSION", "\"${versionName}\""
|
|
180
180
|
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true"
|
|
181
181
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"reactNativeVersion": "0.88.0",
|
|
3
|
-
"sourceHash": "
|
|
3
|
+
"sourceHash": "d5785b6fa4de4ea64f18bdac451d0308",
|
|
4
4
|
"variants": [
|
|
5
5
|
"debug",
|
|
6
6
|
"release"
|
|
@@ -16,5 +16,5 @@
|
|
|
16
16
|
"libexpo-modules-jsi.so"
|
|
17
17
|
],
|
|
18
18
|
"stripped": true,
|
|
19
|
-
"createdAt": "2026-10-
|
|
19
|
+
"createdAt": "2026-10-21T17:10:44.785915196Z"
|
|
20
20
|
}
|
|
Binary file
|
|
@@ -82,9 +82,16 @@ abstract class ExpoComposeView<T : ComposeProps>(
|
|
|
82
82
|
|
|
83
83
|
override val shouldUseAndroidLayout = withHostingView
|
|
84
84
|
|
|
85
|
+
// A measure pass skipped while detached is cached by Android, so the same specs will not measure
|
|
86
|
+
// the Compose content again. Set when that happens, so the first attach can request a new pass.
|
|
87
|
+
// React Native can attach this view from inside its own `layout()`, which clears the forced-layout
|
|
88
|
+
// flag when it returns, so the request is posted.
|
|
89
|
+
private var needsLayoutOnAttach = false
|
|
90
|
+
|
|
85
91
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
|
86
92
|
// In case of issues there's an alternative solution in previous commits at https://github.com/expo/expo/pull/33759
|
|
87
93
|
if (shouldUseAndroidLayout && !isAttachedToWindow) {
|
|
94
|
+
needsLayoutOnAttach = true
|
|
88
95
|
setMeasuredDimension(widthMeasureSpec, heightMeasureSpec)
|
|
89
96
|
return
|
|
90
97
|
}
|
|
@@ -112,6 +119,10 @@ abstract class ExpoComposeView<T : ComposeProps>(
|
|
|
112
119
|
|
|
113
120
|
override fun onAttachedToWindow() {
|
|
114
121
|
super.onAttachedToWindow()
|
|
122
|
+
if (needsLayoutOnAttach) {
|
|
123
|
+
needsLayoutOnAttach = false
|
|
124
|
+
post { requestLayout() }
|
|
125
|
+
}
|
|
115
126
|
if (!withHostingView) {
|
|
116
127
|
validateHostingAncestor()
|
|
117
128
|
}
|
|
@@ -102,7 +102,7 @@ std::vector<jsi::PropNameID> jsiArrayToPropNameIdsVector(jsi::Runtime &runtime,
|
|
|
102
102
|
return vector;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
static jsi::Object createDescriptorObject(jsi::Runtime &runtime, const PropertyDescriptor& descriptor) {
|
|
106
106
|
jsi::Object jsDescriptor(runtime);
|
|
107
107
|
|
|
108
108
|
// These three flags are all `false` by default, so set the property only when `true`.
|
|
@@ -146,20 +146,32 @@ void defineProperty(jsi::Runtime &runtime, jsi::Object *object, const char *name
|
|
|
146
146
|
jsDescriptor.setProperty(runtime, valuePropName, descriptor.value);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
return jsDescriptor;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
void
|
|
152
|
+
static void callDefineProperty(jsi::Runtime &runtime, jsi::Object *object, jsi::Value key, jsi::Object descriptor) {
|
|
153
153
|
jsi::Object global = runtime.global();
|
|
154
154
|
jsi::Object objectClass = global.getPropertyAsObject(runtime, "Object");
|
|
155
155
|
jsi::Function definePropertyFunction = objectClass.getPropertyAsFunction(runtime, "defineProperty");
|
|
156
156
|
|
|
157
|
-
// This call is basically the same as `Object.defineProperty(object,
|
|
157
|
+
// This call is basically the same as `Object.defineProperty(object, key, descriptor)` in JS
|
|
158
158
|
definePropertyFunction.callWithThis(runtime, objectClass, {
|
|
159
159
|
jsi::Value(runtime, *object),
|
|
160
|
-
|
|
160
|
+
std::move(key),
|
|
161
161
|
std::move(descriptor),
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
void defineProperty(jsi::Runtime &runtime, jsi::Object *object, const char *name, const PropertyDescriptor& descriptor) {
|
|
166
|
+
callDefineProperty(runtime, object, jsi::String::createFromUtf8(runtime, name), createDescriptorObject(runtime, descriptor));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
void defineProperty(jsi::Runtime &runtime, jsi::Object *object, const jsi::Symbol &key, const PropertyDescriptor& descriptor) {
|
|
170
|
+
callDefineProperty(runtime, object, jsi::Value(runtime, key), createDescriptorObject(runtime, descriptor));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
void defineProperty(jsi::Runtime &runtime, jsi::Object *object, const char *name, jsi::Object descriptor) {
|
|
174
|
+
callDefineProperty(runtime, object, jsi::String::createFromUtf8(runtime, name), std::move(descriptor));
|
|
175
|
+
}
|
|
176
|
+
|
|
165
177
|
} // namespace expo::common
|
|
@@ -66,6 +66,11 @@ struct PropertyDescriptor {
|
|
|
66
66
|
*/
|
|
67
67
|
void defineProperty(jsi::Runtime &runtime, jsi::Object *object, const char *name, const PropertyDescriptor& descriptor);
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
Defines the property under a symbol key, such as `Symbol.toStringTag`, with the provided descriptor options.
|
|
71
|
+
*/
|
|
72
|
+
void defineProperty(jsi::Runtime &runtime, jsi::Object *object, const jsi::Symbol &key, const PropertyDescriptor& descriptor);
|
|
73
|
+
|
|
69
74
|
/**
|
|
70
75
|
Calls `Object.defineProperty(object, name, descriptor)`.
|
|
71
76
|
*/
|
|
@@ -74,6 +74,27 @@ void installBaseClass(jsi::Runtime &runtime, const ObjectReleaser& releaser) {
|
|
|
74
74
|
prototype.setProperty(runtime, "release", releaseFunction);
|
|
75
75
|
prototype.setProperty(runtime, "toJSON", toJSONFunction);
|
|
76
76
|
|
|
77
|
+
// React in development deep-compares props whose `Object.prototype.toString` is `[object Object]`.
|
|
78
|
+
// That reads every property getter, and a getter throws when its shared object was released.
|
|
79
|
+
// The tag is the name of the object's class, so subclasses, also those defined in JS, report their own.
|
|
80
|
+
jsi::Symbol toStringTag = runtime.global()
|
|
81
|
+
.getPropertyAsObject(runtime, "Symbol")
|
|
82
|
+
.getProperty(runtime, "toStringTag")
|
|
83
|
+
.getSymbol(runtime);
|
|
84
|
+
defineProperty(runtime, &prototype, toStringTag, common::PropertyDescriptor {
|
|
85
|
+
.configurable = true,
|
|
86
|
+
.get = [](jsi::Runtime &runtime, jsi::Object thisObject) {
|
|
87
|
+
jsi::Value constructor = thisObject.getProperty(runtime, "constructor");
|
|
88
|
+
if (constructor.isObject()) {
|
|
89
|
+
jsi::Value name = constructor.getObject(runtime).getProperty(runtime, "name");
|
|
90
|
+
if (name.isString() && !name.getString(runtime).utf8(runtime).empty()) {
|
|
91
|
+
return name;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return jsi::Value(jsi::String::createFromAscii(runtime, "SharedObject"));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
77
98
|
// This property should be deprecated, but it's still used when passing as a view prop.
|
|
78
99
|
defineProperty(runtime, &prototype, "__expo_shared_object_id__", common::PropertyDescriptor {
|
|
79
100
|
.get = [](jsi::Runtime &runtime, jsi::Object thisObject) {
|
|
@@ -55,6 +55,34 @@ extension Benchmarks {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
@Test
|
|
59
|
+
func `@JS: record argument`() async throws {
|
|
60
|
+
try await functionBenchmarkCase(setup: "var point = { x: 1, y: 2 };", body: "m.take(point);") { run, runtime in
|
|
61
|
+
try benchmark("@JS: record argument", runtime: runtime) { iterations in
|
|
62
|
+
_ = try run.call(arguments: iterations)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Test
|
|
68
|
+
func `@JS: record result`() async throws {
|
|
69
|
+
try await functionBenchmarkCase(body: "m.makePoint();") { run, runtime in
|
|
70
|
+
try benchmark("@JS: record result", runtime: runtime) { iterations in
|
|
71
|
+
_ = try run.call(arguments: iterations)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Test
|
|
77
|
+
func `@JS: array of 10 records argument and result`() async throws {
|
|
78
|
+
let setup = "var points = []; for (var k = 0; k < 10; k++) { points.push({ x: k, y: k }); }"
|
|
79
|
+
try await functionBenchmarkCase(setup: setup, body: "m.mirrorAll(points);") { run, runtime in
|
|
80
|
+
try benchmark("@JS: array of 10 records argument and result", runtime: runtime) { iterations in
|
|
81
|
+
_ = try run.call(arguments: iterations)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
58
86
|
@Test
|
|
59
87
|
func `@JS: async function with no arguments`() async throws {
|
|
60
88
|
try await functionBenchmarkCase(body: "m.noopAsync();") { run, runtime in
|
|
@@ -91,6 +119,19 @@ private final class FunctionBenchmarkModule: Module {
|
|
|
91
119
|
return BenchmarkPoint(x: point.y, y: point.x)
|
|
92
120
|
}
|
|
93
121
|
|
|
122
|
+
@JS
|
|
123
|
+
func take(point: BenchmarkPoint) {}
|
|
124
|
+
|
|
125
|
+
@JS
|
|
126
|
+
func makePoint() -> BenchmarkPoint {
|
|
127
|
+
return BenchmarkPoint(x: 1, y: 2)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@JS
|
|
131
|
+
func mirrorAll(points: [BenchmarkPoint]) -> [BenchmarkPoint] {
|
|
132
|
+
return points
|
|
133
|
+
}
|
|
134
|
+
|
|
94
135
|
@JS
|
|
95
136
|
@JavaScriptActor
|
|
96
137
|
func noopAsync() async {}
|
|
@@ -5,9 +5,9 @@ import Testing
|
|
|
5
5
|
|
|
6
6
|
@testable import ExpoModulesCore
|
|
7
7
|
|
|
8
|
-
/// Benchmarks for JavaScript using a `@SharedObject` class: creating instances
|
|
9
|
-
/// members. A JavaScript driver runs the measured loop. Read every result
|
|
10
|
-
/// `JS: empty driver loop`.
|
|
8
|
+
/// Benchmarks for JavaScript using a `@SharedObject` class: creating instances, getting them from a `@JS`
|
|
9
|
+
/// function and calling their `@JS` members. A JavaScript driver runs the measured loop. Read every result
|
|
10
|
+
/// against `JS: empty driver loop`.
|
|
11
11
|
extension Benchmarks {
|
|
12
12
|
@Test
|
|
13
13
|
func `@SharedObject: new instance`() async throws {
|
|
@@ -18,6 +18,24 @@ extension Benchmarks {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
@Test
|
|
22
|
+
func `@SharedObject: instance returned from a function`() async throws {
|
|
23
|
+
try await sharedObjectBenchmarkCase(body: "m.makeCounter(i);") { run, runtime in
|
|
24
|
+
try benchmark("@SharedObject: instance returned from a function", runtime: runtime) { iterations in
|
|
25
|
+
_ = try run.call(arguments: iterations)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Test
|
|
31
|
+
func `SharedRef without a class: returned from a function`() async throws {
|
|
32
|
+
try await sharedObjectBenchmarkCase(body: "m.makeRef(i);") { run, runtime in
|
|
33
|
+
try benchmark("SharedRef without a class: returned from a function", runtime: runtime) { iterations in
|
|
34
|
+
_ = try run.call(arguments: iterations)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
21
39
|
@Test
|
|
22
40
|
func `@SharedObject: method call`() async throws {
|
|
23
41
|
try await sharedObjectBenchmarkCase(body: "counter.increment(1);") { run, runtime in
|
|
@@ -59,10 +77,20 @@ private final class BenchmarkCounter: SharedObject {
|
|
|
59
77
|
}
|
|
60
78
|
|
|
61
79
|
@ExpoModule(classes: [BenchmarkCounter.self])
|
|
62
|
-
private final class SharedObjectBenchmarkModule: Module {
|
|
80
|
+
private final class SharedObjectBenchmarkModule: Module {
|
|
81
|
+
@JS
|
|
82
|
+
func makeCounter(value: Int) -> BenchmarkCounter {
|
|
83
|
+
return BenchmarkCounter(value: value)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@JS
|
|
87
|
+
func makeRef(value: Int) -> SharedRef<Int> {
|
|
88
|
+
return SharedRef(value)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
63
91
|
|
|
64
92
|
/// Runs one case with `SharedObjectBenchmarkModule` registered and a JavaScript driver that runs `body`
|
|
65
|
-
/// in a loop, with the class in `Counter` and one instance in `counter`.
|
|
93
|
+
/// in a loop, with the module in `m`, the class in `Counter` and one instance in `counter`.
|
|
66
94
|
private func sharedObjectBenchmarkCase(
|
|
67
95
|
body: String,
|
|
68
96
|
_ measure: @escaping @JavaScriptActor (borrowing JavaScriptFunction, JavaScriptRuntime) throws -> Void
|
|
@@ -72,7 +100,7 @@ private func sharedObjectBenchmarkCase(
|
|
|
72
100
|
} _: { _, runtime in
|
|
73
101
|
let run = try javaScriptDriver(
|
|
74
102
|
runtime,
|
|
75
|
-
setup: "var
|
|
103
|
+
setup: "var m = expo.modules.SharedObjectBenchmarkModule; var Counter = m.BenchmarkCounter; var counter = new Counter(0);",
|
|
76
104
|
body: body
|
|
77
105
|
)
|
|
78
106
|
try measure(run, runtime)
|
|
@@ -230,24 +230,18 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
|
|
|
230
230
|
|
|
231
231
|
internal lazy var sharedObjectRegistry = SharedObjectRegistry(appContext: self)
|
|
232
232
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
Perhaps it should be kept by the `ModuleHolder`.
|
|
237
|
-
*/
|
|
233
|
+
/// A registry containing references to the prototypes of JavaScript classes.
|
|
234
|
+
/// - ToDo: Make one registry per module, not the entire app context.
|
|
235
|
+
/// Perhaps it should be kept by the `ModuleHolder`.
|
|
238
236
|
internal let classRegistry = ClassRegistry()
|
|
239
237
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
*/
|
|
238
|
+
/// Creates a new JavaScript object with the class prototype associated with the given native class.
|
|
239
|
+
/// Returns `nil` when no JavaScript class is registered for the native class.
|
|
240
|
+
/// - ToDo: Move this to `ModuleHolder` along the `classRegistry` property.
|
|
244
241
|
internal func newObject(nativeClassId: ObjectIdentifier) throws -> JavaScriptObject? {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
return try JavaScriptActor.assumeIsolated {
|
|
249
|
-
let prototype = try jsClass.getProperty("prototype").asObject()
|
|
250
|
-
return try runtime.createObject(prototype: prototype)
|
|
242
|
+
let runtime = try self.runtime
|
|
243
|
+
return classRegistry.withPrototype(nativeClassId: nativeClassId) { (prototype: borrowing JavaScriptObject) in
|
|
244
|
+
return runtime.createObject(prototype: prototype)
|
|
251
245
|
}
|
|
252
246
|
}
|
|
253
247
|
|
|
@@ -691,11 +685,12 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
|
|
|
691
685
|
guard let nativeState = nativeState as? NativeState, nativeState.ownsLifecycle else {
|
|
692
686
|
return
|
|
693
687
|
}
|
|
694
|
-
//
|
|
695
|
-
//
|
|
696
|
-
//
|
|
697
|
-
//
|
|
698
|
-
//
|
|
688
|
+
// Hermes runs this on its finalizer thread while the JS thread waits in the runtime's
|
|
689
|
+
// destructor, so nothing else uses the runtime and `destroy()` can release JS objects
|
|
690
|
+
// here. Don't send that work to another thread: it would run after Hermes frees its
|
|
691
|
+
// values. A future cross-runtime sharing path that could drop this state's last JSI slot
|
|
692
|
+
// while the runtime still runs JavaScript (see `JavaScriptNativeState.acquireShared`)
|
|
693
|
+
// would need to hop to the JS thread here first.
|
|
699
694
|
nativeState.appContext.destroy()
|
|
700
695
|
}
|
|
701
696
|
}
|
|
@@ -87,15 +87,16 @@ public final class ClassDefinition: ObjectDefinition {
|
|
|
87
87
|
|
|
88
88
|
try decorate(object: klass, appContext: appContext)
|
|
89
89
|
|
|
90
|
+
let prototype = klass.getProperty("prototype").getObject()
|
|
91
|
+
|
|
90
92
|
// Bind the macro's `@JS` members onto the prototype.
|
|
91
93
|
if let sharedObjectType {
|
|
92
|
-
let prototype = klass.getProperty("prototype").getObject()
|
|
93
94
|
try sharedObjectType._decorateSharedObject(prototype: prototype, in: appContext.runtime)
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
// Register the JS class
|
|
97
|
+
// Register the prototype of the JS class for its associated native type.
|
|
97
98
|
if let sharedObjectType = associatedType as? DynamicSharedObjectType {
|
|
98
|
-
appContext.classRegistry.register(nativeClassId: sharedObjectType.typeIdentifier,
|
|
99
|
+
appContext.classRegistry.register(nativeClassId: sharedObjectType.typeIdentifier, prototype: prototype)
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
return klass
|
|
@@ -3,33 +3,29 @@
|
|
|
3
3
|
import ExpoModulesJSI
|
|
4
4
|
|
|
5
5
|
internal final class ClassRegistry {
|
|
6
|
-
//
|
|
7
|
-
// Dictionary value.
|
|
8
|
-
|
|
6
|
+
// Prototypes are kept behind `JavaScriptRef` because `JavaScriptObject` is ~Copyable and cannot be a
|
|
7
|
+
// Dictionary value. Only the prototype is kept: creating an instance needs nothing else from the class,
|
|
8
|
+
// and reading the prototype from the class would cost a property lookup on every instance.
|
|
9
|
+
var nativeToPrototype = [ObjectIdentifier: JavaScriptObject.Ref]()
|
|
9
10
|
|
|
10
11
|
// MARK: - Accessing
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return
|
|
13
|
+
/// Calls `body` with the prototype of the JavaScript class registered for the native class.
|
|
14
|
+
/// Returns `nil` when no class is registered.
|
|
15
|
+
func withPrototype<R: ~Copyable>(
|
|
16
|
+
nativeClassId: ObjectIdentifier,
|
|
17
|
+
_ body: (borrowing JavaScriptObject) throws -> R
|
|
18
|
+
) rethrows -> R? {
|
|
19
|
+
return try nativeToPrototype[nativeClassId]?.withUnwrappedValue(body)
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
// MARK: - Registration
|
|
22
23
|
|
|
23
|
-
func register(nativeClassId: ObjectIdentifier,
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
func register(nativeClass: SharedObject.Type, javaScriptClass: borrowing JavaScriptObject) {
|
|
28
|
-
let nativeClassId = ObjectIdentifier(nativeClass)
|
|
29
|
-
register(nativeClassId: nativeClassId, javaScriptClass: javaScriptClass)
|
|
24
|
+
func register(nativeClassId: ObjectIdentifier, prototype: consuming JavaScriptObject) {
|
|
25
|
+
nativeToPrototype[nativeClassId] = prototype.ref()
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
internal func clear() {
|
|
33
|
-
|
|
29
|
+
nativeToPrototype.removeAll()
|
|
34
30
|
}
|
|
35
31
|
}
|
|
@@ -14,8 +14,9 @@ import ExpoModulesJSI
|
|
|
14
14
|
// context never prepared has no such state, so recovery returns `nil` and the conversion throws
|
|
15
15
|
// `Exceptions.AppContextNotFound`.
|
|
16
16
|
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
17
|
+
// `decode` reads the object straight from the borrowed value and hands it to
|
|
18
|
+
// `from(object:appContext:)`, so a record argument isn't copied first. An owning value takes the
|
|
19
|
+
// `JavaScriptDecodable` default, which borrows it and calls this `decode`.
|
|
19
20
|
|
|
20
21
|
extension Record {
|
|
21
22
|
// A record decodes only from an object.
|
|
@@ -24,16 +25,6 @@ extension Record {
|
|
|
24
25
|
return .object
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
@JavaScriptActor
|
|
28
|
-
@inlinable
|
|
29
|
-
public static func decode(_ value: borrowing JavaScriptValue, in runtime: borrowing JavaScriptRuntime) throws -> Self
|
|
30
|
-
{
|
|
31
|
-
guard let appContext = AppContext.from(runtime: runtime) else {
|
|
32
|
-
throw Exceptions.AppContextNotFound()
|
|
33
|
-
}
|
|
34
|
-
return try from(object: value.asObject(), appContext: appContext)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
28
|
@JavaScriptActor
|
|
38
29
|
@inlinable
|
|
39
30
|
public static func decode(_ value: borrowing JavaScriptUnownedValue, in runtime: borrowing JavaScriptRuntime) throws
|
|
@@ -208,7 +208,9 @@ public struct Conversions {
|
|
|
208
208
|
case let string as NSString:
|
|
209
209
|
return .representing(value: string as String, in: runtime)
|
|
210
210
|
case let data as Data:
|
|
211
|
-
return try
|
|
211
|
+
return try JavaScriptActor.assumeIsolated {
|
|
212
|
+
return try Data.encode(data, in: runtime)
|
|
213
|
+
}
|
|
212
214
|
case let array as NSArray:
|
|
213
215
|
let jsArray = runtime.createArray(length: array.count)
|
|
214
216
|
for (index, element) in array.enumerated() {
|
|
@@ -228,20 +230,6 @@ public struct Conversions {
|
|
|
228
230
|
}
|
|
229
231
|
}
|
|
230
232
|
|
|
231
|
-
/**
|
|
232
|
-
Copies the given `Data` into a new JS `ArrayBuffer` and wraps it in a `Uint8Array`.
|
|
233
|
-
*/
|
|
234
|
-
private static func dataToUint8Array(_ data: Data, runtime: JavaScriptRuntime) throws -> JavaScriptValue {
|
|
235
|
-
let arrayBuffer = runtime.createArrayBuffer(size: data.count)
|
|
236
|
-
data.withUnsafeBytes { rawBuffer in
|
|
237
|
-
if let baseAddress = rawBuffer.baseAddress, data.count > 0 {
|
|
238
|
-
memcpy(arrayBuffer.data(), baseAddress, data.count)
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
let uint8ArrayCtor = try runtime.global().getPropertyAsFunction("Uint8Array")
|
|
242
|
-
return try uint8ArrayCtor.callAsConstructor(arrayBuffer.asValue().ref())
|
|
243
|
-
}
|
|
244
|
-
|
|
245
233
|
// MARK: - Exceptions
|
|
246
234
|
|
|
247
235
|
/**
|
|
@@ -71,7 +71,7 @@ internal struct DynamicSharedObjectType: AnyDynamicType {
|
|
|
71
71
|
if let jsObject = sharedObject.getJavaScriptObject() {
|
|
72
72
|
return jsObject.asValue()
|
|
73
73
|
}
|
|
74
|
-
guard let jsObject = (try? appContext.newObject(nativeClassId: typeIdentifier)) ?? (try? newBaseSharedObject(appContext,
|
|
74
|
+
guard let jsObject = (try? appContext.newObject(nativeClassId: typeIdentifier)) ?? (try? newBaseSharedObject(appContext, isSharedRef: sharedObject.sharedRefType != nil)) else {
|
|
75
75
|
// Throwing is not possible here due to swift-objC interop.
|
|
76
76
|
log.warn("Unable to create a JS object for \(description)")
|
|
77
77
|
return JavaScriptValue.undefined()
|
|
@@ -86,15 +86,8 @@ internal struct DynamicSharedObjectType: AnyDynamicType {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
private func
|
|
90
|
-
let isSharedRef = nativeType is AnySharedRef.Type
|
|
89
|
+
private func newBaseSharedObject(_ appContext: AppContext, isSharedRef: Bool) throws -> JavaScriptObject? {
|
|
91
90
|
return try JavaScriptActor.assumeIsolated {
|
|
92
|
-
return try
|
|
91
|
+
return try appContext.runtime.createBaseSharedObject(isSharedRef: isSharedRef)
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
|
-
|
|
96
|
-
private func newBaseSharedObject(_ appContext: AppContext, nativeType: AnySharedObject.Type) throws -> JavaScriptObject? {
|
|
97
|
-
let jsClass = try getBaseSharedType(appContext, nativeType: nativeType)
|
|
98
|
-
let prototype = try jsClass.asObject().getPropertyAsObject("prototype")
|
|
99
|
-
return try appContext.runtime.createObject(prototype: prototype)
|
|
100
|
-
}
|
|
@@ -36,6 +36,16 @@ public enum JSOptions {
|
|
|
36
36
|
/// The call sends the module or shared object off the JavaScript thread, so in Swift 6 language
|
|
37
37
|
/// mode the enclosing class must be `Sendable`.
|
|
38
38
|
case concurrent
|
|
39
|
+
|
|
40
|
+
/// Binds a synchronous function a second time under the given JavaScript name, as a function that
|
|
41
|
+
/// returns a promise and runs the body on the concurrent thread pool, for example
|
|
42
|
+
/// `@JS("textSync", .withAsync("text"))`. The body must be safe to run on any thread, since the
|
|
43
|
+
/// variant isn't isolated to the JavaScript thread. Only valid on a synchronous function that isn't
|
|
44
|
+
/// isolated to a global actor, and the name must be a string literal.
|
|
45
|
+
///
|
|
46
|
+
/// The variant sends the module or shared object off the JavaScript thread, so in Swift 6 language
|
|
47
|
+
/// mode the enclosing class must be `Sendable`.
|
|
48
|
+
case withAsync(String)
|
|
39
49
|
}
|
|
40
50
|
|
|
41
51
|
/// Marker macro applied to module / shared-object members that should be exposed to JavaScript.
|
|
@@ -59,6 +69,9 @@ public enum JSOptions {
|
|
|
59
69
|
/// @JS("doWork", .concurrent)
|
|
60
70
|
/// func performHeavyWork() async throws { ... }
|
|
61
71
|
///
|
|
72
|
+
/// @JS("textSync", .withAsync("text"))
|
|
73
|
+
/// func text(path: String) throws -> String { ... }
|
|
74
|
+
///
|
|
62
75
|
/// Also emits a never-called `_assertTypesConformance_<member>` peer that statically asserts every
|
|
63
76
|
/// type crossing the JS boundary conforms to the JS-convertible protocol, so a non-conforming type
|
|
64
77
|
/// fails to compile on the user's declaration. The peer name embeds the member name, hence
|
|
@@ -158,10 +171,15 @@ public macro SharedObject(_ name: String? = nil) =
|
|
|
158
171
|
/// non-`private`/`fileprivate`, non-`lazy`, non-computed stored property is part of the record — no
|
|
159
172
|
/// `@Field` wrapper needed — and the macro synthesizes the whole conversion surface from each
|
|
160
173
|
/// property's static type: a memberwise `init`, the `from(object:appContext:)` /
|
|
161
|
-
/// `from(dictionary:appContext:)` factories,
|
|
162
|
-
/// `toObject(appContext:)` write side
|
|
163
|
-
///
|
|
164
|
-
///
|
|
174
|
+
/// `from(dictionary:appContext:)` factories, the `toDictionary(appContext:)` /
|
|
175
|
+
/// `toObject(appContext:)` write side, and the `JavaScriptDecodable` / `JavaScriptEncodable`
|
|
176
|
+
/// conversions `decode(_:in:)` and `encode(_:in:)`. The type is auto-conformed to `Record`; the
|
|
177
|
+
/// synthesized methods override `Record`'s reflection-based defaults, so it stays usable anywhere a
|
|
178
|
+
/// `Record` argument is expected.
|
|
179
|
+
///
|
|
180
|
+
/// `decode(_:in:)` and `encode(_:in:)` use the runtime they receive and don't need an app context, so
|
|
181
|
+
/// the record converts on any runtime. A class with an inheritance clause doesn't get them, so it
|
|
182
|
+
/// converts only on a runtime that an app context prepared.
|
|
165
183
|
///
|
|
166
184
|
/// Requiredness is inferred from each property: a default value makes it optional, an optional type
|
|
167
185
|
/// makes it nullable and optional, and a non-optional property without a default is required (the
|
|
@@ -177,8 +195,8 @@ public macro SharedObject(_ name: String? = nil) =
|
|
|
177
195
|
/// }
|
|
178
196
|
@attached(
|
|
179
197
|
member,
|
|
180
|
-
names: named(init), named(from), named(toDictionary), named(toObject),
|
|
181
|
-
named(_assertTypesConformance))
|
|
198
|
+
names: named(init), named(from), named(toDictionary), named(toObject), named(decode), named(encode),
|
|
199
|
+
named(_assertTypesConformance), named(_PropNames))
|
|
182
200
|
@attached(extension, conformances: Record)
|
|
183
201
|
public macro Record() =
|
|
184
202
|
#externalMacro(module: "ExpoModulesMacros", type: "RecordMacro")
|
|
@@ -22,6 +22,19 @@ public class ExpoRuntime: JavaScriptRuntime, @unchecked Sendable {
|
|
|
22
22
|
return try getCoreObject().getPropertyAsFunction("SharedRef")
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/// Creates an instance of the base `SharedObject` class, or of the base `SharedRef` class if `isSharedRef` is true.
|
|
26
|
+
/// The prototypes of both classes are looked up once per runtime and cached.
|
|
27
|
+
@JavaScriptActor
|
|
28
|
+
internal func createBaseSharedObject(isSharedRef: Bool) throws -> JavaScriptObject {
|
|
29
|
+
let prototypes = try cached(baseSharedObjectPrototypesKey) {
|
|
30
|
+
return try BaseSharedObjectPrototypes(in: self)
|
|
31
|
+
}
|
|
32
|
+
if isSharedRef {
|
|
33
|
+
return createObject(prototype: prototypes.sharedRef)
|
|
34
|
+
}
|
|
35
|
+
return createObject(prototype: prototypes.sharedObject)
|
|
36
|
+
}
|
|
37
|
+
|
|
25
38
|
@JavaScriptActor
|
|
26
39
|
internal func createNativeModuleObject() throws -> JavaScriptObject {
|
|
27
40
|
return try getCoreObject()
|
|
@@ -42,3 +55,18 @@ public class ExpoRuntime: JavaScriptRuntime, @unchecked Sendable {
|
|
|
42
55
|
return try createClass(name: name, inheriting: sharedRefBaseClass, constructor)
|
|
43
56
|
}
|
|
44
57
|
}
|
|
58
|
+
|
|
59
|
+
/// The prototypes of the base `SharedObject` and `SharedRef` classes.
|
|
60
|
+
private final class BaseSharedObjectPrototypes {
|
|
61
|
+
let sharedObject: JavaScriptObject
|
|
62
|
+
let sharedRef: JavaScriptObject
|
|
63
|
+
|
|
64
|
+
@JavaScriptActor
|
|
65
|
+
init(in runtime: ExpoRuntime) throws {
|
|
66
|
+
sharedObject = try runtime.getSharedObjectClass().asObject().getPropertyAsObject("prototype")
|
|
67
|
+
sharedRef = try runtime.getSharedRefClass().asObject().getPropertyAsObject("prototype")
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/// Key of the base shared object prototypes in each runtime's cache.
|
|
72
|
+
private let baseSharedObjectPrototypesKey = JavaScriptRuntime.Cache.Key<BaseSharedObjectPrototypes>()
|
|
@@ -36,6 +36,12 @@ open class SharedObject: AnySharedObject {
|
|
|
36
36
|
*/
|
|
37
37
|
public init() {}
|
|
38
38
|
|
|
39
|
+
/// The value of `nativeRefType` on the JavaScript object, or `nil` when the object does not conform to
|
|
40
|
+
/// `AnySharedRef`.
|
|
41
|
+
internal var sharedRefType: String? {
|
|
42
|
+
return (self as? AnySharedRef)?.nativeRefType
|
|
43
|
+
}
|
|
44
|
+
|
|
39
45
|
/**
|
|
40
46
|
A function that will be called before the object is removed from the registry.
|
|
41
47
|
*/
|
|
@@ -23,7 +23,9 @@ public final class SharedObjectRegistry: Sendable {
|
|
|
23
23
|
|
|
24
24
|
// `@unchecked` because `SharedObjectNativeState` isn't `Sendable` (its JSI base class isn't), yet a
|
|
25
25
|
// value escapes `withLock` whenever `get`/the lookups return it. Access is always serialized through
|
|
26
|
-
// `state`'s `Mutex`
|
|
26
|
+
// `state`'s `Mutex`. `delete(_:)` can run on the thread that destroys a C++ native state, such as a
|
|
27
|
+
// garbage collector thread, so it and `add` change the native object's ID and native state only under
|
|
28
|
+
// the lock.
|
|
27
29
|
internal struct State: @unchecked Sendable {
|
|
28
30
|
/**
|
|
29
31
|
Maps each shared object id to the native object's `SharedObjectNativeState`, which carries the
|
|
@@ -93,23 +95,25 @@ public final class SharedObjectRegistry: Sendable {
|
|
|
93
95
|
*/
|
|
94
96
|
@discardableResult
|
|
95
97
|
internal func add(native nativeObject: SharedObject, javaScript jsObject: borrowing JavaScriptObject) -> SharedObjectId {
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
//
|
|
99
|
-
|
|
98
|
+
// Reuse the native state, and with it the ID, only while a live JS object in this runtime holds it.
|
|
99
|
+
// That JS object keeps the C++ native state alive until `setNativeState` attaches it to `jsObject`.
|
|
100
|
+
// Otherwise the C++ native state can be in destruction on another thread, and its release must not
|
|
101
|
+
// apply to `jsObject`, so the native object gets a new native state and ID.
|
|
102
|
+
let pairedObject = pairedObjectHoldingNativeState(of: nativeObject)
|
|
103
|
+
let existingNativeState = pairedObject != nil ? nativeObject.nativeState : nil
|
|
100
104
|
let id = existingNativeState != nil ? nativeObject.sharedObjectId : pullNextId()
|
|
101
105
|
|
|
102
|
-
// Assign the
|
|
103
|
-
nativeObject.sharedObjectId = id
|
|
106
|
+
// Assign the app context to the object.
|
|
104
107
|
nativeObject.appContext = appContext
|
|
105
108
|
|
|
106
109
|
// This property should be deprecated, but it's still used when passing as a view prop.
|
|
107
110
|
// It's already defined in the JS base SharedObject class prototype,
|
|
108
111
|
// but with the current implementation it's possible to use a raw object for registration.
|
|
109
|
-
|
|
112
|
+
// No option set literals here: they build the set through a generic initializer on every call.
|
|
113
|
+
jsObject.defineProperty(sharedObjectIdPropertyName, value: id, options: .writable)
|
|
110
114
|
|
|
111
|
-
if let
|
|
112
|
-
jsObject.defineProperty("nativeRefType", value:
|
|
115
|
+
if let sharedRefType = nativeObject.sharedRefType {
|
|
116
|
+
jsObject.defineProperty("nativeRefType", value: sharedRefType, options: JavaScriptObject.PropertyOptions())
|
|
113
117
|
}
|
|
114
118
|
|
|
115
119
|
let memoryPressure = nativeObject.getAdditionalMemoryPressure()
|
|
@@ -120,11 +124,6 @@ public final class SharedObjectRegistry: Sendable {
|
|
|
120
124
|
// Attach the C++ shared-object native state. Because `expo::SharedObject::NativeState`
|
|
121
125
|
// inherits from `expo::EventEmitter::NativeState`, later `addListener` calls see an
|
|
122
126
|
// existing native state (via the inheritance check) and don't overwrite it.
|
|
123
|
-
//
|
|
124
|
-
// A native object may already carry a native state from a previous pairing in another runtime.
|
|
125
|
-
// Reuse it so all runtimes share one native state (and one underlying C++ pointee, via
|
|
126
|
-
// `acquireShared`); a fresh state per runtime would leave `nativeObject.nativeState` pointing at
|
|
127
|
-
// whichever ran last and lose the earlier runtimes' pairings.
|
|
128
127
|
let nativeState = existingNativeState ?? {
|
|
129
128
|
let releaser: ObjectReleaser = { [weak self] id in
|
|
130
129
|
self?.delete(id)
|
|
@@ -137,21 +136,24 @@ public final class SharedObjectRegistry: Sendable {
|
|
|
137
136
|
contextDeallocator: deallocator
|
|
138
137
|
)
|
|
139
138
|
}
|
|
140
|
-
nativeObject.nativeState = state
|
|
141
139
|
return state
|
|
142
140
|
}()
|
|
143
141
|
|
|
144
|
-
// Index the native state by
|
|
145
|
-
//
|
|
142
|
+
// Index the native state by ID. `delete(_:)` reads the native object's ID and native state on any
|
|
143
|
+
// thread, so they change under the same lock.
|
|
146
144
|
state.withLock { state in
|
|
147
145
|
state.pairs[id] = nativeState
|
|
146
|
+
nativeObject.sharedObjectId = id
|
|
147
|
+
nativeObject.nativeState = nativeState
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
// setNativeState calls acquireShared() synchronously, which retains `nativeState`
|
|
151
151
|
// via Unmanaged.passRetained. That's the wrapper's only strong reference — once
|
|
152
152
|
// the C++ pointee dies, the contextDeallocator releases it. Reattaching the same
|
|
153
153
|
// native state to another runtime's JS object reuses that same C++ pointee.
|
|
154
|
-
|
|
154
|
+
withExtendedLifetime(pairedObject) {
|
|
155
|
+
jsObject.setNativeState(nativeState)
|
|
156
|
+
}
|
|
155
157
|
|
|
156
158
|
// The registry is scoped to its app context, so the JS object being paired here lives in that
|
|
157
159
|
// context's runtime. Record the pairing under that runtime so the native object can recover this
|
|
@@ -171,12 +173,18 @@ public final class SharedObjectRegistry: Sendable {
|
|
|
171
173
|
if let nativeState = state.pairs[id] {
|
|
172
174
|
let native = nativeState.native
|
|
173
175
|
nativeState.markReleased()
|
|
174
|
-
native.sharedObjectWillRelease()
|
|
175
|
-
// Reset an ID on the object.
|
|
176
|
-
native.sharedObjectId = 0
|
|
177
176
|
|
|
178
177
|
// Delete the entry from the dictionary.
|
|
179
178
|
state.pairs[id] = nil
|
|
179
|
+
|
|
180
|
+
// A native object that was paired again after its JS object died has a new native state and ID,
|
|
181
|
+
// and stays paired.
|
|
182
|
+
guard native.nativeState === nativeState else {
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
native.sharedObjectWillRelease()
|
|
186
|
+
// Reset an ID on the object.
|
|
187
|
+
native.sharedObjectId = 0
|
|
180
188
|
native.sharedObjectDidRelease()
|
|
181
189
|
}
|
|
182
190
|
}
|
|
@@ -229,13 +237,7 @@ public final class SharedObjectRegistry: Sendable {
|
|
|
229
237
|
guard let runtime = try? appContext?.runtime else {
|
|
230
238
|
return nil
|
|
231
239
|
}
|
|
232
|
-
|
|
233
|
-
// owns the per-runtime JS counterparts, so a single lookup serves both. Prefer the native object's
|
|
234
|
-
// own back-pointer and fall back to the id table for objects whose back-pointer was cleared.
|
|
235
|
-
let nativeState = unreleasedNativeState(of: nativeObject) ?? state.withLock { state in
|
|
236
|
-
return state.pairs[nativeObject.sharedObjectId]
|
|
237
|
-
}
|
|
238
|
-
return nativeState?.javaScriptObject(in: runtime)
|
|
240
|
+
return unreleasedNativeState(of: nativeObject)?.javaScriptObject(in: runtime)
|
|
239
241
|
}
|
|
240
242
|
|
|
241
243
|
/// Returns the native object's native state, or `nil` if it was released. A released native state can
|
|
@@ -247,6 +249,19 @@ public final class SharedObjectRegistry: Sendable {
|
|
|
247
249
|
return nativeState
|
|
248
250
|
}
|
|
249
251
|
|
|
252
|
+
/// Returns the JS object paired with the native object in this registry's runtime, if it is alive and
|
|
253
|
+
/// still holds the native object's native state.
|
|
254
|
+
private func pairedObjectHoldingNativeState(of nativeObject: SharedObject) -> JavaScriptObject? {
|
|
255
|
+
guard let runtime = try? appContext?.runtime,
|
|
256
|
+
let nativeState = unreleasedNativeState(of: nativeObject),
|
|
257
|
+
let pairedObject = nativeState.javaScriptObject(in: runtime),
|
|
258
|
+
pairedObject.getNativeState(as: SharedObjectNativeState.self) === nativeState
|
|
259
|
+
else {
|
|
260
|
+
return nil
|
|
261
|
+
}
|
|
262
|
+
return pairedObject
|
|
263
|
+
}
|
|
264
|
+
|
|
250
265
|
/**
|
|
251
266
|
Creates a plain JS object and pairs it with a given native object.
|
|
252
267
|
*/
|
|
@@ -16,6 +16,10 @@ open class SharedRef<RefType>: SharedObject, AnySharedRef {
|
|
|
16
16
|
"unknown"
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
internal override var sharedRefType: String? {
|
|
20
|
+
return nativeRefType
|
|
21
|
+
}
|
|
22
|
+
|
|
19
23
|
@available(*, deprecated, renamed: "ref", message: "it has been renamed to 'ref' in Expo SDK 52")
|
|
20
24
|
public var pointer: RefType {
|
|
21
25
|
return ref
|
|
@@ -67,7 +67,11 @@ extension ExpoSwiftUI {
|
|
|
67
67
|
self.contentView = ContentView(props: props)
|
|
68
68
|
let rootView = AnyView(contentView)
|
|
69
69
|
self.props = props
|
|
70
|
+
#if os(iOS) || os(tvOS)
|
|
71
|
+
let controller: UIHostingController<AnyView> = AppearanceTrackingHostingController(rootView: rootView)
|
|
72
|
+
#else
|
|
70
73
|
let controller = UIHostingController(rootView: rootView)
|
|
74
|
+
#endif
|
|
71
75
|
|
|
72
76
|
if #available(iOS 16.0, tvOS 16.0, macOS 13.0, *) {
|
|
73
77
|
controller.sizingOptions = [.intrinsicContentSize]
|
|
@@ -259,10 +263,27 @@ extension ExpoSwiftUI {
|
|
|
259
263
|
addSubview(hostingController.view)
|
|
260
264
|
#if os(iOS) || os(tvOS)
|
|
261
265
|
hostingController.didMove(toParent: parentController)
|
|
266
|
+
forwardAppearanceIfMissed(parentController: parentController)
|
|
262
267
|
#endif
|
|
263
268
|
setupHostingViewConstraints()
|
|
264
269
|
}
|
|
265
270
|
|
|
271
|
+
#if os(iOS) || os(tvOS)
|
|
272
|
+
// A child added during a transition after its parent appeared never appears, so it gets no safe area (#51288).
|
|
273
|
+
// TODO: Workaround for https://github.com/software-mansion/react-native-screens/pull/4997, remove once it ships.
|
|
274
|
+
private func forwardAppearanceIfMissed(parentController: UIViewController) {
|
|
275
|
+
guard
|
|
276
|
+
parentController.transitionCoordinator != nil,
|
|
277
|
+
let controller = hostingController as? AppearanceTrackingHostingController,
|
|
278
|
+
!controller.isAppearing
|
|
279
|
+
else {
|
|
280
|
+
return
|
|
281
|
+
}
|
|
282
|
+
controller.beginAppearanceTransition(true, animated: false)
|
|
283
|
+
controller.endAppearanceTransition()
|
|
284
|
+
}
|
|
285
|
+
#endif
|
|
286
|
+
|
|
266
287
|
#if os(macOS)
|
|
267
288
|
public override func reactViewController() -> NSViewController? {
|
|
268
289
|
var currentView: NSView? = self
|
|
@@ -278,6 +299,23 @@ extension ExpoSwiftUI {
|
|
|
278
299
|
}
|
|
279
300
|
}
|
|
280
301
|
|
|
302
|
+
#if os(iOS) || os(tvOS)
|
|
303
|
+
// Records whether UIKit forwarded appearance, so `HostingView` can forward it when UIKit misses it.
|
|
304
|
+
private final class AppearanceTrackingHostingController: UIHostingController<AnyView> {
|
|
305
|
+
private(set) var isAppearing = false
|
|
306
|
+
|
|
307
|
+
override func viewWillAppear(_ animated: Bool) {
|
|
308
|
+
super.viewWillAppear(animated)
|
|
309
|
+
isAppearing = true
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
override func viewDidDisappear(_ animated: Bool) {
|
|
313
|
+
super.viewDidDisappear(animated)
|
|
314
|
+
isAppearing = false
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
#endif
|
|
318
|
+
|
|
281
319
|
extension UIHostingController {
|
|
282
320
|
/// Applies the `ignoreSafeArea` mode reactively, restoring the default safe area when `nil` so
|
|
283
321
|
/// clearing the prop re-enables the safe area without an app reload.
|
|
@@ -8,6 +8,8 @@ extension ExpoSwiftUI {
|
|
|
8
8
|
*/
|
|
9
9
|
struct UIViewHost: UIViewRepresentable, AnyChild {
|
|
10
10
|
let view: UIView
|
|
11
|
+
// Fabric can mount a recycled view again; a new identity per mount gives it a new container.
|
|
12
|
+
private let mountToken = MountToken()
|
|
11
13
|
|
|
12
14
|
// MARK: - UIViewRepresentable implementations
|
|
13
15
|
|
|
@@ -64,8 +66,14 @@ extension ExpoSwiftUI {
|
|
|
64
66
|
var uiView: UIView? {
|
|
65
67
|
view
|
|
66
68
|
}
|
|
69
|
+
|
|
70
|
+
var childIdentity: ExpoSwiftUI.ChildIdentity {
|
|
71
|
+
.object(ObjectIdentifier(mountToken))
|
|
72
|
+
}
|
|
67
73
|
}
|
|
68
74
|
|
|
75
|
+
private final class MountToken {}
|
|
76
|
+
|
|
69
77
|
#if !os(macOS)
|
|
70
78
|
/**
|
|
71
79
|
Disposable UIView handed to SwiftUI in place of the React-managed view —
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-modules-core",
|
|
3
|
-
"version": "58.0.
|
|
3
|
+
"version": "58.0.24",
|
|
4
4
|
"description": "The core of Expo Modules architecture",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"expo",
|
|
@@ -66,12 +66,12 @@
|
|
|
66
66
|
"./package.json": "./package.json"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"expo-modules-jsi": "~58.0.
|
|
70
|
-
"expo-modules-macros": "0.
|
|
69
|
+
"expo-modules-jsi": "~58.0.17",
|
|
70
|
+
"expo-modules-macros": "0.22.0",
|
|
71
71
|
"invariant": "^2.2.4"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@expo/internal-scripts": "58.0.
|
|
74
|
+
"@expo/internal-scripts": "58.0.4",
|
|
75
75
|
"@testing-library/react-native": "^14.0.1",
|
|
76
76
|
"@types/invariant": "^2.2.33",
|
|
77
77
|
"@types/react": "~19.3.0",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|