expo-modules-core 58.0.16 → 58.0.18

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,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 58.0.18
4
+
5
+ ### Patch Changes
6
+
7
+ - [iOS] Fix slow cold launches in brownfield apps where the `ExpoModulesProvider` lookup scanned `Bundle.allFrameworks` inside `+load`. The lookup now tries the framework that contains ExpoModulesCore before falling back to the scan. ([#51481](https://github.com/expo/expo/pull/51481) by [@expo-bot](https://github.com/expo-bot))
8
+ - [iOS] Update `expo-modules-macros` to 0.20.0, which binds `@JS` functions and setters that return nothing through the `Void` overload, so they no longer build an `undefined` value on each call. ([#51548](https://github.com/expo/expo/pull/51548) by [@tsapeta](https://github.com/tsapeta))
9
+ - [iOS] Reduced the overhead of emitting module events. ([#51553](https://github.com/expo/expo/pull/51553) by [@tsapeta](https://github.com/tsapeta))
10
+ - Updated dependencies. ([#51496](https://github.com/expo/expo/pull/51496), [#51499](https://github.com/expo/expo/pull/51499), [#51498](https://github.com/expo/expo/pull/51498), [#51371](https://github.com/expo/expo/pull/51371))
11
+ - expo-modules-jsi@58.0.13
12
+
13
+ ## 58.0.17
14
+
15
+ ### Patch Changes
16
+
17
+ - [iOS] Fix a launch crash (`Symbol not found: _swift_allocateMetadataPack`) in apps that use precompiled Expo modules and build with Xcode 27. `ExpoModulesJSI` no longer exports Swift runtime symbols, so the precompiled `ExpoModulesCore` no longer depends on them. ([#51463](https://github.com/expo/expo/pull/51463) by [@chrfalch](https://github.com/chrfalch))
18
+ - [iOS] Fix a `UIViewControllerHierarchyInconsistency` crash when a SwiftUI view (such as `@expo/ui`'s `Host`) is rendered inside a text input's accessory view, for example React Native's `InputAccessoryView` or react-native-keyboard-controller's `KeyboardExtender`. ([#51420](https://github.com/expo/expo/pull/51420) by [@kirillzyusko](https://github.com/kirillzyusko))
19
+ - Updated dependencies. ([#51463](https://github.com/expo/expo/pull/51463), [#51451](https://github.com/expo/expo/pull/51451))
20
+ - expo-modules-jsi@58.0.12
21
+
3
22
  ## 58.0.16
4
23
 
5
24
  ### Patch Changes
@@ -119,7 +119,7 @@ Pod::Spec.new do |s|
119
119
  s.static_framework = true
120
120
  s.header_dir = 'ExpoModulesCore'
121
121
  s.source_files = 'ios/**/*.{h,m,mm,swift,cpp}', 'common/cpp/**/*.{h,cpp}'
122
- s.exclude_files = ['ios/Tests', 'ios/Worklets', 'ios/WorkletsTests', 'ios/WorkletsAdapter']
122
+ s.exclude_files = ['ios/Tests', 'ios/Benchmarks', 'ios/Worklets', 'ios/WorkletsTests', 'ios/WorkletsAdapter']
123
123
  s.compiler_flags = compiler_flags
124
124
  s.private_header_files = ['ios/**/*+Private.h', 'ios/**/Swift.h']
125
125
  end
@@ -145,4 +145,13 @@ Pod::Spec.new do |s|
145
145
  'SWIFT_OBJC_BRIDGING_HEADER' => '$(PODS_TARGET_SRCROOT)/ios/Tests/Tests-Bridging-Header.h'
146
146
  }
147
147
  end
148
+
149
+ # Performance benchmarks. A separate spec, so unit test runs neither build nor run them.
150
+ s.test_spec 'Benchmarks' do |test_spec|
151
+ test_spec.dependency 'ExpoModulesTestCore'
152
+ test_spec.source_files = 'ios/Benchmarks/**/*.swift'
153
+ test_spec.pod_target_xcconfig = {
154
+ 'OTHER_LDFLAGS' => '$(inherited) -lc++'
155
+ }
156
+ end
148
157
  end
@@ -46,7 +46,7 @@ if (shouldIncludeCompose) {
46
46
  }
47
47
 
48
48
  group = 'host.exp.exponent'
49
- version = '58.0.16'
49
+ version = '58.0.18'
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.4"
100
+ def expoModulesV2Version = "0.2.5"
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.16"
178
+ versionName "58.0.18"
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": "4a484f59a9d342285a14ab862c0ea08a",
3
+ "sourceHash": "0b72456880c81b38b6a81f2e69eb4cf4",
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-13T08:41:33.015189716Z"
19
+ "createdAt": "2026-10-14T21:13:57.838030Z"
20
20
  }
Binary file
@@ -3,6 +3,7 @@ package expo.modules.v2
3
3
  import com.facebook.react.bridge.ReactApplicationContext
4
4
  import expo.modules.kotlin.logger
5
5
  import io.github.expo.modules.v2.Module
6
+ import io.github.expo.modules.v2.react.ExpoModulesV2React
6
7
  import io.github.expo.modules.v2.react.ReactRuntime
7
8
  import java.lang.reflect.Modifier
8
9
 
@@ -30,6 +31,9 @@ object ExpoModulesV2Host {
30
31
  }
31
32
 
32
33
  try {
34
+ // Must run before `ReactRuntime` initializes. Its superclass, kolibri's `NativeObject`,
35
+ // otherwise loads the native library under kolibri's default name, which does not exist.
36
+ ExpoModulesV2React.ensureLoaded()
33
37
  // The runtime creates a context of its own, and serves the modules of that context.
34
38
  val attached = ReactRuntime.attach(reactContext)
35
39
  try {
@@ -41,10 +41,11 @@ size_t Listeners::listenersCount(const std::string& eventName) noexcept {
41
41
  }
42
42
 
43
43
  void Listeners::call(jsi::Runtime &runtime, const std::string& eventName, const jsi::Object &thisObject, const jsi::Value *args, size_t count) noexcept {
44
- if (!listenersMap.contains(eventName)) {
44
+ auto entry = listenersMap.find(eventName);
45
+ if (entry == listenersMap.end()) {
45
46
  return;
46
47
  }
47
- ListenersList &listenersList = listenersMap[eventName];
48
+ ListenersList &listenersList = entry->second;
48
49
  size_t listSize = listenersList.size();
49
50
 
50
51
  if (listSize == 0) {
@@ -102,8 +103,11 @@ NativeState::~NativeState() {
102
103
  }
103
104
 
104
105
  NativeState::Shared NativeState::get(jsi::Runtime &runtime, const jsi::Object &object, bool createIfMissing) {
105
- if (object.hasNativeState<NativeState>(runtime)) {
106
- return object.getNativeState<NativeState>(runtime);
106
+ // The untyped `hasNativeState` is a single runtime call. The state is then fetched once, and its type is checked.
107
+ if (object.hasNativeState(runtime)) {
108
+ if (NativeState::Shared state = std::dynamic_pointer_cast<NativeState>(object.getNativeState(runtime))) {
109
+ return state;
110
+ }
107
111
  }
108
112
  if (createIfMissing) {
109
113
  NativeState::Shared state = std::make_shared<NativeState>();
@@ -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.4")
36
+ implementation("io.github.expo:expo-modules-v2-gradle-plugin:0.2.5")
37
37
 
38
38
  if (isExpoAutolinkingSettingsPluginAvailable) {
39
39
  implementation("expo.modules:expo-autolinking-plugin-shared")
@@ -0,0 +1,15 @@
1
+ // Copyright 2026-present 650 Industries. All rights reserved.
2
+
3
+ import Testing
4
+
5
+ /// Umbrella suite for the ExpoModulesCore benchmarks; the other files in this directory extend it.
6
+ ///
7
+ /// The benchmarks are the `Benchmarks` test spec of the pod, separate from the unit tests. Build them in
8
+ /// the Release configuration, so the numbers reflect optimized code. Each case prints one `[benchmark]`
9
+ /// line with the median and minimum ns/op.
10
+ ///
11
+ /// The suite is serialized so only one benchmark runs at a time: the `JavaScriptActor` executor runs
12
+ /// jobs synchronously on the calling thread, so cases running in parallel would disturb each other's
13
+ /// measurements.
14
+ @Suite(.serialized)
15
+ struct Benchmarks {}
@@ -0,0 +1,140 @@
1
+ // Copyright 2026-present 650 Industries. All rights reserved.
2
+
3
+ import ExpoModulesTestCore
4
+ import Testing
5
+
6
+ @testable import ExpoModulesCore
7
+
8
+ /// Benchmarks for emitting module events to JavaScript. Each case emits from Swift in a loop to a
9
+ /// no-op JS listener. The standalone test runtime runs scheduled work synchronously, so every operation
10
+ /// covers the whole path: scheduling, converting the payload, reaching the module's JavaScript object
11
+ /// and calling the listener. Read the payload cases against `emit: no payload`.
12
+ extension Benchmarks {
13
+ @Test
14
+ func `emit: no payload`() async throws {
15
+ try await eventBenchmarkCase { module, runtime in
16
+ try benchmark("emit: no payload", runtime: runtime) { iterations in
17
+ for _ in 0..<iterations {
18
+ module.emit(event: "ping")
19
+ }
20
+ }
21
+ }
22
+ }
23
+
24
+ @Test
25
+ func `emit: no payload, 100 other modules registered`() async throws {
26
+ try await eventBenchmarkCase(otherModuleCount: 100) { module, runtime in
27
+ try benchmark("emit: no payload, 100 other modules registered", runtime: runtime) { iterations in
28
+ for _ in 0..<iterations {
29
+ module.emit(event: "ping")
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ @Test
36
+ func `emit: Int payload`() async throws {
37
+ try await eventBenchmarkCase { module, runtime in
38
+ try benchmark("emit: Int payload", runtime: runtime) { iterations in
39
+ for index in 0..<iterations {
40
+ module.emit(event: "count", payload: index)
41
+ }
42
+ }
43
+ }
44
+ }
45
+
46
+ @Test
47
+ func `emit: Int payload through @Event`() async throws {
48
+ try await eventBenchmarkCase { module, runtime in
49
+ try benchmark("emit: Int payload through @Event", runtime: runtime) { iterations in
50
+ for index in 0..<iterations {
51
+ module.onCount(index)
52
+ }
53
+ }
54
+ }
55
+ }
56
+
57
+ @Test
58
+ func `emit: Int payload as AnyArgument`() async throws {
59
+ try await eventBenchmarkCase { module, runtime in
60
+ try benchmark("emit: Int payload as AnyArgument", runtime: runtime) { iterations in
61
+ for index in 0..<iterations {
62
+ emitAsAnyArgument(module, event: "count", payload: index)
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ @Test
69
+ func `emit: record payload`() async throws {
70
+ try await eventBenchmarkCase { module, runtime in
71
+ try benchmark("emit: record payload", runtime: runtime) { iterations in
72
+ for index in 0..<iterations {
73
+ module.emit(event: "progress", payload: ProgressPayload(percent: index, label: "loading"))
74
+ }
75
+ }
76
+ }
77
+ }
78
+
79
+ @Test
80
+ func `emit: record payload as AnyArgument`() async throws {
81
+ try await eventBenchmarkCase { module, runtime in
82
+ try benchmark("emit: record payload as AnyArgument", runtime: runtime) { iterations in
83
+ for index in 0..<iterations {
84
+ emitAsAnyArgument(module, event: "progress", payload: ProgressPayload(percent: index, label: "loading"))
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+
91
+ @Record
92
+ private struct ProgressPayload {
93
+ var percent: Int = 0
94
+ var label: String = ""
95
+ }
96
+
97
+ @ExpoModule
98
+ private final class EventBenchmarkModule: Module {
99
+ @Event
100
+ var onPing: () -> Void
101
+
102
+ @Event
103
+ var onCount: (Int) -> Void
104
+
105
+ @Event
106
+ var onProgress: (ProgressPayload) -> Void
107
+ }
108
+
109
+ @ExpoModule
110
+ private final class IdleModule: Module {}
111
+
112
+ /// Runs one case with a fresh app context that has `EventBenchmarkModule` registered, with a no-op
113
+ /// JavaScript listener on each of its events. `otherModuleCount` more modules are registered first.
114
+ private func eventBenchmarkCase(
115
+ otherModuleCount: Int = 0,
116
+ _ body: @escaping @JavaScriptActor (EventBenchmarkModule, JavaScriptRuntime) throws -> Void
117
+ ) async throws {
118
+ try await moduleBenchmarkCase { appContext in
119
+ for index in 0..<otherModuleCount {
120
+ appContext.moduleRegistry.register(module: IdleModule(appContext: appContext), name: "IdleModule\(index)")
121
+ }
122
+ return EventBenchmarkModule(appContext: appContext)
123
+ } _: { module, runtime in
124
+ try runtime.eval(
125
+ """
126
+ const listener = () => {};
127
+ expo.modules.EventBenchmarkModule.addListener('ping', listener);
128
+ expo.modules.EventBenchmarkModule.addListener('count', listener);
129
+ expo.modules.EventBenchmarkModule.addListener('progress', listener);
130
+ """
131
+ )
132
+ try body(module, runtime)
133
+ }
134
+ }
135
+
136
+ /// Emits through the `AnyArgument` overload, which a direct call doesn't reach for a payload that is
137
+ /// also `JavaScriptEncodable`.
138
+ private func emitAsAnyArgument<P: AnyArgument>(_ module: EventBenchmarkModule, event: String, payload: sending P) {
139
+ module.emit(event: event, payload: payload)
140
+ }
@@ -0,0 +1,112 @@
1
+ // Copyright 2026-present 650 Industries. All rights reserved.
2
+
3
+ import ExpoModulesTestCore
4
+ import Testing
5
+
6
+ @testable import ExpoModulesCore
7
+
8
+ /// Benchmarks for JavaScript calling `@JS` functions of an `@ExpoModule`. A JavaScript driver runs the
9
+ /// measured loop, so each operation covers the full call: the engine's call dispatch, decoding the
10
+ /// arguments, the Swift function and encoding the result. Read every result against
11
+ /// `JS: empty driver loop`.
12
+ extension Benchmarks {
13
+ @Test
14
+ func `JS: empty driver loop`() async throws {
15
+ try await functionBenchmarkCase(body: "") { run, runtime in
16
+ try benchmark("JS: empty driver loop", runtime: runtime) { iterations in
17
+ _ = try run.call(arguments: iterations)
18
+ }
19
+ }
20
+ }
21
+
22
+ @Test
23
+ func `@JS: no arguments`() async throws {
24
+ try await functionBenchmarkCase(body: "m.noop();") { run, runtime in
25
+ try benchmark("@JS: no arguments", runtime: runtime) { iterations in
26
+ _ = try run.call(arguments: iterations)
27
+ }
28
+ }
29
+ }
30
+
31
+ @Test
32
+ func `@JS: two Double arguments and a Double result`() async throws {
33
+ try await functionBenchmarkCase(body: "m.add(i, 2);") { run, runtime in
34
+ try benchmark("@JS: two Double arguments and a Double result", runtime: runtime) { iterations in
35
+ _ = try run.call(arguments: iterations)
36
+ }
37
+ }
38
+ }
39
+
40
+ @Test
41
+ func `@JS: String argument and result`() async throws {
42
+ try await functionBenchmarkCase(body: "m.echo('hello');") { run, runtime in
43
+ try benchmark("@JS: String argument and result", runtime: runtime) { iterations in
44
+ _ = try run.call(arguments: iterations)
45
+ }
46
+ }
47
+ }
48
+
49
+ @Test
50
+ func `@JS: record argument and result`() async throws {
51
+ try await functionBenchmarkCase(setup: "var point = { x: 1, y: 2 };", body: "m.mirror(point);") { run, runtime in
52
+ try benchmark("@JS: record argument and result", runtime: runtime) { iterations in
53
+ _ = try run.call(arguments: iterations)
54
+ }
55
+ }
56
+ }
57
+
58
+ @Test
59
+ func `@JS: async function with no arguments`() async throws {
60
+ try await functionBenchmarkCase(body: "m.noopAsync();") { run, runtime in
61
+ try benchmark("@JS: async function with no arguments", runtime: runtime) { iterations in
62
+ _ = try run.call(arguments: iterations)
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ @Record
69
+ private struct BenchmarkPoint {
70
+ var x: Double = 0
71
+ var y: Double = 0
72
+ }
73
+
74
+ @ExpoModule
75
+ private final class FunctionBenchmarkModule: Module {
76
+ @JS
77
+ func noop() {}
78
+
79
+ @JS
80
+ func add(a: Double, b: Double) -> Double {
81
+ return a + b
82
+ }
83
+
84
+ @JS
85
+ func echo(text: String) -> String {
86
+ return text
87
+ }
88
+
89
+ @JS
90
+ func mirror(point: BenchmarkPoint) -> BenchmarkPoint {
91
+ return BenchmarkPoint(x: point.y, y: point.x)
92
+ }
93
+
94
+ @JS
95
+ @JavaScriptActor
96
+ func noopAsync() async {}
97
+ }
98
+
99
+ /// Runs one case with `FunctionBenchmarkModule` registered and a JavaScript driver that runs `body` in a
100
+ /// loop, with the module in `m`.
101
+ private func functionBenchmarkCase(
102
+ setup: String = "",
103
+ body: String,
104
+ _ measure: @escaping @JavaScriptActor (borrowing JavaScriptFunction, JavaScriptRuntime) throws -> Void
105
+ ) async throws {
106
+ try await moduleBenchmarkCase { appContext in
107
+ return FunctionBenchmarkModule(appContext: appContext)
108
+ } _: { _, runtime in
109
+ let run = try javaScriptDriver(runtime, setup: "var m = expo.modules.FunctionBenchmarkModule; \(setup)", body: body)
110
+ try measure(run, runtime)
111
+ }
112
+ }
@@ -0,0 +1,80 @@
1
+ // Copyright 2026-present 650 Industries. All rights reserved.
2
+
3
+ import ExpoModulesTestCore
4
+ import Testing
5
+
6
+ @testable import ExpoModulesCore
7
+
8
+ /// Benchmarks for JavaScript using a `@SharedObject` class: creating instances and calling their `@JS`
9
+ /// members. A JavaScript driver runs the measured loop. Read every result against
10
+ /// `JS: empty driver loop`.
11
+ extension Benchmarks {
12
+ @Test
13
+ func `@SharedObject: new instance`() async throws {
14
+ try await sharedObjectBenchmarkCase(body: "new Counter(i);") { run, runtime in
15
+ try benchmark("@SharedObject: new instance", runtime: runtime) { iterations in
16
+ _ = try run.call(arguments: iterations)
17
+ }
18
+ }
19
+ }
20
+
21
+ @Test
22
+ func `@SharedObject: method call`() async throws {
23
+ try await sharedObjectBenchmarkCase(body: "counter.increment(1);") { run, runtime in
24
+ try benchmark("@SharedObject: method call", runtime: runtime) { iterations in
25
+ _ = try run.call(arguments: iterations)
26
+ }
27
+ }
28
+ }
29
+
30
+ @Test
31
+ func `@SharedObject: property read`() async throws {
32
+ try await sharedObjectBenchmarkCase(body: "counter.current;") { run, runtime in
33
+ try benchmark("@SharedObject: property read", runtime: runtime) { iterations in
34
+ _ = try run.call(arguments: iterations)
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ @SharedObject
41
+ private final class BenchmarkCounter: SharedObject {
42
+ private var value: Int
43
+
44
+ @JS
45
+ init(value: Int) {
46
+ self.value = value
47
+ }
48
+
49
+ @JS
50
+ func increment(by amount: Int) -> Int {
51
+ value += amount
52
+ return value
53
+ }
54
+
55
+ @JS
56
+ var current: Int {
57
+ return value
58
+ }
59
+ }
60
+
61
+ @ExpoModule(classes: [BenchmarkCounter.self])
62
+ private final class SharedObjectBenchmarkModule: Module {}
63
+
64
+ /// 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`.
66
+ private func sharedObjectBenchmarkCase(
67
+ body: String,
68
+ _ measure: @escaping @JavaScriptActor (borrowing JavaScriptFunction, JavaScriptRuntime) throws -> Void
69
+ ) async throws {
70
+ try await moduleBenchmarkCase { appContext in
71
+ return SharedObjectBenchmarkModule(appContext: appContext)
72
+ } _: { _, runtime in
73
+ let run = try javaScriptDriver(
74
+ runtime,
75
+ setup: "var Counter = expo.modules.SharedObjectBenchmarkModule.BenchmarkCounter; var counter = new Counter(0);",
76
+ body: body
77
+ )
78
+ try measure(run, runtime)
79
+ }
80
+ }
@@ -764,7 +764,27 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
764
764
  return providerClass.init()
765
765
  }
766
766
 
767
- // [2] Fallback to search for `ExpoModulesProvider` in frameworks (brownfield use case)
767
+ // [2] Fallback to the framework that contains ExpoModulesCore itself (brownfield use case).
768
+ // Brownfield apps often prelink React Native and Expo into one dynamic framework; the
769
+ // generated provider is then compiled into that framework, so its Swift module is the
770
+ // framework's name and the main-bundle lookups above miss. Trying this bundle first avoids
771
+ // the `Bundle.allFrameworks` scan below, which materializes a bundle for every loaded
772
+ // framework and runs inside `+load` on every cold launch.
773
+ let coreBundle = Bundle(for: AppContext.self)
774
+ if coreBundle.bundlePath != Bundle.main.bundlePath {
775
+ let coreBundleNames = [
776
+ coreBundle.infoDictionary?["CFBundleExecutable"],
777
+ coreBundle.infoDictionary?["CFBundleName"]
778
+ ].compactMap { $0 as? String }
779
+
780
+ for providerClassName in moduleProviderClassNames(withName: providerName, bundleNames: coreBundleNames) {
781
+ if let providerClass = NSClassFromString(providerClassName) as? ModulesProvider.Type {
782
+ return providerClass.init()
783
+ }
784
+ }
785
+ }
786
+
787
+ // [3] Fallback to search for `ExpoModulesProvider` in frameworks (brownfield use case)
768
788
  for bundle in Bundle.allFrameworks {
769
789
  let frameworkBundleNames = [
770
790
  bundle.infoDictionary?["CFBundleExecutable"],
@@ -778,7 +798,7 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
778
798
  }
779
799
  }
780
800
 
781
- // [3] Fallback to an empty `ModulesProvider` if `ExpoModulesProvider` was not generated
801
+ // [4] Fallback to an empty `ModulesProvider` if `ExpoModulesProvider` was not generated
782
802
  return ModulesProvider()
783
803
  }
784
804
 
@@ -45,10 +45,10 @@ public extension EventEmitter {
45
45
  let payload = payload.ref()
46
46
  // The emitter is not necessarily `Sendable` - some modules hold non-sendable state — so we can't let
47
47
  // the compiler send `self` into the `@JavaScriptActor` region. Wrapping it in a weak, `@unchecked
48
- // Sendable` box is safe here because the scheduled closure only calls `withEventTarget`, which touches
48
+ // Sendable` reference is safe here because the scheduled closure only calls `withEventTarget`, which touches
49
49
  // `@JavaScriptActor`-isolated or `Sendable` state (the JS object, the registry, `appContext`) and the
50
50
  // emitter's identity - never the module's own mutable state.
51
- let emitter = NonisolatedUnsafeWeakVar(self)
51
+ let emitter = WeakEventEmitterReference(value: self)
52
52
 
53
53
  runtime.schedule {
54
54
  guard let emitter = emitter.value else {
@@ -71,15 +71,51 @@ public extension EventEmitter {
71
71
  /**
72
72
  Schedules an event with the given name and payload to be emitted to the associated JavaScript object.
73
73
  */
74
+ 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
+ return
78
+ }
79
+ // See the note in `emit(event:payload:)` above - the emitter is captured in a weak, `@unchecked
80
+ // Sendable` reference because it isn't necessarily `Sendable`, and the scheduled closure only reaches
81
+ // `@JavaScriptActor`-isolated or `Sendable` state through it.
82
+ let emitter = WeakEventEmitterReference(value: self)
83
+
84
+ runtime.schedule {
85
+ guard let emitter = emitter.value else {
86
+ return
87
+ }
88
+ let jsPayload: JavaScriptValue
89
+ do {
90
+ jsPayload = try P.encode(payload, in: runtime)
91
+ } catch {
92
+ log.warn("Failed to convert payload for event '\(event)' on \(P.self); the event will not be emitted: \(error)")
93
+ return
94
+ }
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
+ }
102
+ }
103
+ }
104
+
105
+ /**
106
+ Schedules an event with the given name and payload to be emitted to the associated JavaScript object.
107
+ Payloads that are `JavaScriptEncodable` use the overload above, which converts them statically.
108
+ */
109
+ @_disfavoredOverload
74
110
  func emit<P: AnyArgument>(event: String, payload: sending P) {
75
111
  guard let appContext, let runtime = try? appContext.runtime else {
76
112
  log.warn("Trying to send event '\(event)' to \(type(of: self)), but the JS runtime has been lost")
77
113
  return
78
114
  }
79
115
  // See the note in `emit(event:payload:)` above - the emitter is captured in a weak, `@unchecked
80
- // Sendable` box because it isn't necessarily `Sendable`, and the scheduled closure only reaches
116
+ // Sendable` reference because it isn't necessarily `Sendable`, and the scheduled closure only reaches
81
117
  // `@JavaScriptActor`-isolated or `Sendable` state through it.
82
- let emitter = NonisolatedUnsafeWeakVar(self)
118
+ let emitter = WeakEventEmitterReference(value: self)
83
119
 
84
120
  runtime.schedule { [weak appContext] in
85
121
  guard let emitter = emitter.value, let appContext else {
@@ -103,6 +139,12 @@ public extension EventEmitter {
103
139
  }
104
140
  }
105
141
 
142
+ /// 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 {
145
+ weak var value: (any EventEmitter)?
146
+ }
147
+
106
148
  /**
107
149
  Sends a pre-converted event payload to the given JavaScript object via the JSI emitter helper.
108
150
  Must run on the JS thread; the public `emit` overloads schedule onto the runtime before calling in.
@@ -112,13 +154,15 @@ internal func dispatchEvent(event: String, payload: borrowing JavaScriptValue, t
112
154
  runtime.withUnsafePointee { runtimePtr in
113
155
  target.withUnsafePointee { objectPtr in
114
156
  payload.withUnsafePointee { payloadPtr in
115
- JSUtils.emitEvent(
116
- event,
117
- runtimePointer: runtimePtr,
118
- objectPointer: objectPtr,
119
- argumentsPointer: payloadPtr,
120
- argumentCount: 1
121
- )
157
+ event.withCString { eventName in
158
+ emitJSEvent(
159
+ utf8Name: eventName,
160
+ runtimePointer: runtimePtr,
161
+ objectPointer: objectPtr,
162
+ argumentsPointer: payloadPtr,
163
+ argumentCount: 1
164
+ )
165
+ }
122
166
  }
123
167
  }
124
168
  }
@@ -53,6 +53,7 @@ public final class ModuleHolder {
53
53
  self._name = name
54
54
  self.module = module
55
55
  self.definition = ModuleHolder.buildDefinition(for: module)
56
+ (module as? BaseModule)?.holder = self
56
57
  post(event: .moduleCreate)
57
58
  }
58
59
 
@@ -31,8 +31,8 @@ public final class ModuleRegistry: Sequence {
31
31
  return true
32
32
  }
33
33
  if didRegister {
34
- // Call the `didCreate` lifecycle hook only after the holder is in the registry, so the module
35
- // can already look itself up (e.g. through `withEventTarget`). Rejected registrations don't get it.
34
+ // Call the `didCreate` lifecycle hook only after the holder is in the registry, so lookups such as
35
+ // `get(moduleWithName:)` can already find the module. Rejected registrations don't get it.
36
36
  holder.module.didCreate()
37
37
  }
38
38
  }
@@ -8,6 +8,10 @@ import ExpoModulesJSI
8
8
  open class BaseModule {
9
9
  public private(set) weak var appContext: AppContext?
10
10
 
11
+ /// The holder that registered this module. Emitting events reaches the module's JavaScript object
12
+ /// through it, without searching the module registry.
13
+ internal weak var holder: ModuleHolder?
14
+
11
15
  @available(
12
16
  *, unavailable,
13
17
  message: "Module's initializer cannot be overridden, override the \"didCreate\" lifecycle hook instead."
@@ -51,16 +55,14 @@ open class BaseModule {
51
55
 
52
56
  extension BaseModule: EventEmitter {
53
57
  /**
54
- Lends the module's JavaScript object, looked up from the module registry, for the duration of `body`.
58
+ Lends the module's JavaScript object for the duration of `body`.
55
59
  */
56
60
  @JavaScriptActor
57
61
  public func withEventTarget<R>(_ body: (borrowing JavaScriptObject) throws -> R) rethrows -> R? {
58
- guard let appContext else {
62
+ guard let holder else {
59
63
  return nil
60
64
  }
61
- let holder = appContext.moduleRegistry.first { $0.module === self }
62
-
63
- return try holder?.withEventTarget(body) ?? nil
65
+ return try holder.withEventTarget(body)
64
66
  }
65
67
  }
66
68
 
@@ -240,6 +240,15 @@ extension ExpoSwiftUI {
240
240
  hostingController.removeFromParent()
241
241
  return
242
242
  }
243
+ // `reactViewController()` walks the responder chain, which may not match the view hierarchy:
244
+ // UIKit makes an input accessory view's `nextResponder` the text input that owns it. UIKit throws
245
+ // when a child controller's view is outside its parent's view, so skip containment in that case.
246
+ if !(parentController.viewIfLoaded.map(isDescendant(of:)) ?? false) {
247
+ hostingController.removeFromParent()
248
+ addSubview(hostingController.view)
249
+ setupHostingViewConstraints()
250
+ return
251
+ }
243
252
  if parentController as? UINavigationController == nil && parentController as? UITabBarController == nil {
244
253
  // Swift automatically adds the hostingController in the correct place when the parentController
245
254
  // is UINavigationController, since its children are supposed to be only screens.
@@ -1,6 +1,7 @@
1
1
  // Copyright 2025-present 650 Industries. All rights reserved.
2
2
 
3
3
  #import <Foundation/Foundation.h>
4
+ #import <ExpoModulesCore/EXDefines.h>
4
5
 
5
6
  NS_SWIFT_NAME(JSUtils)
6
7
  @interface EXJSUtils : NSObject
@@ -26,3 +27,18 @@ NS_SWIFT_NAME(JSUtils)
26
27
  argumentCount:(NSUInteger)argumentCount;
27
28
 
28
29
  @end
30
+
31
+ EX_EXTERN_C_BEGIN
32
+
33
+ /**
34
+ Same as `+[EXJSUtils emitEvent:runtimePointer:objectPointer:argumentsPointer:argumentCount:]`, but the event
35
+ name is a null-terminated UTF-8 string, and the call needs no Objective-C message.
36
+ */
37
+ void EXJSUtilsEmitEvent(const char *_Nonnull eventName,
38
+ void *_Nonnull runtimePointer,
39
+ const void *_Nonnull objectPointer,
40
+ const void *_Nullable argumentsPointer,
41
+ size_t argumentCount)
42
+ NS_SWIFT_NAME(emitJSEvent(utf8Name:runtimePointer:objectPointer:argumentsPointer:argumentCount:));
43
+
44
+ EX_EXTERN_C_END
@@ -27,17 +27,26 @@
27
27
  objectPointer:(nonnull const void *)objectPointer
28
28
  argumentsPointer:(nullable const void *)argumentsPointer
29
29
  argumentCount:(NSUInteger)argumentCount
30
+ {
31
+ EXJSUtilsEmitEvent([eventName UTF8String], runtimePointer, objectPointer, argumentsPointer, argumentCount);
32
+ }
33
+
34
+ @end
35
+
36
+ void EXJSUtilsEmitEvent(const char *eventName,
37
+ void *runtimePointer,
38
+ const void *objectPointer,
39
+ const void *argumentsPointer,
40
+ size_t argumentCount)
30
41
  {
31
42
  auto &runtime = *static_cast<jsi::Runtime *>(runtimePointer);
32
43
  auto &object = *static_cast<const jsi::Object *>(objectPointer);
33
44
 
34
45
  if (argumentCount == 0 || argumentsPointer == nullptr) {
35
- expo::EventEmitter::emitEvent(runtime, object, [eventName UTF8String], nullptr, 0);
46
+ expo::EventEmitter::emitEvent(runtime, object, eventName, nullptr, 0);
36
47
  return;
37
48
  }
38
49
 
39
50
  auto *args = static_cast<const jsi::Value *>(argumentsPointer);
40
- expo::EventEmitter::emitEvent(runtime, object, [eventName UTF8String], args, static_cast<size_t>(argumentCount));
51
+ expo::EventEmitter::emitEvent(runtime, object, eventName, args, argumentCount);
41
52
  }
42
-
43
- @end
@@ -95,20 +95,6 @@ internal class NonisolatedUnsafeVar<VarType>: @unchecked Sendable {
95
95
  }
96
96
  }
97
97
 
98
- /**
99
- Like ``NonisolatedUnsafeVar``, but holds a weak reference so it can be captured into an isolated
100
- closure without extending the referenced object's lifetime. Useful for sending a non-`Sendable`
101
- object across an isolation boundary while keeping weak semantics.
102
- - TODO: Remove it once the code is refactored to deal better with the concurrency model.
103
- */
104
- internal class NonisolatedUnsafeWeakVar<VarType: AnyObject>: @unchecked Sendable {
105
- nonisolated(unsafe) weak var value: VarType?
106
-
107
- init(_ value: VarType?) {
108
- self.value = value
109
- }
110
- }
111
-
112
98
  internal func performSynchronouslyOnMainActor<Result: Sendable>(_ closure: @MainActor () throws -> Result) rethrows -> Result {
113
99
  if Thread.isMainThread {
114
100
  return try MainActor.assumeIsolated(closure)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-modules-core",
3
- "version": "58.0.16",
3
+ "version": "58.0.18",
4
4
  "description": "The core of Expo Modules architecture",
5
5
  "keywords": [
6
6
  "expo",
@@ -64,12 +64,12 @@
64
64
  "./package.json": "./package.json"
65
65
  },
66
66
  "dependencies": {
67
- "expo-modules-jsi": "~58.0.11",
68
- "expo-modules-macros": "0.19.1",
67
+ "expo-modules-jsi": "~58.0.13",
68
+ "expo-modules-macros": "0.20.0",
69
69
  "invariant": "^2.2.4"
70
70
  },
71
71
  "devDependencies": {
72
- "@expo/internal-scripts": "58.0.1",
72
+ "@expo/internal-scripts": "58.0.2",
73
73
  "@testing-library/react-native": "^14.0.1",
74
74
  "@types/invariant": "^2.2.33",
75
75
  "@types/react": "~19.3.0",
package/spm.config.json CHANGED
@@ -36,7 +36,13 @@
36
36
  "path": "ios",
37
37
  "pattern": "**/*.{m,mm}",
38
38
  "headerPattern": "**/*.h",
39
- "exclude": ["Tests/**", "WorkletsTests/**", "Worklets/**", "WorkletsAdapter/**"],
39
+ "exclude": [
40
+ "Tests/**",
41
+ "Benchmarks/**",
42
+ "WorkletsTests/**",
43
+ "Worklets/**",
44
+ "WorkletsAdapter/**"
45
+ ],
40
46
  "fileMapping": [
41
47
  {
42
48
  "from": "Core/Views/SwiftUI/SwiftUIVirtualViewSharedImpl+Private.h",
@@ -65,6 +71,7 @@
65
71
  "exclude": [
66
72
  "JSI/**",
67
73
  "Tests/**",
74
+ "Benchmarks/**",
68
75
  "WorkletsTests/**",
69
76
  "BridgeModule/**",
70
77
  "Views/**",