expo-modules-core 3.0.22 → 3.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 CHANGED
@@ -10,6 +10,33 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 3.0.24 — 2025-11-03
14
+
15
+ ### 🎉 New features
16
+
17
+ - [iOS] Added `subscriberDidRegister` function to AppDelegate subscribers. ([#40684](https://github.com/expo/expo/pull/40684) by [@tsapeta](https://github.com/tsapeta))
18
+
19
+ ### 🐛 Bug fixes
20
+
21
+ - [iOS] Fix `Either` conversion in `Record` ([#40655](https://github.com/expo/expo/pull/40655) by [@vonovak](https://github.com/vonovak))
22
+
23
+ ## 3.0.23 — 2025-10-28
24
+
25
+ ### 🎉 New features
26
+
27
+ - [iOS] Add `applicationDidReceiveMemoryWarning` subscribing to ExpoAppDelegateSubscriberManager ([#40504](https://github.com/expo/expo/pull/40504) by [@szydlovsky](https://github.com/szydlovsky))
28
+ - [iOS] Swift's `Encodable` types can now be converted to JavaScript values. ([#40621](https://github.com/expo/expo/pull/40621) by [@tsapeta](https://github.com/tsapeta))
29
+
30
+ ### 🐛 Bug fixes
31
+
32
+ - [core] [iOS] Addresses a potential crash where `[NSString UTF8String]` could return `nil` for certain string inputs (non-English), leading to an attempt to dereference a null pointer during `jsi::String` creation. ([#40639](https://github.com/expo/expo/pull/40639) by [@mohammadamin16](https://github.com/mohammadamin16))
33
+ - [Android] Fix `androidNavigationBar.enforceContrast` app config property not working. ([#40263](https://github.com/expo/expo/pull/40263) by [@behenate](https://github.com/behenate))
34
+
35
+ ### 💡 Others
36
+
37
+ - [iOS] Removed some runtime type checks for dynamic types. ([#40611](https://github.com/expo/expo/pull/40611) by [@tsapeta](https://github.com/tsapeta))
38
+ - [iOS] Added base props support for SwiftUI integration. ([#40492](https://github.com/expo/expo/pull/40492) by [@kudo](https://github.com/kudo))
39
+
13
40
  ## 3.0.22 — 2025-10-20
14
41
 
15
42
  ### 🎉 New features
@@ -29,7 +29,7 @@ if (shouldIncludeCompose) {
29
29
  }
30
30
 
31
31
  group = 'host.exp.exponent'
32
- version = '3.0.22'
32
+ version = '3.0.24'
33
33
 
34
34
  def isExpoModulesCoreTests = {
35
35
  Gradle gradle = getGradle()
@@ -79,7 +79,7 @@ android {
79
79
  defaultConfig {
80
80
  consumerProguardFiles 'proguard-rules.pro'
81
81
  versionCode 1
82
- versionName "3.0.22"
82
+ versionName "3.0.24"
83
83
  buildConfigField "String", "EXPO_MODULES_CORE_VERSION", "\"${versionName}\""
84
84
  buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled.toString()
85
85
 
@@ -0,0 +1,69 @@
1
+ package expo.modules.kotlin.edgeToEdge
2
+
3
+ import android.R
4
+ import android.app.Activity
5
+ import android.content.Context
6
+ import android.content.res.TypedArray
7
+ import android.os.Build
8
+ import android.os.Bundle
9
+ import android.util.Log
10
+ import android.view.Window
11
+ import androidx.annotation.RequiresApi
12
+ import expo.modules.core.BasePackage
13
+ import expo.modules.core.interfaces.ReactActivityLifecycleListener
14
+ import kotlin.Unit
15
+
16
+ class EdgeToEdgePackage : BasePackage() {
17
+ override fun createReactActivityLifecycleListeners(activityContext: Context?): List<ReactActivityLifecycleListener?>? {
18
+ return listOf(object : ReactActivityLifecycleListener {
19
+ override fun onCreate(activity: Activity?, savedInstanceState: Bundle?) {
20
+ val edgeToEdgeEnabled = invokeWindowUtilKtMethod<Boolean>("isEdgeToEdgeFeatureFlagOn") ?: true
21
+
22
+ if (edgeToEdgeEnabled) {
23
+ invokeWindowUtilKtMethod<Unit>("enableEdgeToEdge", Pair(Window::class.java, activity?.window))
24
+
25
+ // React-native sets `window.isNavigationBarContrastEnforced` to `true` in `WindowUtilKt.enableEdgeToEdge`.
26
+ // We have to set it back to the value defined in the app styles, which comes from our config plugin.
27
+ activity?.enforceNavigationBarContrastFromTheme()
28
+ }
29
+ }
30
+ })
31
+ }
32
+ }
33
+
34
+ @RequiresApi(Build.VERSION_CODES.Q)
35
+ private fun Activity.getEnforceContrastFromTheme(): Boolean {
36
+ val attrs = intArrayOf(R.attr.enforceNavigationBarContrast)
37
+ val typedArray: TypedArray = theme.obtainStyledAttributes(attrs)
38
+
39
+ return try {
40
+ typedArray.getBoolean(0, true)
41
+ } finally {
42
+ typedArray.recycle()
43
+ }
44
+ }
45
+
46
+ private fun Activity.enforceNavigationBarContrastFromTheme() {
47
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
48
+ window.isNavigationBarContrastEnforced = getEnforceContrastFromTheme()
49
+ }
50
+ }
51
+
52
+ private inline fun <reified T> invokeWindowUtilKtMethod(
53
+ methodName: String,
54
+ vararg args: Pair<Class<*>, Any?>
55
+ ): T? {
56
+ val windowUtilClassName = "com.facebook.react.views.view.WindowUtilKt"
57
+
58
+ return runCatching {
59
+ val windowUtilKtClass = Class.forName(windowUtilClassName)
60
+ val parameterTypes = args.map { it.first }.toTypedArray()
61
+ val parameterValues = args.map { it.second }.toTypedArray()
62
+ val method = windowUtilKtClass.getDeclaredMethod(methodName, *parameterTypes)
63
+
64
+ method.isAccessible = true
65
+ method.invoke(null, *parameterValues) as? T
66
+ }.onFailure {
67
+ Log.e("EdgeToEdgePackage", "Failed to invoke '$methodName' on $windowUtilClassName", it)
68
+ }.getOrNull()
69
+ }
@@ -15,7 +15,7 @@ public struct ViewDefinitionBuilder<ViewType: UIView> {
15
15
  }
16
16
 
17
17
  /**
18
- Accepts `Events` definition element of `View`.
18
+ Accepts `ViewName` definition element of `View`.
19
19
  */
20
20
  public static func buildExpression(_ element: ViewNameDefinition) -> AnyViewDefinitionElement {
21
21
  return element
@@ -24,6 +24,14 @@ open class BaseExpoAppDelegateSubscriber: UIResponder {
24
24
  @objc(EXAppDelegateSubscriberProtocol)
25
25
  public protocol ExpoAppDelegateSubscriberProtocol: UIApplicationDelegate {
26
26
  @objc optional func customizeRootView(_ rootView: UIView)
27
+
28
+ /**
29
+ Function that is called automatically by the `ExpoAppDelegate` once the subscriber is successfully registered.
30
+ If the subscriber is loaded from the modules provider, it is executed just before the main code of the app,
31
+ thus even before any other `UIApplicationDelegate` function. Use it if your subscriber needs to run some code as early as possible,
32
+ but keep in mind that this affects the application loading time.
33
+ */
34
+ @objc optional func subscriberDidRegister()
27
35
  }
28
36
 
29
37
  /**
@@ -139,7 +139,18 @@ public class ExpoAppDelegateSubscriberManager: NSObject {
139
139
  }
140
140
  #endif
141
141
 
142
- // TODO: - Responding to Environment Changes
142
+ // MARK: - Responding to Environment Changes
143
+
144
+ #if os(iOS) || os(tvOS)
145
+
146
+ @objc
147
+ public static func applicationDidReceiveMemoryWarning(_ application: UIApplication) {
148
+ ExpoAppDelegateSubscriberRepository
149
+ .subscribers
150
+ .forEach { $0.applicationDidReceiveMemoryWarning?(application) }
151
+ }
152
+
153
+ #endif
143
154
 
144
155
  // TODO: - Managing App State Restoration
145
156
 
@@ -32,6 +32,7 @@ public class ExpoAppDelegateSubscriberRepository: NSObject {
32
32
  fatalError("Given app delegate subscriber `\(String(describing: subscriber))` is already registered.")
33
33
  }
34
34
  _subscribers.append(subscriber)
35
+ subscriber.subscriberDidRegister?()
35
36
  }
36
37
 
37
38
  @objc
@@ -15,6 +15,11 @@ protocol AnyEither: AnyArgument {
15
15
  A dynamic either type for the current either type.
16
16
  */
17
17
  static func getDynamicType() -> any AnyDynamicType
18
+
19
+ /**
20
+ The underlying type-erased value.
21
+ */
22
+ var value: Any? { get }
18
23
  }
19
24
 
20
25
  /*
@@ -40,6 +40,23 @@ internal struct DynamicEitherType<EitherType: AnyEither>: AnyDynamicType {
40
40
  throw NeitherTypeException(types)
41
41
  }
42
42
 
43
+ func convertResult<ResultType>(_ result: ResultType, appContext: AppContext) throws -> Any {
44
+ guard let either = result as? EitherType else {
45
+ throw Conversions.CastingException<EitherType>(result)
46
+ }
47
+
48
+ let types = eitherType.dynamicTypes()
49
+
50
+ // Try each type - one should succeed
51
+ for type in types {
52
+ if let converted = try? type.convertResult(either.value, appContext: appContext) {
53
+ return converted
54
+ }
55
+ }
56
+
57
+ throw NeitherTypeException(types)
58
+ }
59
+
43
60
  var description: String {
44
61
  let types = eitherType.dynamicTypes()
45
62
  return "Either<\(types.map(\.description).joined(separator: ", "))>"
@@ -0,0 +1,47 @@
1
+ // Copyright 2025-present 650 Industries. All rights reserved.
2
+
3
+ /**
4
+ Dynamic type for values conforming to `Encodable` protocol.
5
+ Note that currently it can only encode from native to JavaScript values, thus cannot be used for arguments.
6
+ */
7
+ internal struct DynamicEncodableType: AnyDynamicType {
8
+ static let shared = DynamicEncodableType()
9
+
10
+ func wraps<InnerType>(_ type: InnerType.Type) -> Bool {
11
+ return type is Encodable
12
+ }
13
+
14
+ func equals(_ type: any AnyDynamicType) -> Bool {
15
+ // Just mocking it here as we don't really need this function and we rather want to keep it a singleton
16
+ return false
17
+ }
18
+
19
+ func cast<ValueType>(_ value: ValueType, appContext: AppContext) throws -> Any {
20
+ // TODO: Create DynamicDecodableType and reuse it here – that would work perfectly with Codable types
21
+ fatalError("DynamicEncodableType can only cast to JavaScript, not from")
22
+ }
23
+
24
+ func castToJS<ValueType>(_ value: ValueType, appContext: AppContext) throws -> JavaScriptValue {
25
+ if let value = value as? JavaScriptValue {
26
+ return value
27
+ }
28
+ if let value = value as? Encodable {
29
+ let runtime = try appContext.runtime
30
+ let encoder = JSValueEncoder(runtime: runtime)
31
+
32
+ try value.encode(to: encoder)
33
+
34
+ return encoder.value
35
+ }
36
+ throw Conversions.ConversionToJSFailedException((kind: .object, nativeType: ValueType.self))
37
+ }
38
+
39
+ func convertResult<ResultType>(_ result: ResultType, appContext: AppContext) throws -> Any {
40
+ // TODO: We should get rid of this function, but it seems it's still used in some places
41
+ return try castToJS(result, appContext: appContext)
42
+ }
43
+
44
+ var description: String {
45
+ "Encodable"
46
+ }
47
+ }
@@ -7,54 +7,22 @@
7
7
  /**
8
8
  Factory creating an instance of the dynamic type wrapper conforming to `AnyDynamicType`.
9
9
  Depending on the given type, it may return one of `DynamicArrayType`, `DynamicOptionalType`, `DynamicConvertibleType`, etc.
10
- Note that this goes through many type checks, thus it might be a bit more expensive than using generic type constraints,
11
- see the `~` prefix operator below that handles types conforming to `AnyArgument` in a faster way.
10
+ It does some type checks in runtime when the type's conformance/inheritance is unknown for the compiler.
11
+ See the `~` prefix operator overloads that are used for types known for the compiler.
12
+ You can add more type checks for types that don't conform to `AnyArgument`, but are allowed to be used as return types.
13
+ `Void` is a good example as it cannot conform to anything or language protocols that cannot be extended to implement `AnyArgument`.
12
14
  */
13
15
  private func DynamicType<T>(_ type: T.Type) -> AnyDynamicType {
14
- if type is any Numeric.Type {
15
- return DynamicNumberType(numberType: T.self)
16
- }
17
- if type is String.Type {
18
- return DynamicStringType.shared
19
- }
20
- if let ArrayType = T.self as? AnyArray.Type {
21
- return DynamicArrayType(elementType: ArrayType.getElementDynamicType())
22
- }
23
- if let DictionaryType = T.self as? AnyDictionary.Type {
24
- return DynamicDictionaryType(valueType: DictionaryType.getValueDynamicType())
25
- }
26
- if let OptionalType = T.self as? any AnyOptional.Type {
27
- return DynamicOptionalType(wrappedType: OptionalType.getWrappedDynamicType())
28
- }
29
- if let ConvertibleType = T.self as? Convertible.Type {
30
- return DynamicConvertibleType(innerType: ConvertibleType)
31
- }
32
- if let EnumType = T.self as? any Enumerable.Type {
33
- return DynamicEnumType(innerType: EnumType)
34
- }
35
- if let ViewType = T.self as? UIView.Type {
36
- return DynamicViewType(innerType: ViewType)
37
- }
38
- if let SharedObjectType = T.self as? SharedObject.Type {
39
- return DynamicSharedObjectType(innerType: SharedObjectType)
40
- }
41
- if let TypedArrayType = T.self as? AnyTypedArray.Type {
42
- return DynamicTypedArrayType(innerType: TypedArrayType)
43
- }
44
- if T.self is Data.Type {
45
- return DynamicDataType.shared
46
- }
47
- if let JavaScriptValueType = T.self as? any AnyJavaScriptValue.Type {
48
- return DynamicJavaScriptType(innerType: JavaScriptValueType)
16
+ if let AnyArgumentType = T.self as? AnyArgument.Type {
17
+ return AnyArgumentType.getDynamicType()
49
18
  }
50
19
  if T.self == Void.self {
51
20
  return DynamicVoidType.shared
52
21
  }
53
- if let AnyEitherType = T.self as? AnyEither.Type {
54
- return AnyEitherType.getDynamicType()
55
- }
56
- if let AnyValueOrUndefinedType = T.self as? AnyValueOrUndefined.Type {
57
- return AnyValueOrUndefinedType.getDynamicType()
22
+ if T.self is Encodable.Type {
23
+ // There is no dedicated `~` operator overload for encodables to avoid ambiguity
24
+ // when the type is both `AnyArgument` and `Encodable` (e.g. strings, numeric types).
25
+ return DynamicEncodableType.shared
58
26
  }
59
27
  return DynamicRawType(innerType: T.self)
60
28
  }
@@ -0,0 +1,201 @@
1
+ // Copyright 2025-present 650 Industries. All rights reserved.
2
+
3
+ /**
4
+ Encodes `Encodable` objects or values to `JavaScriptValue`. This implementation is incomplete,
5
+ but it supports basic use cases with structs defined by the user and when the default `Encodable` implementation is used.
6
+ */
7
+ internal final class JSValueEncoder: Encoder {
8
+ private let runtime: JavaScriptRuntime
9
+ private let valueHolder = JSValueHolder()
10
+
11
+ /**
12
+ The result of encoding to `JavaScriptValue`. Use this property after running `encode(to:)` on the encodable.
13
+ */
14
+ var value: JavaScriptValue {
15
+ return valueHolder.value
16
+ }
17
+
18
+ /**
19
+ Initializes the encoder with the given runtime in which the value will be created.
20
+ */
21
+ init(runtime: JavaScriptRuntime) {
22
+ self.runtime = runtime
23
+ }
24
+
25
+ // MARK: - Encoder
26
+
27
+ // We don't use `codingPath` and `userInfo`, but they are required by the protocol.
28
+ let codingPath: [any CodingKey] = []
29
+ let userInfo: [CodingUserInfoKey: Any] = [:]
30
+
31
+ /**
32
+ Returns an encoding container appropriate for holding multiple values keyed by the given key type.
33
+ */
34
+ func container<Key>(keyedBy type: Key.Type) -> KeyedEncodingContainer<Key> where Key: CodingKey {
35
+ let container = JSObjectEncodingContainer<Key>(to: valueHolder, runtime: runtime)
36
+ return KeyedEncodingContainer(container)
37
+ }
38
+
39
+ /**
40
+ Returns an encoding container appropriate for holding multiple unkeyed values.
41
+ */
42
+ func unkeyedContainer() -> any UnkeyedEncodingContainer {
43
+ return JSArrayEncodingContainer(to: valueHolder, runtime: runtime)
44
+ }
45
+
46
+ /**
47
+ Returns an encoding container appropriate for holding a single primitive value, including optionals.
48
+ */
49
+ func singleValueContainer() -> any SingleValueEncodingContainer {
50
+ return JSValueEncodingContainer(to: valueHolder, runtime: runtime)
51
+ }
52
+ }
53
+
54
+ /**
55
+ An object that holds a JS value that could be overriden by the encoding container.
56
+ */
57
+ private final class JSValueHolder {
58
+ var value: JavaScriptValue = .undefined
59
+ }
60
+
61
+ /**
62
+ Single value container used to encode primitive values, including optionals.
63
+ */
64
+ private struct JSValueEncodingContainer: SingleValueEncodingContainer {
65
+ private weak var runtime: JavaScriptRuntime?
66
+ private let valueHolder: JSValueHolder
67
+
68
+ init(to valueHolder: JSValueHolder, runtime: JavaScriptRuntime?) {
69
+ self.runtime = runtime
70
+ self.valueHolder = valueHolder
71
+ }
72
+
73
+ // MARK: - SingleValueEncodingContainer
74
+
75
+ // Unused, but required by the protocol.
76
+ let codingPath: [any CodingKey] = []
77
+
78
+ mutating func encodeNil() throws {
79
+ self.valueHolder.value = .null
80
+ }
81
+
82
+ mutating func encode<ValueType: Encodable>(_ value: ValueType) throws {
83
+ guard let runtime else {
84
+ // Do nothing when the runtime is already deallocated
85
+ return
86
+ }
87
+ let jsValue = JavaScriptValue.from(value, runtime: runtime)
88
+
89
+ // If the given value couldn't be converted to JavaScriptValue, try to encode it farther.
90
+ // It might be the case when the default implementation of `Encodable` has chosen the single value container
91
+ // for an optional type that should rather use keyed or unkeyed container when unwrapped.
92
+ if jsValue.isUndefined() {
93
+ let encoder = JSValueEncoder(runtime: runtime)
94
+ try value.encode(to: encoder)
95
+ self.valueHolder.value = encoder.value
96
+ return
97
+ }
98
+ self.valueHolder.value = jsValue
99
+ }
100
+ }
101
+
102
+ /**
103
+ Keyed container that encodes to a JavaScript object.
104
+ */
105
+ private struct JSObjectEncodingContainer<Key: CodingKey>: KeyedEncodingContainerProtocol {
106
+ private weak var runtime: JavaScriptRuntime?
107
+ private let valueHolder: JSValueHolder
108
+ private var object: JavaScriptObject
109
+
110
+ init(to valueHolder: JSValueHolder, runtime: JavaScriptRuntime) {
111
+ let object = runtime.createObject()
112
+ valueHolder.value = JavaScriptValue.from(object, runtime: runtime)
113
+
114
+ self.runtime = runtime
115
+ self.object = object
116
+ self.valueHolder = valueHolder
117
+ }
118
+
119
+ // MARK: - KeyedEncodingContainerProtocol
120
+
121
+ // Unused, but required by the protocol.
122
+ var codingPath: [any CodingKey] = []
123
+
124
+ mutating func encodeNil(forKey key: Key) throws {
125
+ object.setProperty(key.stringValue, value: JavaScriptValue.null)
126
+ }
127
+
128
+ mutating func encode<ValueType: Encodable>(_ value: ValueType, forKey key: Key) throws {
129
+ guard let runtime else {
130
+ // Do nothing when the runtime is already deallocated
131
+ return
132
+ }
133
+ let encoder = JSValueEncoder(runtime: runtime)
134
+ try value.encode(to: encoder)
135
+ object.setProperty(key.stringValue, value: encoder.value)
136
+ }
137
+
138
+ mutating func nestedContainer<NestedKey: CodingKey>(keyedBy keyType: NestedKey.Type, forKey key: Key) -> KeyedEncodingContainer<NestedKey> {
139
+ fatalError("JSValueEncoder does not support nested containers")
140
+ }
141
+
142
+ mutating func nestedUnkeyedContainer(forKey key: Key) -> any UnkeyedEncodingContainer {
143
+ fatalError("JSValueEncoder does not support nested containers")
144
+ }
145
+
146
+ mutating func superEncoder() -> any Encoder {
147
+ fatalError("superEncoder() is not implemented in JSValueEncoder")
148
+ }
149
+
150
+ mutating func superEncoder(forKey key: Key) -> any Encoder {
151
+ return self.superEncoder()
152
+ }
153
+ }
154
+
155
+ /**
156
+ Unkeyed container that encodes values to a JavaScript array.
157
+ */
158
+ private struct JSArrayEncodingContainer: UnkeyedEncodingContainer {
159
+ private weak var runtime: JavaScriptRuntime?
160
+ private let valueHolder: JSValueHolder
161
+ private var items: [JavaScriptValue] = []
162
+
163
+ init(to valueHolder: JSValueHolder, runtime: JavaScriptRuntime) {
164
+ self.runtime = runtime
165
+ self.valueHolder = valueHolder
166
+ }
167
+
168
+ // MARK: - UnkeyedEncodingContainer
169
+
170
+ // Unused, but required by the protocol.
171
+ var codingPath: [any CodingKey] = []
172
+ var count: Int = 0
173
+
174
+ mutating func encodeNil() throws {
175
+ items.append(.null)
176
+ }
177
+
178
+ mutating func encode<ValueType: Encodable>(_ value: ValueType) throws {
179
+ guard let runtime else {
180
+ // Do nothing when the runtime is already deallocated
181
+ return
182
+ }
183
+ let encoder = JSValueEncoder(runtime: runtime)
184
+ try value.encode(to: encoder)
185
+
186
+ items.append(encoder.value)
187
+ valueHolder.value = .from(items, runtime: runtime)
188
+ }
189
+
190
+ mutating func nestedContainer<NestedKey>(keyedBy keyType: NestedKey.Type) -> KeyedEncodingContainer<NestedKey> where NestedKey : CodingKey {
191
+ fatalError("JSValueEncoder does not support nested containers")
192
+ }
193
+
194
+ mutating func nestedUnkeyedContainer() -> any UnkeyedEncodingContainer {
195
+ fatalError("JSValueEncoder does not support nested containers")
196
+ }
197
+
198
+ mutating func superEncoder() -> any Encoder {
199
+ fatalError("superEncoder() is not implemented in JSValueEncoder")
200
+ }
201
+ }
@@ -68,12 +68,25 @@ public extension Record {
68
68
  }
69
69
  }
70
70
 
71
+ /**
72
+ Recursively collects all children from a Mirror, including inherited properties from superclasses.
73
+ */
74
+ internal func allMirrorChildren(_ mirror: Mirror) -> [Mirror.Child] {
75
+ var children: [Mirror.Child] = Array(mirror.children)
76
+ if let superclassMirror = mirror.superclassMirror {
77
+ children.append(contentsOf: allMirrorChildren(superclassMirror))
78
+ }
79
+ return children
80
+ }
81
+
71
82
  /**
72
83
  Returns an array of fields found in record's mirror. If the field is missing the `key`,
73
84
  it gets assigned to the property label, so after all it's safe to enforce unwrapping it (using `key!`).
85
+ This function now supports inheritance by recursively traversing the superclass hierarchy.
74
86
  */
75
87
  internal func fieldsOf(_ record: Record) -> [AnyFieldInternal] {
76
- return Mirror(reflecting: record).children.compactMap { (label: String?, value: Any) in
88
+ let mirror = Mirror(reflecting: record)
89
+ return allMirrorChildren(mirror).compactMap { (label: String?, value: Any) in
77
90
  guard var field = value as? AnyFieldInternal, let key = field.key ?? convertLabelToKey(label) else {
78
91
  return nil
79
92
  }
@@ -113,7 +113,7 @@ extension ExpoSwiftUI {
113
113
  }
114
114
 
115
115
  public override func getSupportedPropNames() -> [String] {
116
- return dummyPropsMirror.children.compactMap { (label: String?, value: Any) in
116
+ return allMirrorChildren(dummyPropsMirror).compactMap { (label: String?, value: Any) in
117
117
  guard let field = value as? AnyFieldInternal else {
118
118
  return nil
119
119
  }
@@ -122,14 +122,13 @@ extension ExpoSwiftUI {
122
122
  }
123
123
 
124
124
  public override func getSupportedEventNames() -> [String] {
125
- let builtInEventNames = [GLOBAL_EVENT_NAME]
126
- let propEventNames: [String] = dummyPropsMirror.children.compactMap { (label: String?, value: Any) in
125
+ let propEventNames: [String] = allMirrorChildren(dummyPropsMirror).compactMap { (label: String?, value: Any) in
127
126
  guard let event = value as? EventDispatcher else {
128
127
  return nil
129
128
  }
130
129
  return event.customName ?? convertLabelToKey(label)
131
130
  }
132
- return builtInEventNames + propEventNames
131
+ return propEventNames
133
132
  }
134
133
  }
135
134
  }
@@ -10,6 +10,13 @@ extension ExpoSwiftUI {
10
10
  return elements
11
11
  }
12
12
 
13
+ /**
14
+ Accepts `ViewName` definition element of `View`.
15
+ */
16
+ public static func buildExpression(_ element: ViewNameDefinition) -> AnyViewDefinitionElement {
17
+ return element
18
+ }
19
+
13
20
  /**
14
21
  Accepts functions as a view definition elements.
15
22
  */
@@ -15,7 +15,7 @@ extension ExpoSwiftUI {
15
15
  /**
16
16
  An array of views passed by React as children.
17
17
  */
18
- @Field public var children: [any AnyChild]?
18
+ public var children: [any AnyChild]?
19
19
 
20
20
  public internal(set) weak var appContext: AppContext?
21
21
 
@@ -37,7 +37,8 @@ extension ExpoSwiftUI {
37
37
  dispatcher(GLOBAL_EVENT_NAME, payload)
38
38
  }
39
39
 
40
- Mirror(reflecting: self).children.forEach { (label: String?, value: Any) in
40
+ let mirror = Mirror(reflecting: self)
41
+ allMirrorChildren(mirror).forEach { (label: String?, value: Any) in
41
42
  guard let event = value as? EventDispatcher else {
42
43
  return
43
44
  }
@@ -31,7 +31,8 @@ jsi::String convertNSStringToJSIString(jsi::Runtime &runtime, NSString *value)
31
31
  #if !TARGET_OS_OSX
32
32
  const uint8_t *utf8 = (const uint8_t *)[value UTF8String];
33
33
  const size_t length = [value length];
34
- if (expo::isAllASCIIAndNotNull(utf8, utf8 + length)) {
34
+
35
+ if (utf8 != nullptr && expo::isAllASCIIAndNotNull(utf8, utf8 + length)) {
35
36
  return jsi::String::createFromAscii(runtime, (const char *)utf8, length);
36
37
  }
37
38
  // Using cStringUsingEncoding should be fine as long as we provide the length.
@@ -60,6 +60,7 @@ NS_SWIFT_NAME(JavaScriptValue)
60
60
  #pragma mark - Statics
61
61
 
62
62
  @property (class, nonatomic, assign, readonly, nonnull) EXJavaScriptValue *undefined;
63
+ @property (class, nonatomic, assign, readonly, nonnull) EXJavaScriptValue *null;
63
64
 
64
65
  + (nonnull EXJavaScriptValue *)number:(double)value;
65
66
 
@@ -170,10 +170,14 @@
170
170
 
171
171
  + (nonnull EXJavaScriptValue *)undefined
172
172
  {
173
- auto undefined = std::make_shared<jsi::Value>();
174
173
  return [[EXJavaScriptValue alloc] initWithRuntime:nil value:jsi::Value::undefined()];
175
174
  }
176
175
 
176
+ + (nonnull EXJavaScriptValue *)null
177
+ {
178
+ return [[EXJavaScriptValue alloc] initWithRuntime:nil value:jsi::Value::null()];
179
+ }
180
+
177
181
  + (nonnull EXJavaScriptValue *)number:(double)value
178
182
  {
179
183
  return [[EXJavaScriptValue alloc] initWithRuntime:nil value:jsi::Value(value)];
@@ -405,5 +405,75 @@ final class DynamicTypeSpec: ExpoSpec {
405
405
  }
406
406
  }
407
407
  }
408
+
409
+ // MARK: - DynamicEncodableType
410
+
411
+ describe("DynamicEncodableType") {
412
+ struct TestEncodable: Encodable {
413
+ let string: String
414
+ let number: Int
415
+ let bool: Bool
416
+ var object: TestEncodableChild? = nil
417
+ var array: [Int]? = nil
418
+ }
419
+ struct TestEncodableChild: Encodable {
420
+ let name: String
421
+ }
422
+
423
+ it("is created") {
424
+ expect(~TestEncodable.self).to(beAKindOf(DynamicEncodableType.self))
425
+ }
426
+ it("casts to JS object") {
427
+ let encodable = TestEncodable(string: "test", number: -5, bool: true)
428
+ let result = try (~TestEncodable.self).castToJS(encodable, appContext: appContext)
429
+
430
+ expect(result.kind) == .object
431
+ }
432
+ it("has proper property names") {
433
+ let encodable = TestEncodable(string: "test", number: -5, bool: true)
434
+ let result = try (~TestEncodable.self).castToJS(encodable, appContext: appContext)
435
+ let propertyNames = result.getObject().getPropertyNames()
436
+
437
+ expect(propertyNames.count) == 3
438
+ expect(propertyNames).to(contain(["string", "number", "bool"]))
439
+ }
440
+ it("has correct values") {
441
+ let encodable = TestEncodable(string: "test", number: -5, bool: true)
442
+ let result = try (~TestEncodable.self).castToJS(encodable, appContext: appContext)
443
+ let object = result.getObject()
444
+
445
+ expect(try object.getProperty("string").asString()) == encodable.string
446
+ expect(try object.getProperty("number").asInt()) == encodable.number
447
+ expect(try object.getProperty("bool").asBool()) == encodable.bool
448
+ expect(object.getProperty("object").isUndefined()) == true
449
+ expect(object.getProperty("array").isUndefined()) == true
450
+ }
451
+ it("casts nested objects") {
452
+ let encodable = TestEncodable(
453
+ string: "test",
454
+ number: -5,
455
+ bool: true,
456
+ object: TestEncodableChild(name: "expo")
457
+ )
458
+ let result = try (~TestEncodable.self).castToJS(encodable, appContext: appContext)
459
+ let nestedValue = result.getObject().getProperty("object")
460
+
461
+ expect(nestedValue.kind) == .object
462
+ expect(try nestedValue.getObject().getProperty("name").asString()) == encodable.object?.name
463
+ }
464
+ it("casts arrays") {
465
+ let encodable = TestEncodable(
466
+ string: "test",
467
+ number: -5,
468
+ bool: true,
469
+ array: [1, 2, 3]
470
+ )
471
+ let result = try (~TestEncodable.self).castToJS(encodable, appContext: appContext)
472
+ let array = result.getObject().getProperty("array").getArray()
473
+
474
+ expect(array.count) == encodable.array?.count
475
+ expect(array.map({ $0.getInt() })) == encodable.array
476
+ }
477
+ }
408
478
  }
409
479
  }
@@ -252,6 +252,11 @@ class FunctionSpec: ExpoSpec {
252
252
  @Field var url: URL = defaultURL
253
253
  }
254
254
 
255
+ struct TestEncodable: Encodable {
256
+ let name: String
257
+ let version: Int
258
+ }
259
+
255
260
  afterEach {
256
261
  try runtime.eval("globalThis.result = undefined")
257
262
  }
@@ -309,6 +314,10 @@ class FunctionSpec: ExpoSpec {
309
314
  return "\(f?.property ?? "no value")"
310
315
  }
311
316
 
317
+ Function("returnEncodable") {
318
+ return TestEncodable(name: "Expo SDK", version: 55)
319
+ }
320
+
312
321
  Function("withSharedObject") {
313
322
  return SharedString("Test")
314
323
  }
@@ -325,6 +334,10 @@ class FunctionSpec: ExpoSpec {
325
334
  p.resolve(SharedString("Test with Promise"))
326
335
  }
327
336
 
337
+ Function("withEither") { (either: Either<Bool, String>) in
338
+ return either
339
+ }
340
+
328
341
  AsyncFunction("withURLAsync") {
329
342
  return TestURLRecord.defaultURL
330
343
  }
@@ -388,6 +401,14 @@ class FunctionSpec: ExpoSpec {
388
401
  expect(try runtime.eval("expo.modules.TestModule.withOptionalRecord({property: \"123\"})").asString()) == "123"
389
402
  }
390
403
 
404
+ it("returns encodable struct") {
405
+ let result = try runtime.eval("expo.modules.TestModule.returnEncodable()")
406
+ expect(result.kind) == .object
407
+ expect(result.getObject().getPropertyNames()).to(contain(["name", "version"]))
408
+ expect(try result.getObject().getProperty("name").asString()) == "Expo SDK"
409
+ expect(try result.getObject().getProperty("version").asInt()) == 55
410
+ }
411
+
391
412
  it("returns URL (sync)") {
392
413
  let result = try runtime.eval("globalThis.result = expo.modules.TestModule.withURL()")
393
414
  expect(result.kind) == .string
@@ -487,7 +508,17 @@ class FunctionSpec: ExpoSpec {
487
508
  expect(result.kind) == .string
488
509
  expect(result.getString()) == "Test with Promise"
489
510
  }
490
-
511
+
512
+ it("accepts and returns Either value") {
513
+ let stringResult = try runtime.eval("expo.modules.TestModule.withEither('test string')")
514
+ expect(stringResult.kind) == .string
515
+ expect(stringResult.getString()) == "test string"
516
+
517
+ let boolResult = try runtime.eval("expo.modules.TestModule.withEither(true)")
518
+ expect(boolResult.kind) == .bool
519
+ expect(boolResult.getBool()) == true
520
+ }
521
+
491
522
  // For async tests, this is a safe way to repeatedly evaluate JS
492
523
  // and catch both Swift and ObjC exceptions
493
524
  func safeBoolEval(_ js: String) -> Bool {
@@ -45,6 +45,31 @@ class RecordSpec: ExpoSpec {
45
45
  expect(record.toDictionary()["b"] as? Int).to(equal(dict["b"]! as! Int))
46
46
  }
47
47
 
48
+ it("works back and forth with Either") {
49
+ struct TestRecord: Record {
50
+ @Field var stringValue: Either<Bool, String>?
51
+ @Field var boolValue: Either<Bool, String>?
52
+ @Field var intValue: Either<Int, String>?
53
+ @Field var nilValue: Either<Int, String>?
54
+ }
55
+ let dict: [String: Any] = [
56
+ "stringValue": "custom",
57
+ "boolValue": true,
58
+ "intValue": 42,
59
+ ]
60
+ let record = try TestRecord(from: dict, appContext: appContext)
61
+ expect(record.stringValue?.get() as String?).to(equal("custom"))
62
+ expect(record.boolValue?.get() as Bool?).to(equal(true))
63
+ expect(record.intValue?.get() as Int?).to(equal(42))
64
+ expect(record.nilValue).to(beNil())
65
+
66
+ let asDict = record.toDictionary(appContext: appContext)
67
+ expect(asDict["stringValue"] as? String).to(equal("custom"))
68
+ expect(asDict["boolValue"] as? Bool).to(equal(true))
69
+ expect(asDict["intValue"] as? Int).to(equal(42))
70
+ expect(asDict["nilValue"] as? Int).to(beNil())
71
+ }
72
+
48
73
  it("works back and forth with a keyed field") {
49
74
  struct TestRecord: Record {
50
75
  @Field("key") var a: String?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-modules-core",
3
- "version": "3.0.22",
3
+ "version": "3.0.24",
4
4
  "description": "The core of Expo Modules architecture",
5
5
  "main": "src/index.ts",
6
6
  "types": "build/index.d.ts",
@@ -65,5 +65,5 @@
65
65
  "@testing-library/react-native": "^13.2.0",
66
66
  "expo-module-scripts": "^5.0.7"
67
67
  },
68
- "gitHead": "ea56136a4420322f46d00e4b1549595d8f85150e"
68
+ "gitHead": "1bba12a43e14a442f2cf1c73fe21968e0ef097c1"
69
69
  }