expo-modules-core 58.0.26 → 58.0.27

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 CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 58.0.27
4
+
5
+ ### Patch Changes
6
+
7
+ - [Android] Fix a crash when a function returns the same `ArrayBuffer` to JavaScript many times. Each return held a new JNI global reference until garbage collection, which overflowed the global reference table. ([#52278](https://github.com/expo/expo/pull/52278) by [@github-actions](https://github.com/apps/github-actions))
8
+ - [Android] Avoid Kotlin reflection when sorting task service providers. ([`571588f`](https://github.com/expo/expo/commit/571588f363d0598e9196bb9560635bc1cf8fe817) by [@matthew-gizmo](https://github.com/matthew-gizmo))
9
+ - [iOS] Reduce the overhead of emitting events by reaching the JSI runtime, the emitter object and the payload in one call. ([#52178](https://github.com/expo/expo/pull/52178) by [@tsapeta](https://github.com/tsapeta))
10
+ - [iOS] Reduce the overhead of emitting events with a `JavaScriptEncodable` payload, including from `@Event` properties, by specializing `emit(event:payload:)` for the payload type in the caller's module. ([#52179](https://github.com/expo/expo/pull/52179) by [@tsapeta](https://github.com/tsapeta))
11
+ - [iOS] Build the JavaScript classes of `@SharedObject` classes registered with `@ExpoModule(classes:)` from their type, without a `ClassDefinition`. ([#52137](https://github.com/expo/expo/pull/52137) by [@tsapeta](https://github.com/tsapeta))
12
+ - [iOS] Update `expo-modules-macros` to 0.24.0. A sync closure argument of a `@JS` function now encodes its arguments with code specialized for their types. ([#52232](https://github.com/expo/expo/pull/52232) by [@tsapeta](https://github.com/tsapeta))
13
+ - [iOS] Update `expo-modules-macros` to 0.23.1. `@JS` now supports a `lazy var`, which is read-only from JavaScript and stores its value on the JavaScript object at the first read. `@SharedObject` now supports subclasses of `SharedRef<T>`. Macros in a generic type no longer fail to build when a generic parameter of the type has the same name as one in the generated code. ([#52200](https://github.com/expo/expo/pull/52200) by [@tsapeta](https://github.com/tsapeta))
14
+ - [iOS] Fix `MenuView` triggers that fill their parent, so text in them wraps and they resize on rotation. ([#52278](https://github.com/expo/expo/pull/52278) by [@github-actions](https://github.com/apps/github-actions))
15
+ - Updated dependencies. ([#52232](https://github.com/expo/expo/pull/52232), [#52164](https://github.com/expo/expo/pull/52164), [#52178](https://github.com/expo/expo/pull/52178))
16
+ - expo-modules-jsi@58.0.20
17
+
3
18
  ## 58.0.26
4
19
 
5
20
  ### Patch Changes
@@ -46,7 +46,7 @@ if (shouldIncludeCompose) {
46
46
  }
47
47
 
48
48
  group = 'host.exp.exponent'
49
- version = '58.0.26'
49
+ version = '58.0.27'
50
50
 
51
51
  def isExpoModulesCoreTests = {
52
52
  Gradle gradle = getGradle()
@@ -97,7 +97,7 @@ if (workletsProject != null) {
97
97
 
98
98
  def reactNativeWorkletsRootDir = workletsProject?.projectDir?.parentFile
99
99
 
100
- def expoModulesV2Version = "0.2.5"
100
+ def expoModulesV2Version = "0.2.6"
101
101
 
102
102
  configurations {
103
103
  // Artifact-only: the C++ sources, not something to put on any classpath.
@@ -175,7 +175,7 @@ android {
175
175
  defaultConfig {
176
176
  consumerProguardFiles 'proguard-rules.pro'
177
177
  versionCode 1
178
- versionName "58.0.26"
178
+ versionName "58.0.27"
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": "d5785b6fa4de4ea64f18bdac451d0308",
3
+ "sourceHash": "e93890c6e60394cdef56149d38614433",
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-23T23:08:09.663847375Z"
19
+ "createdAt": "2026-10-27T11:46:34.803657897Z"
20
20
  }
Binary file
@@ -282,7 +282,13 @@ jni::local_ref<jni::JByteBuffer> ByteBufferArrayBufferStorage::toDirectBuffer()
282
282
  }
283
283
 
284
284
  std::shared_ptr<jsi::MutableBuffer> ByteBufferArrayBufferStorage::jsiMutableBuffer() {
285
- return std::make_shared<ByteBufferJSIMutableBuffer>(jni::make_local(_byteBuffer));
285
+ // All JS array buffers of this storage share one mutable buffer. Each mutable buffer holds a
286
+ // JNI global reference, and Android aborts the app when the global reference table overflows.
287
+ std::lock_guard<std::mutex> lock(_jsiMutableBufferMutex);
288
+ if (_jsiMutableBuffer == nullptr) {
289
+ _jsiMutableBuffer = std::make_shared<ByteBufferJSIMutableBuffer>(jni::make_local(_byteBuffer));
290
+ }
291
+ return _jsiMutableBuffer;
286
292
  }
287
293
 
288
294
  jsi::Value ByteBufferArrayBufferStorage::toJSIValue(jsi::Runtime &runtime) {
@@ -87,6 +87,8 @@ public:
87
87
 
88
88
  private:
89
89
  jni::global_ref<jni::JByteBuffer> _byteBuffer;
90
+ std::mutex _jsiMutableBufferMutex;
91
+ std::shared_ptr<jsi::MutableBuffer> _jsiMutableBuffer;
90
92
  };
91
93
 
92
94
  class MutableBufferViewArrayBufferStorage : public ArrayBufferStorage {
@@ -30,7 +30,7 @@ object TaskServiceProviderHelper {
30
30
  // Invoke and get the list of packages
31
31
  val result = getPackageList.invoke(null) as? List<*> ?: return null
32
32
  val packages = result.filterIsInstance<Package>()
33
- .sortedByDescending { ModulePriorities.get(it::class.qualifiedName) }
33
+ .sortedByDescending { ModulePriorities.get(it.javaClass.canonicalName) }
34
34
 
35
35
  // Check if any of the packages are providing a task manager implementation
36
36
  return packages
@@ -95,6 +95,18 @@ public:
95
95
  return it != viewProps->propsMap.end() && it->second.isBool() && it->second.getBool();
96
96
  }
97
97
 
98
+ // Set by `MenuView`'s `RNHostView`, whose `Host` is sized by Yoga instead of its content.
99
+ static bool boundedByHost(const react::Props::Shared &props) {
100
+ auto const *viewProps = dynamic_cast<const ExpoViewProps *>(props.get());
101
+
102
+ if (viewProps == nullptr) {
103
+ return false;
104
+ }
105
+
106
+ auto const it = viewProps->propsMap.find("expoInternalBoundedByHost");
107
+ return it != viewProps->propsMap.end() && it->second.isBool() && it->second.getBool();
108
+ }
109
+
98
110
  // Yoga calls this method for RNHostView when it has matchContents set
99
111
  react::Size measureContent(
100
112
  const react::LayoutContext &layoutContext,
@@ -111,7 +123,14 @@ public:
111
123
  return {};
112
124
  }
113
125
 
114
- return content->measure(layoutContext, hostedContentConstraints(*content));
126
+ auto constraints = hostedContentConstraints(*content);
127
+
128
+ if (boundedByHost(this->getProps())) {
129
+ // Like any Yoga child, the content can't be bigger than the space the `Host` offers.
130
+ constrainToMaximumSize(constraints, layoutConstraints.maximumSize);
131
+ }
132
+
133
+ return content->measure(layoutContext, constraints);
115
134
  }
116
135
 
117
136
  // We override this so RNHostView can lay out it's children
@@ -130,11 +149,14 @@ public:
130
149
  }
131
150
 
132
151
  // Use the same constraint that was used to measure the content, so that the layout is consistent with the measurement
152
+ auto constraints = hostedContentConstraints(*content);
153
+
154
+ if (boundedByHost(this->getProps())) {
155
+ constrainToMaximumSize(constraints, this->getLayoutMetrics().frame.size);
156
+ }
157
+
133
158
  auto const clonedContent = content->clone({});
134
- static_cast<react::LayoutableShadowNode &>(*clonedContent).layoutTree(
135
- layoutContext,
136
- hostedContentConstraints(*content)
137
- );
159
+ static_cast<react::LayoutableShadowNode &>(*clonedContent).layoutTree(layoutContext, constraints);
138
160
 
139
161
  this->replaceChild(*content, clonedContent, 0);
140
162
 
@@ -145,6 +167,13 @@ public:
145
167
  }
146
168
 
147
169
  private:
170
+ static void constrainToMaximumSize(react::LayoutConstraints &constraints, react::Size maximumSize) {
171
+ constraints.maximumSize.width = std::min(constraints.maximumSize.width, maximumSize.width);
172
+ constraints.maximumSize.height = std::min(constraints.maximumSize.height, maximumSize.height);
173
+ constraints.minimumSize.width = std::min(constraints.minimumSize.width, constraints.maximumSize.width);
174
+ constraints.minimumSize.height = std::min(constraints.minimumSize.height, constraints.maximumSize.height);
175
+ }
176
+
148
177
  // Owning on purpose: `layout()` calls `replaceChild()`, which overwrites this node's only strong
149
178
  // reference to the content — `RNHostView` is a leaf Yoga node, so Yoga keeps no second one, and
150
179
  // `YogaLayoutableShadowNode::replaceChild()` reads `oldChild` right after.
@@ -33,7 +33,7 @@ dependencies {
33
33
  implementation("com.facebook.react:react-native-gradle-plugin")
34
34
  implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
35
35
  implementation("io.github.expo.pika:pika-gradle:1.1.0")
36
- implementation("io.github.expo:expo-modules-v2-gradle-plugin:0.2.5")
36
+ implementation("io.github.expo:expo-modules-v2-gradle-plugin:0.2.6")
37
37
 
38
38
  if (isExpoAutolinkingSettingsPluginAvailable) {
39
39
  implementation("expo.modules:expo-autolinking-plugin-shared")
@@ -21,6 +21,17 @@ extension Benchmarks {
21
21
  }
22
22
  }
23
23
 
24
+ @Test
25
+ func `emit: no payload through @Event`() async throws {
26
+ try await eventBenchmarkCase { module, runtime in
27
+ try benchmark("emit: no payload through @Event", runtime: runtime) { iterations in
28
+ for _ in 0..<iterations {
29
+ module.onPing()
30
+ }
31
+ }
32
+ }
33
+ }
34
+
24
35
  @Test
25
36
  func `emit: no payload, 100 other modules registered`() async throws {
26
37
  try await eventBenchmarkCase(otherModuleCount: 100) { module, runtime in
@@ -76,6 +87,17 @@ extension Benchmarks {
76
87
  }
77
88
  }
78
89
 
90
+ @Test
91
+ func `emit: record payload through @Event`() async throws {
92
+ try await eventBenchmarkCase { module, runtime in
93
+ try benchmark("emit: record payload through @Event", runtime: runtime) { iterations in
94
+ for index in 0..<iterations {
95
+ module.onProgress(ProgressPayload(percent: index, label: "loading"))
96
+ }
97
+ }
98
+ }
99
+ }
100
+
79
101
  @Test
80
102
  func `emit: record payload as AnyArgument`() async throws {
81
103
  try await eventBenchmarkCase { module, runtime in
@@ -86,6 +108,49 @@ extension Benchmarks {
86
108
  }
87
109
  }
88
110
  }
111
+
112
+ @Test
113
+ func `emit: shared object payload`() async throws {
114
+ try await eventBenchmarkCase { module, runtime in
115
+ // Encoding the object once pairs it with a JavaScript object, as an object already used from
116
+ // JavaScript would be. Holding that object keeps the pair alive across garbage collections.
117
+ // A shared object isn't `Sendable`, so it can't be sent to `emit` more than once without
118
+ // opting out of the check, and an `@Event` with this payload type doesn't compile.
119
+ nonisolated(unsafe) let payload = EventPayloadObject()
120
+ let payloadObject = try EventPayloadObject.encode(payload, in: runtime)
121
+
122
+ try withExtendedLifetime(payloadObject) {
123
+ try benchmark("emit: shared object payload", runtime: runtime) { iterations in
124
+ for _ in 0..<iterations {
125
+ module.emit(event: "object", payload: payload)
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+
132
+ @Test
133
+ func `emit: [String: Any] payload`() async throws {
134
+ try await eventBenchmarkCase { module, runtime in
135
+ // `[String: Any]` isn't `Sendable`, so an `@Event` with this payload type doesn't compile.
136
+ try benchmark("emit: [String: Any] payload", runtime: runtime) { iterations in
137
+ for index in 0..<iterations {
138
+ module.emit(event: "dictionary", payload: ["percent": index, "label": "loading"] as [String: Any])
139
+ }
140
+ }
141
+ }
142
+ }
143
+
144
+ @Test
145
+ func `emit: [String: String] payload through @Event`() async throws {
146
+ try await eventBenchmarkCase { module, runtime in
147
+ try benchmark("emit: [String: String] payload through @Event", runtime: runtime) { iterations in
148
+ for _ in 0..<iterations {
149
+ module.onStrings(["state": "loading", "label": "file"])
150
+ }
151
+ }
152
+ }
153
+ }
89
154
  }
90
155
 
91
156
  @Record
@@ -94,6 +159,8 @@ private struct ProgressPayload {
94
159
  var label: String = ""
95
160
  }
96
161
 
162
+ private final class EventPayloadObject: SharedObject {}
163
+
97
164
  @ExpoModule
98
165
  private final class EventBenchmarkModule: Module {
99
166
  @Event
@@ -104,6 +171,9 @@ private final class EventBenchmarkModule: Module {
104
171
 
105
172
  @Event
106
173
  var onProgress: (ProgressPayload) -> Void
174
+
175
+ @Event
176
+ var onStrings: ([String: String]) -> Void
107
177
  }
108
178
 
109
179
  @ExpoModule
@@ -127,6 +197,9 @@ private func eventBenchmarkCase(
127
197
  expo.modules.EventBenchmarkModule.addListener('ping', listener);
128
198
  expo.modules.EventBenchmarkModule.addListener('count', listener);
129
199
  expo.modules.EventBenchmarkModule.addListener('progress', listener);
200
+ expo.modules.EventBenchmarkModule.addListener('object', listener);
201
+ expo.modules.EventBenchmarkModule.addListener('dictionary', listener);
202
+ expo.modules.EventBenchmarkModule.addListener('strings', listener);
130
203
  """
131
204
  )
132
205
  try body(module, runtime)
@@ -582,12 +582,9 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
582
582
  }) {
583
583
  instance = cachedInstance
584
584
  } else {
585
- guard let classDefinition = self.findClassDefinition(for: typeId) else {
586
- throw SharedObjectClassNotRegisteredException(String(describing: type(of: nativeObject)))
587
- }
588
- let built = try classDefinition.buildPrototype(
585
+ let built = try self.buildWorkletPrototype(
586
+ for: type(of: nativeObject),
589
587
  in: runtime,
590
- appContext: self,
591
588
  basePrototype: sharedObjectBaseProto.getObject()
592
589
  )
593
590
  instance = runtime.createObject(prototype: built)
@@ -601,6 +598,25 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
601
598
  sharedObjectClass.setProperty("__resolveInWorklet", value: resolveInWorklet.asObject())
602
599
  }
603
600
 
601
+ /// Builds the worklet prototype for a native shared object class, from the `ClassDefinition` of a module
602
+ /// that defines it or from a module that registers it in `_classTypes`.
603
+ @JavaScriptActor
604
+ private func buildWorkletPrototype(
605
+ for nativeType: SharedObject.Type,
606
+ in runtime: JavaScriptRuntime,
607
+ basePrototype: consuming JavaScriptObject
608
+ ) throws -> JavaScriptObject {
609
+ let typeId = ObjectIdentifier(nativeType)
610
+
611
+ if let classDefinition = findClassDefinition(for: typeId) {
612
+ return try classDefinition.buildPrototype(in: runtime, appContext: self, basePrototype: basePrototype)
613
+ }
614
+ if let classType = findClassType(for: typeId) {
615
+ return try JavaScriptBindings.buildSharedObjectPrototype(classType, in: runtime, basePrototype: basePrototype)
616
+ }
617
+ throw SharedObjectClassNotRegisteredException(String(describing: nativeType))
618
+ }
619
+
604
620
  /**
605
621
  Finds the ClassDefinition for a given native type identifier by searching all modules.
606
622
  */
@@ -616,6 +632,17 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
616
632
  return nil
617
633
  }
618
634
 
635
+ /// Finds the `@SharedObject` class for a given native type identifier among the classes that modules
636
+ /// register in `_classTypes`.
637
+ private func findClassType(for typeId: ObjectIdentifier) -> SharedObject.Type? {
638
+ for module in moduleRegistry {
639
+ if let classType = type(of: module.module)._classTypes.first(where: { ObjectIdentifier($0) == typeId }) {
640
+ return classType
641
+ }
642
+ }
643
+ return nil
644
+ }
645
+
619
646
  /**
620
647
  Unsets runtime objects that we hold for each module.
621
648
  */
@@ -1,6 +1,6 @@
1
1
  // Copyright 2024-present 650 Industries. All rights reserved.
2
2
 
3
- import ExpoModulesJSI
3
+ @_spi(Internal) import ExpoModulesJSI
4
4
 
5
5
  /**
6
6
  A protocol for native objects that have an associated JavaScript object capable of receiving events.
@@ -27,6 +27,7 @@ public extension EventEmitter {
27
27
  /**
28
28
  Schedules an event with the given name to be emitted to the associated JavaScript object.
29
29
  */
30
+ @inlinable
30
31
  func emit(event: String) {
31
32
  emit(event: event, payload: JavaScriptUndefined())
32
33
  }
@@ -71,9 +72,12 @@ public extension EventEmitter {
71
72
  /**
72
73
  Schedules an event with the given name and payload to be emitted to the associated JavaScript object.
73
74
  */
75
+ @inlinable
74
76
  func emit<P: JavaScriptEncodable>(event: String, payload: sending P) {
75
- guard let appContext, let runtime = try? appContext.runtime else {
76
- log.warn("Trying to send event '\(event)' to \(type(of: self)), but the JS runtime has been lost")
77
+ // Inlinable, so `P` and the scheduled closure specialize in the caller's module. Unspecialized, the
78
+ // payload is boxed and `P.encode` goes through the witness table on every event. The non-generic
79
+ // parts are calls into this module.
80
+ guard let runtime = eventRuntime(forEvent: event) else {
77
81
  return
78
82
  }
79
83
  // See the note in `emit(event:payload:)` above - the emitter is captured in a weak, `@unchecked
@@ -89,16 +93,10 @@ public extension EventEmitter {
89
93
  do {
90
94
  jsPayload = try P.encode(payload, in: runtime)
91
95
  } catch {
92
- log.warn("Failed to convert payload for event '\(event)' on \(P.self); the event will not be emitted: \(error)")
96
+ warnPayloadNotEncoded(event: event, payloadType: P.self, error: error)
93
97
  return
94
98
  }
95
- let dispatched = emitter.withEventTarget { target in
96
- dispatchEvent(event: event, payload: jsPayload, to: target, in: runtime)
97
- return true
98
- }
99
- if dispatched == nil {
100
- log.warn("Trying to send event '\(event)' to JS, but the JS object is no longer associated with the native instance")
101
- }
99
+ dispatchEvent(event: event, payload: jsPayload, from: emitter, in: runtime)
102
100
  }
103
101
  }
104
102
 
@@ -140,9 +138,57 @@ public extension EventEmitter {
140
138
  }
141
139
 
142
140
  /// A weak reference to an event emitter that the scheduled `emit` closures capture by value, so it is stored
143
- /// in the closure context without an allocation of its own.
144
- private struct WeakEventEmitterReference: @unchecked Sendable {
141
+ /// in the closure context without an allocation of its own. Frozen, because with library evolution the
142
+ /// inlinable initializer can't assign the stored property of a struct whose layout isn't fixed.
143
+ @frozen
144
+ @usableFromInline
145
+ internal struct WeakEventEmitterReference: @unchecked Sendable {
146
+ @usableFromInline
145
147
  weak var value: (any EventEmitter)?
148
+
149
+ @inlinable
150
+ init(value: any EventEmitter) {
151
+ self.value = value
152
+ }
153
+ }
154
+
155
+ extension EventEmitter {
156
+ /// The runtime to schedule an event on, or `nil` after logging a warning when it has been lost.
157
+ @usableFromInline
158
+ internal func eventRuntime(forEvent event: String) -> JavaScriptRuntime? {
159
+ guard let appContext, let runtime = try? appContext.runtime else {
160
+ log.warn("Trying to send event '\(event)' to \(type(of: self)), but the JS runtime has been lost")
161
+ return nil
162
+ }
163
+ return runtime
164
+ }
165
+ }
166
+
167
+ /// Logs that the payload of an event couldn't be converted, so the event is not emitted.
168
+ @usableFromInline
169
+ internal func warnPayloadNotEncoded(event: String, payloadType: Any.Type, error: any Error) {
170
+ log.warn(
171
+ "Failed to convert payload for event '\(event)' on \(payloadType); the event will not be emitted: \(error)"
172
+ )
173
+ }
174
+
175
+ /// Sends a pre-converted event payload to the JavaScript object of the given emitter. Logs a warning
176
+ /// when the emitter is no longer associated with a JavaScript object.
177
+ @JavaScriptActor
178
+ @usableFromInline
179
+ internal func dispatchEvent(
180
+ event: String,
181
+ payload: borrowing JavaScriptValue,
182
+ from emitter: any EventEmitter,
183
+ in runtime: JavaScriptRuntime
184
+ ) {
185
+ let dispatched = emitter.withEventTarget { target in
186
+ dispatchEvent(event: event, payload: payload, to: target, in: runtime)
187
+ return true
188
+ }
189
+ if dispatched == nil {
190
+ log.warn("Trying to send event '\(event)' to JS, but the JS object is no longer associated with the native instance")
191
+ }
146
192
  }
147
193
 
148
194
  /**
@@ -151,19 +197,15 @@ private struct WeakEventEmitterReference: @unchecked Sendable {
151
197
  */
152
198
  @JavaScriptActor
153
199
  internal func dispatchEvent(event: String, payload: borrowing JavaScriptValue, to target: borrowing JavaScriptObject, in runtime: JavaScriptRuntime) {
154
- runtime.withUnsafePointee { runtimePtr in
155
- target.withUnsafePointee { objectPtr in
156
- payload.withUnsafePointee { payloadPtr in
157
- event.withCString { eventName in
158
- emitJSEvent(
159
- utf8Name: eventName,
160
- runtimePointer: runtimePtr,
161
- objectPointer: objectPtr,
162
- argumentsPointer: payloadPtr,
163
- argumentCount: 1
164
- )
165
- }
166
- }
200
+ runtime.withUnsafePointees(object: target, value: payload) { runtimePtr, objectPtr, payloadPtr in
201
+ event.withCString { eventName in
202
+ emitJSEvent(
203
+ utf8Name: eventName,
204
+ runtimePointer: runtimePtr,
205
+ objectPointer: objectPtr,
206
+ argumentsPointer: payloadPtr,
207
+ argumentCount: 1
208
+ )
167
209
  }
168
210
  }
169
211
  }
@@ -107,11 +107,9 @@ public macro Event(_ name: String? = nil, sync: Bool = false) =
107
107
  #externalMacro(module: "ExpoModulesMacros", type: "EventMacro")
108
108
 
109
109
  /// Member macro applied to a `Module` subclass. Scans the class body for declarations
110
- /// marked with `@JS` and synthesizes a framework-internal `_synthesizedDefinition()` method.
111
- /// `expo-modules-core` calls it automatically and merges the result into the module's
112
- /// definition, so the user doesn't have to reference it from `definition()`. `@JS` functions are
113
- /// additionally bound directly into the module's JS object by a synthesized
114
- /// `_decorateModule(object:in:)`.
110
+ /// marked with `@JS` and binds them directly into the module's JS object by a synthesized
111
+ /// `_decorateModule(object:in:)`. The `@SharedObject` classes in the `classes:` argument are
112
+ /// emitted as a `_classTypes` static, and core adds their JavaScript classes to the module's JS object.
115
113
  ///
116
114
  /// The module's JavaScript name is synthesized into a `_jsName` static and read by core, so there
117
115
  /// is no `Name(…)` DSL entry. It defaults to the class name; pass `@ExpoModule("CustomName")` to
@@ -127,7 +125,7 @@ public macro Event(_ name: String? = nil, sync: Bool = false) =
127
125
  @attached(
128
126
  member,
129
127
  names:
130
- named(_jsName), named(_synthesizedDefinition), named(appContext), named(init),
128
+ named(_jsName), named(_classTypes), named(appContext), named(init),
131
129
  named(_decorateModule))
132
130
  @attached(memberAttribute)
133
131
  @attached(extension, conformances: AnyModule)
@@ -136,15 +134,16 @@ public macro ExpoModule(_ name: String? = nil, classes: [Any.Type] = []) =
136
134
 
137
135
  /// Member macro applied to a `SharedObject` subclass. Scans the class body for declarations
138
136
  /// marked with `@JS` (including a single `@JS init(...)` for the JS constructor) and
139
- /// synthesizes a `_synthesizedClassDefinition()` static method returning a `ClassDefinition`.
140
- /// The companion `@ExpoModule(classes: [Foo.self])` wires the class into the module's
141
- /// exposed surface.
137
+ /// binds them through overrides of the `SharedObject` hooks below. The class's JavaScript name
138
+ /// is emitted as a `_jsName` override. The companion `@ExpoModule(classes: [Foo.self])` wires the
139
+ /// class into the module's exposed surface.
142
140
  ///
143
141
  /// `@JS` methods and properties are bound directly onto the class prototype by an override of
144
- /// `_decorateSharedObject(prototype:in:)`, and a single `@JS init(...)` becomes an override
145
- /// of `_constructSharedObject(this:arguments:in:)` that builds the native instance from the
146
- /// JS arguments. Core calls both when building the class, so the synthesized `Class(…)` block carries
147
- /// no DSL entries for the `@JS` members.
142
+ /// `_decorateSharedObject(prototype:in:)`, `static` and `class` ones onto the class itself by an
143
+ /// override of `_decorateSharedObject(constructor:in:)`, and a single `@JS init(...)` becomes an
144
+ /// override of `_constructSharedObject(this:arguments:in:)` that builds the native instance from the
145
+ /// JS arguments. Core calls them when building the class. The class must be a `SharedObject`
146
+ /// subclass, direct or not, or the `_jsName` override doesn't compile.
148
147
  ///
149
148
  /// Usage:
150
149
  ///
@@ -162,7 +161,7 @@ public macro ExpoModule(_ name: String? = nil, classes: [Any.Type] = []) =
162
161
  @attached(
163
162
  member,
164
163
  names:
165
- named(_synthesizedClassDefinition), named(_decorateSharedObject), named(_constructSharedObject))
164
+ named(_jsName), named(_decorateSharedObject), named(_constructSharedObject))
166
165
  @attached(memberAttribute)
167
166
  public macro SharedObject(_ name: String? = nil) =
168
167
  #externalMacro(module: "ExpoModulesMacros", type: "SharedObjectMacro")
@@ -57,15 +57,8 @@ public final class ModuleHolder {
57
57
  post(event: .moduleCreate)
58
58
  }
59
59
 
60
- /// Combines the user-authored definition with the entries synthesized by the
61
- /// `@ExpoModule` macro on this module's class (if any). The macro emits a
62
- /// `_synthesizedDefinition()` method returning an `[AnyDefinition]` array of the
63
- /// `Function` / `Property` / `Constructor` entries it generated from `@JS`
64
- /// members. Those entries are prepended to the user's definitions and the
65
- /// whole list is fed back through `ModuleDefinition.init` so the merged
66
- /// result is rebucketed (into `functions`, `properties`, etc.) just like a
67
- /// hand-written definition. Modules that don't use the macro fall through
68
- /// the empty-synthesized fast path and return the user's definition unchanged.
60
+ /// Merges the entries from `_synthesizedDefinition()` into the user-authored definition. Only module
61
+ /// binaries built with earlier `@ExpoModule` macros return any, so other modules take the fast path.
69
62
  private static func buildDefinition(for module: AnyModule) -> ModuleDefinition {
70
63
  let userDefinition = module.definition()
71
64
  let synthesized = module._synthesizedDefinition()
@@ -137,6 +130,11 @@ public final class ModuleHolder {
137
130
  log.info("Creating JS object for module '\(name)'")
138
131
  let object = try definition.build(appContext: appContext)
139
132
 
133
+ // Install the `@SharedObject` classes the `@ExpoModule` macro registers by type.
134
+ for classType in type(of: module)._classTypes {
135
+ object.setProperty(classType._jsName, value: try JavaScriptBindings.buildSharedObjectClass(classType, appContext: appContext))
136
+ }
137
+
140
138
  // Install the `@JS` members the `@ExpoModule` macro binds directly into the JS object
141
139
  // (the direct-JSI path). A no-op for modules that don't use the macro.
142
140
  try module._decorateModule(object: object, in: appContext.runtime)
@@ -29,9 +29,8 @@ public final class ModuleDefinition: ObjectDefinition {
29
29
 
30
30
  let eventObservers: [AnyEventObservingDefinition]
31
31
 
32
- /// The raw list of definitions used to construct this module. Retained so
33
- /// that `ModuleHolder` can merge in the entries synthesized by the
34
- /// `@ExpoModule` macro without losing the user-authored ones.
32
+ /// The raw list of definitions used to construct this module. Retained so that `ModuleHolder` can
33
+ /// merge in the entries from `_synthesizedDefinition()` without losing the user-authored ones.
35
34
  let rawDefinitions: [AnyDefinition]
36
35
 
37
36
  /**
@@ -21,10 +21,14 @@ public protocol AnyModule: AnyObject, AnyArgument {
21
21
  /// Modules that don't use the macro fall back to the default, which is the class name.
22
22
  static var _jsName: String { get }
23
23
 
24
- /// Returns definitions synthesized from `@JS`-annotated members by the `@ExpoModule` macro.
25
- /// Framework-internal: the leading underscore signals this is not part of the public API and
26
- /// should only be called by `expo-modules-core` itself. Modules that don't use the macro fall
27
- /// back to the default empty implementation.
24
+ /// The `@SharedObject` classes the module exposes in its JavaScript object, emitted as a static
25
+ /// constant by the `@ExpoModule` macro from its `classes:` argument. Framework-internal (leading
26
+ /// underscore). Modules that don't use the macro fall back to the default empty list.
27
+ static var _classTypes: [SharedObject.Type] { get }
28
+
29
+ /// Returns definitions that core merges into the module's definition. The `@ExpoModule` macro no
30
+ /// longer emits it. It stays so that module binaries built with earlier macros keep loading and
31
+ /// keep their classes. Framework-internal (leading underscore).
28
32
  func _synthesizedDefinition() -> [AnyDefinition]
29
33
 
30
34
  /// Binds the module's `@JS` members directly into its JavaScript object, generated by the
@@ -62,6 +66,10 @@ extension AnyModule {
62
66
  @ModuleDefinitionBuilder
63
67
  public func definition() -> ModuleDefinition {}
64
68
 
69
+ public static var _classTypes: [SharedObject.Type] {
70
+ return []
71
+ }
72
+
65
73
  public func _synthesizedDefinition() -> [AnyDefinition] {
66
74
  return []
67
75
  }
@@ -111,6 +111,12 @@ open class SharedObject: AnySharedObject {
111
111
 
112
112
  // MARK: - Macro-synthesized JSI hooks
113
113
 
114
+ /// The name of the class in JavaScript. Overridden by the `@SharedObject` macro with the class name
115
+ /// or the `@SharedObject("CustomName")` argument. A module registers the class through `_classTypes`.
116
+ open class var _jsName: String {
117
+ return unqualifiedTypeName(self)
118
+ }
119
+
114
120
  /// Binds the class's `@JS` members onto its JavaScript prototype. Overridden by the `@SharedObject`
115
121
  /// macro; a `class func` (not a protocol requirement) so dispatch resolves per subclass.
116
122
  @JavaScriptActor
@@ -0,0 +1,53 @@
1
+ // Copyright 2026-present 650 Industries. All rights reserved.
2
+
3
+ import ExpoModulesJSI
4
+
5
+ /// Binds native types into the JavaScript runtime: creates their JavaScript classes and objects,
6
+ /// installs them and registers them in the app context.
7
+ internal enum JavaScriptBindings {
8
+ // MARK: - Shared objects
9
+
10
+ /// Builds the JavaScript class of a `@SharedObject` class that a module registers in `_classTypes`,
11
+ /// and registers its prototype for the class in `ClassRegistry`. All members come from the macro
12
+ /// hooks, so no `ClassDefinition` is needed.
13
+ @JavaScriptActor
14
+ static func buildSharedObjectClass(_ type: SharedObject.Type, appContext: AppContext) throws -> JavaScriptObject {
15
+ let name = type._jsName
16
+ let constructor: JavaScriptRuntime.SyncFunctionClosure = { [weak appContext] this, arguments in
17
+ guard let appContext else {
18
+ throw Exceptions.AppContextLost()
19
+ }
20
+ // Pair the native instance with `this` (returning a different object would drop the prototype
21
+ // chain `new` set up). Without a `@JS init`, only the native side can create an instance.
22
+ guard let sharedObject = try type._constructSharedObject(this: this, arguments: arguments, in: appContext.runtime) else {
23
+ throw Exceptions.ConstructorUnavailable(name)
24
+ }
25
+ appContext.sharedObjectRegistry.add(native: sharedObject, javaScript: this.getObject(), inheritsBaseClass: true)
26
+ return this
27
+ }
28
+ let runtime = try appContext.runtime
29
+ let createClass = type is AnySharedRef.Type ? runtime.createSharedRefClass : runtime.createSharedObjectClass
30
+ let klass = try createClass(name, constructor).asObject()
31
+ let prototype = klass.getProperty("prototype").getObject()
32
+
33
+ try type._decorateSharedObject(prototype: prototype, in: runtime)
34
+ try type._decorateSharedObject(constructor: klass, in: runtime)
35
+
36
+ appContext.classRegistry.register(nativeClassId: ObjectIdentifier(type), prototype: prototype)
37
+ return klass
38
+ }
39
+
40
+ /// Builds a prototype for a `@SharedObject` class in an alternate runtime (e.g. the worklet runtime),
41
+ /// inheriting from the given base prototype. The counterpart of `ClassDefinition.buildPrototype` for
42
+ /// the classes that a module registers in `_classTypes`.
43
+ @JavaScriptActor
44
+ static func buildSharedObjectPrototype(
45
+ _ type: SharedObject.Type,
46
+ in runtime: JavaScriptRuntime,
47
+ basePrototype: consuming JavaScriptObject
48
+ ) throws -> JavaScriptObject {
49
+ let prototype = runtime.createObject(prototype: basePrototype)
50
+ try type._decorateSharedObject(prototype: prototype, in: runtime)
51
+ return prototype
52
+ }
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-modules-core",
3
- "version": "58.0.26",
3
+ "version": "58.0.27",
4
4
  "description": "The core of Expo Modules architecture",
5
5
  "keywords": [
6
6
  "expo",
@@ -66,8 +66,8 @@
66
66
  "./package.json": "./package.json"
67
67
  },
68
68
  "dependencies": {
69
- "expo-modules-jsi": "~58.0.19",
70
- "expo-modules-macros": "0.22.0",
69
+ "expo-modules-jsi": "~58.0.20",
70
+ "expo-modules-macros": "0.24.0",
71
71
  "invariant": "^2.2.4"
72
72
  },
73
73
  "devDependencies": {