expo-modules-core 1.2.6 → 1.3.0
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 +33 -4
- package/ExpoModulesCore.podspec +1 -0
- package/README.md +1 -1
- package/android/ExpoModulesCorePlugin.gradle +16 -0
- package/android/build.gradle +3 -2
- package/android/src/main/cpp/Exceptions.cpp +8 -0
- package/android/src/main/cpp/Exceptions.h +11 -0
- package/android/src/main/cpp/ExpoModulesHostObject.cpp +22 -5
- package/android/src/main/cpp/ExpoModulesHostObject.h +5 -0
- package/android/src/main/cpp/JNIInjector.cpp +2 -0
- package/android/src/main/cpp/JSIInteropModuleRegistry.cpp +25 -1
- package/android/src/main/cpp/JSIInteropModuleRegistry.h +14 -0
- package/android/src/main/cpp/JSIObjectWrapper.h +15 -4
- package/android/src/main/cpp/JSITypeConverter.h +3 -2
- package/android/src/main/cpp/JavaReferencesCache.cpp +2 -0
- package/android/src/main/cpp/JavaScriptFunction.cpp +56 -0
- package/android/src/main/cpp/JavaScriptFunction.h +54 -0
- package/android/src/main/cpp/JavaScriptModuleObject.cpp +225 -105
- package/android/src/main/cpp/JavaScriptModuleObject.h +67 -34
- package/android/src/main/cpp/JavaScriptObject.cpp +55 -1
- package/android/src/main/cpp/JavaScriptObject.h +17 -13
- package/android/src/main/cpp/JavaScriptRuntime.cpp +12 -3
- package/android/src/main/cpp/JavaScriptRuntime.h +9 -1
- package/android/src/main/cpp/JavaScriptValue.cpp +9 -0
- package/android/src/main/cpp/JavaScriptValue.h +4 -0
- package/android/src/main/cpp/MethodMetadata.cpp +66 -87
- package/android/src/main/cpp/MethodMetadata.h +18 -16
- package/android/src/main/cpp/ObjectDeallocator.h +25 -0
- package/android/src/main/cpp/WeakRuntimeHolder.cpp +7 -0
- package/android/src/main/cpp/WeakRuntimeHolder.h +4 -0
- package/android/src/main/cpp/types/CppType.h +4 -1
- package/android/src/main/cpp/types/FrontendConverter.cpp +58 -0
- package/android/src/main/cpp/types/FrontendConverter.h +45 -0
- package/android/src/main/cpp/types/FrontendConverterProvider.cpp +3 -0
- package/android/src/main/cpp/types/JNIToJSIConverter.cpp +88 -0
- package/android/src/main/cpp/types/JNIToJSIConverter.h +22 -0
- package/android/src/main/java/com/facebook/react/uimanager/ReactStylesDiffMapHelper.kt +10 -0
- package/android/src/main/java/expo/modules/kotlin/AppContext.kt +18 -25
- package/android/src/main/java/expo/modules/kotlin/FilteredIterator.kt +37 -0
- package/android/src/main/java/expo/modules/kotlin/KotlinInteropModuleRegistry.kt +1 -1
- package/android/src/main/java/expo/modules/kotlin/ModuleHolder.kt +34 -21
- package/android/src/main/java/expo/modules/kotlin/ModuleRegistry.kt +13 -3
- package/android/src/main/java/expo/modules/kotlin/Utils.kt +21 -0
- package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultCaller.kt +21 -1
- package/android/src/main/java/expo/modules/kotlin/classcomponent/ClassComponentBuilder.kt +112 -0
- package/android/src/main/java/expo/modules/kotlin/classcomponent/ClassDefinitionData.kt +10 -0
- package/android/src/main/java/expo/modules/kotlin/exception/CodedException.kt +21 -0
- package/android/src/main/java/expo/modules/kotlin/exception/CommonExceptions.kt +15 -0
- package/android/src/main/java/expo/modules/kotlin/functions/AnyFunction.kt +17 -4
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunction.kt +38 -8
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionComponent.kt +3 -2
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionWithPromiseComponent.kt +3 -2
- package/android/src/main/java/expo/modules/kotlin/functions/SuspendFunctionComponent.kt +1 -0
- package/android/src/main/java/expo/modules/kotlin/functions/SyncFunctionComponent.kt +18 -11
- package/android/src/main/java/expo/modules/kotlin/jni/CppType.kt +4 -1
- package/android/src/main/java/expo/modules/kotlin/jni/JNIDeallocator.kt +73 -0
- package/android/src/main/java/expo/modules/kotlin/jni/JSIInteropModuleRegistry.kt +28 -2
- package/android/src/main/java/expo/modules/kotlin/jni/JavaCallback.kt +8 -1
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptFunction.kt +48 -0
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptModuleObject.kt +40 -3
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptObject.kt +23 -3
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptValue.kt +26 -1
- package/android/src/main/java/expo/modules/kotlin/modules/Module.kt +0 -11
- package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +26 -16
- package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionData.kt +3 -1
- package/android/src/main/java/expo/modules/kotlin/sharedobjects/SharedObject.kt +12 -0
- package/android/src/main/java/expo/modules/kotlin/sharedobjects/SharedObjectRegistry.kt +62 -0
- package/android/src/main/java/expo/modules/kotlin/sharedobjects/SharedObjectTypeConverter.kt +27 -0
- package/android/src/main/java/expo/modules/kotlin/types/AnyType.kt +2 -1
- package/android/src/main/java/expo/modules/kotlin/types/EitherTypeConverter.kt +7 -6
- package/android/src/main/java/expo/modules/kotlin/types/JavaScriptFunctionTypeConverter.kt +22 -0
- package/android/src/main/java/expo/modules/kotlin/types/TypeConverter.kt +30 -24
- package/android/src/main/java/expo/modules/kotlin/types/TypeConverterProvider.kt +45 -1
- package/android/src/main/java/expo/modules/kotlin/types/TypedArrayTypeConverter.kt +3 -2
- package/android/src/main/java/expo/modules/kotlin/views/AnyViewProp.kt +3 -1
- package/android/src/main/java/expo/modules/kotlin/views/ConcreteViewProp.kt +3 -3
- package/android/src/main/java/expo/modules/kotlin/views/FilteredReadableMap.kt +53 -0
- package/android/src/main/java/expo/modules/kotlin/views/GroupViewManagerWrapper.kt +25 -5
- package/android/src/main/java/expo/modules/kotlin/views/SimpleViewManagerWrapper.kt +25 -5
- package/android/src/main/java/expo/modules/kotlin/views/ViewDefinitionBuilder.kt +161 -10
- package/android/src/main/java/expo/modules/kotlin/views/ViewGroupDefinitionBuilder.kt +0 -67
- package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinition.kt +7 -8
- package/android/src/main/java/expo/modules/kotlin/views/ViewManagerWrapperDelegate.kt +40 -3
- package/android/src/main/java/expo/modules/kotlin/views/ViewTypeConverter.kt +44 -0
- package/android-annotation/build.gradle +45 -0
- package/android-annotation/src/main/java/expo/modules/annotation/Config.kt +7 -0
- package/android-annotation/src/main/java/expo/modules/annotation/ConverterBinder.kt +7 -0
- package/android-annotation-processor/build.gradle +51 -0
- package/android-annotation-processor/src/main/java/expo/modules/annotationprocessor/ExpoSymbolProcessor.kt +175 -0
- package/android-annotation-processor/src/main/java/expo/modules/annotationprocessor/ExpoSymbolProcessorProvider.kt +10 -0
- package/android-annotation-processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider +1 -0
- package/build/NativeViewManagerAdapter.native.d.ts.map +1 -1
- package/build/NativeViewManagerAdapter.native.js +36 -23
- package/build/NativeViewManagerAdapter.native.js.map +1 -1
- package/build/requireNativeModule.js +2 -2
- package/build/requireNativeModule.js.map +1 -1
- package/common/cpp/fabric/ExpoViewProps.cpp +18 -3
- package/common/cpp/fabric/ExpoViewProps.h +4 -1
- package/ios/Fabric/ExpoFabricView.swift +10 -10
- package/ios/Fabric/ExpoFabricViewObjC.h +2 -0
- package/ios/Fabric/ExpoFabricViewObjC.mm +17 -2
- package/ios/JSI/EXJSIInstaller.mm +1 -1
- package/ios/JSI/EXJSIUtils.h +5 -0
- package/ios/JSI/EXJSIUtils.mm +17 -0
- package/ios/JSI/EXJavaScriptRuntime.h +5 -0
- package/ios/JSI/EXJavaScriptRuntime.mm +6 -0
- package/ios/JSI/EXJavaScriptValue.h +2 -0
- package/ios/JSI/EXJavaScriptValue.mm +8 -0
- package/ios/JSI/EXJavaScriptWeakObject.mm +29 -8
- package/ios/JSI/EXRawJavaScriptFunction.h +24 -0
- package/ios/JSI/EXRawJavaScriptFunction.mm +52 -0
- package/ios/JSI/ExpoModulesHostObject.mm +1 -1
- package/ios/JSI/JavaScriptValue.swift +28 -1
- package/ios/ModuleRegistry/EXModuleRegistry.h +0 -4
- package/ios/ModuleRegistry/EXModuleRegistry.m +0 -23
- package/ios/ModuleRegistryAdapter/EXModuleRegistryAdapter.m +0 -16
- package/ios/ModuleRegistryProvider/EXModuleRegistryProvider.m +0 -6
- package/ios/NativeModulesProxy/EXNativeModulesProxy.mm +1 -31
- package/ios/Swift/AppContext.swift +46 -6
- package/ios/Swift/Arguments/Convertible.swift +3 -3
- package/ios/Swift/Arguments/Convertibles.swift +5 -5
- package/ios/Swift/Classes/ClassComponent.swift +18 -12
- package/ios/Swift/Classes/ClassRegistry.swift +31 -0
- package/ios/Swift/Conversions.swift +19 -3
- package/ios/Swift/Convertibles/Convertibles+Color.swift +3 -3
- package/ios/Swift/Convertibles/Either.swift +6 -4
- package/ios/Swift/DynamicTypes/AnyDynamicType.swift +18 -2
- package/ios/Swift/DynamicTypes/DynamicArrayType.swift +3 -3
- package/ios/Swift/DynamicTypes/DynamicConvertibleType.swift +2 -2
- package/ios/Swift/DynamicTypes/DynamicEnumType.swift +1 -1
- package/ios/Swift/DynamicTypes/DynamicJavaScriptType.swift +27 -0
- package/ios/Swift/DynamicTypes/DynamicOptionalType.swift +9 -2
- package/ios/Swift/DynamicTypes/DynamicRawType.swift +1 -1
- package/ios/Swift/DynamicTypes/DynamicSharedObjectType.swift +16 -2
- package/ios/Swift/DynamicTypes/DynamicType.swift +6 -0
- package/ios/Swift/DynamicTypes/DynamicTypedArrayType.swift +15 -4
- package/ios/Swift/DynamicTypes/DynamicViewType.swift +68 -0
- package/ios/Swift/ExpoBridgeModule.swift +1 -1
- package/ios/Swift/Functions/AnyFunction.swift +5 -4
- package/ios/Swift/Functions/AsyncFunctionComponent.swift +22 -19
- package/ios/Swift/Functions/ConcurrentFunctionDefinition.swift +29 -13
- package/ios/Swift/Functions/SyncFunctionComponent.swift +26 -15
- package/ios/Swift/JavaScriptFunction.swift +68 -0
- package/ios/Swift/JavaScriptUtils.swift +57 -18
- package/ios/Swift/ModuleHolder.swift +22 -10
- package/ios/Swift/Modules/ModuleDefinition.swift +8 -2
- package/ios/Swift/Objects/JavaScriptObjectBuilder.swift +8 -8
- package/ios/Swift/Objects/ObjectDefinition.swift +17 -15
- package/ios/Swift/Objects/PropertyComponent.swift +23 -17
- package/ios/Swift/Records/AnyField.swift +1 -1
- package/ios/Swift/Records/Field.swift +2 -2
- package/ios/Swift/Records/Record.swift +5 -5
- package/ios/Swift/SharedObjects/SharedObjectRegistry.swift +4 -0
- package/ios/Swift/Views/AnyViewProp.swift +1 -1
- package/ios/Swift/Views/ComponentData.swift +37 -2
- package/ios/Swift/Views/ConcreteViewProp.swift +2 -2
- package/ios/Swift/Views/ViewDefinition.swift +39 -0
- package/ios/Swift/Views/ViewModuleWrapper.swift +0 -29
- package/ios/Tests/ClassComponentSpec.swift +39 -27
- package/ios/Tests/ConvertiblesSpec.swift +75 -49
- package/ios/Tests/DynamicTypeSpec.swift +29 -27
- package/ios/Tests/EitherSpec.swift +9 -7
- package/ios/Tests/ExpoModulesSpec.swift +13 -13
- package/ios/Tests/FunctionSpec.swift +38 -22
- package/ios/Tests/JavaScriptRuntimeSpec.swift +4 -0
- package/ios/Tests/PropertyComponentSpec.swift +33 -30
- package/ios/Tests/RecordSpec.swift +7 -5
- package/ios/Tests/SharedObjectRegistrySpec.swift +12 -12
- package/ios/Tests/TypedArraysSpec.swift +1 -1
- package/ios/Tests/ViewDefinitionSpec.swift +4 -2
- package/package.json +2 -2
- package/src/NativeViewManagerAdapter.native.tsx +33 -29
- package/src/requireNativeModule.ts +2 -2
- package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinitionBuilder.kt +0 -132
- package/ios/EXViewManager.h +0 -21
- package/ios/EXViewManager.m +0 -128
- package/ios/ModuleRegistryAdapter/EXViewManagerAdapterClassesRegistry.h +0 -17
- package/ios/ModuleRegistryAdapter/EXViewManagerAdapterClassesRegistry.m +0 -67
- package/ios/ViewManagerAdapter/EXViewManagerAdapter.h +0 -17
- package/ios/ViewManagerAdapter/EXViewManagerAdapter.m +0 -45
|
@@ -15,7 +15,7 @@ public protocol Record: Convertible {
|
|
|
15
15
|
/**
|
|
16
16
|
Initializes a record from given dictionary. Only members wrapped by `@Field` will be set in the object.
|
|
17
17
|
*/
|
|
18
|
-
init(from: Dict) throws
|
|
18
|
+
init(from: Dict, appContext: AppContext) throws
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
Converts the record back to the dictionary. Only members wrapped by `@Field` will be set in the dictionary.
|
|
@@ -27,14 +27,14 @@ public protocol Record: Convertible {
|
|
|
27
27
|
Provides the default implementation of `Record` protocol.
|
|
28
28
|
*/
|
|
29
29
|
public extension Record {
|
|
30
|
-
static func convert(from value: Any
|
|
30
|
+
static func convert(from value: Any?, appContext: AppContext) throws -> Self {
|
|
31
31
|
if let value = value as? Dict {
|
|
32
|
-
return try Self(from: value)
|
|
32
|
+
return try Self(from: value, appContext: appContext)
|
|
33
33
|
}
|
|
34
34
|
throw Conversions.ConvertingException<Self>(value)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
init(from dict: Dict) throws {
|
|
37
|
+
init(from dict: Dict, appContext: AppContext) throws {
|
|
38
38
|
self.init()
|
|
39
39
|
|
|
40
40
|
let dictKeys = dict.keys
|
|
@@ -45,7 +45,7 @@ public extension Record {
|
|
|
45
45
|
return
|
|
46
46
|
}
|
|
47
47
|
if dictKeys.contains(key) || field.isRequired {
|
|
48
|
-
try field.set(dict[key])
|
|
48
|
+
try field.set(dict[key], appContext: appContext)
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -43,6 +43,37 @@ public final class ComponentData: RCTComponentData {
|
|
|
43
43
|
return super.createPropBlock(propName, isShadowView: isShadowView)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
public override func setProps(_ props: [String: Any], forView view: RCTComponent) {
|
|
47
|
+
guard let view = view as? UIView else {
|
|
48
|
+
log.warn("Given view is not an UIView")
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
guard let viewManager = moduleHolder?.viewManager else {
|
|
52
|
+
log.warn("View manager '\(self.name)' not found")
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
guard let appContext = moduleHolder?.appContext else {
|
|
56
|
+
log.warn("App context has been lost")
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
let propsDict = viewManager.propsDict()
|
|
60
|
+
var remainingProps = props
|
|
61
|
+
|
|
62
|
+
for (key, prop) in propsDict {
|
|
63
|
+
let newValue = props[key] as Any
|
|
64
|
+
|
|
65
|
+
// TODO: @tsapeta: Figure out better way to rethrow errors from here.
|
|
66
|
+
try? prop.set(value: Conversions.fromNSObject(newValue), onView: view, appContext: appContext)
|
|
67
|
+
|
|
68
|
+
remainingProps.removeValue(forKey: key)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Let the base class `RCTComponentData` handle all remaining props.
|
|
72
|
+
super.setProps(remainingProps, forView: view)
|
|
73
|
+
|
|
74
|
+
viewManager.callLifecycleMethods(withType: .didUpdateProps, forView: view)
|
|
75
|
+
}
|
|
76
|
+
|
|
46
77
|
/**
|
|
47
78
|
The base `RCTComponentData` class does some Objective-C dynamic calls in this function, but we don't
|
|
48
79
|
need to do these slow operations since the Sweet API gives us necessary details without reflections.
|
|
@@ -52,8 +83,12 @@ public final class ComponentData: RCTComponentData {
|
|
|
52
83
|
var directEvents: [String] = []
|
|
53
84
|
let superClass: AnyClass? = managerClass.superclass()
|
|
54
85
|
|
|
55
|
-
if let
|
|
56
|
-
for
|
|
86
|
+
if let viewManager = moduleHolder?.viewManager {
|
|
87
|
+
for prop in viewManager.props {
|
|
88
|
+
// `id` allows every type to be passed in
|
|
89
|
+
propTypes[prop.name] = "id"
|
|
90
|
+
}
|
|
91
|
+
for eventName in viewManager.eventNames {
|
|
57
92
|
directEvents.append(RCTNormalizeInputEventName(eventName))
|
|
58
93
|
propTypes[eventName] = "BOOL"
|
|
59
94
|
}
|
|
@@ -32,13 +32,13 @@ public final class ConcreteViewProp<ViewType: UIView, PropType: AnyArgument>: An
|
|
|
32
32
|
/**
|
|
33
33
|
Function that sets the underlying prop value for given view.
|
|
34
34
|
*/
|
|
35
|
-
public func set(value: Any, onView view: UIView) throws {
|
|
35
|
+
public func set(value: Any, onView view: UIView, appContext: AppContext) throws {
|
|
36
36
|
// Method's signature must be type-erased to conform to `AnyViewProp` protocol.
|
|
37
37
|
// Given view must be castable to the generic `ViewType` type.
|
|
38
38
|
guard let view = view as? ViewType else {
|
|
39
39
|
throw IncompatibleViewException((propName: name, viewType: ViewType.self))
|
|
40
40
|
}
|
|
41
|
-
guard let value = try propType.cast(value) as? PropType else {
|
|
41
|
+
guard let value = try propType.cast(value, appContext: appContext) as? PropType else {
|
|
42
42
|
throw Conversions.CastingException<PropType>(value)
|
|
43
43
|
}
|
|
44
44
|
setter(view, value)
|
|
@@ -52,14 +52,53 @@ public final class ViewDefinition<ViewType: UIView>: ViewManagerDefinition {
|
|
|
52
52
|
public static func buildExpression(_ element: ViewLifecycleMethod<ViewType>) -> AnyViewDefinitionElement {
|
|
53
53
|
return element
|
|
54
54
|
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
Accepts functions as a view definition elements.
|
|
58
|
+
*/
|
|
59
|
+
public static func buildExpression<ElementType: ViewDefinitionFunctionElement>(
|
|
60
|
+
_ element: ElementType
|
|
61
|
+
) -> AnyViewDefinitionElement {
|
|
62
|
+
return element
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
Accepts functions that take the owner as a view definition elements.
|
|
67
|
+
*/
|
|
68
|
+
public static func buildExpression<ElementType: ViewDefinitionFunctionElement>(
|
|
69
|
+
_ element: ElementType
|
|
70
|
+
) -> AnyViewDefinitionElement where ElementType.ViewType == ViewType {
|
|
71
|
+
// Enforce async functions to run on the main queue
|
|
72
|
+
if var function = element as? AnyAsyncFunctionComponent {
|
|
73
|
+
function.runOnQueue(.main)
|
|
74
|
+
function.takesOwner = true
|
|
75
|
+
}
|
|
76
|
+
return element
|
|
77
|
+
}
|
|
55
78
|
}
|
|
56
79
|
}
|
|
57
80
|
|
|
81
|
+
// MARK: - AnyViewDefinitionElement
|
|
82
|
+
|
|
58
83
|
public protocol AnyViewDefinitionElement: AnyDefinition {}
|
|
59
84
|
extension ConcreteViewProp: AnyViewDefinitionElement {}
|
|
60
85
|
extension EventsDefinition: AnyViewDefinitionElement {}
|
|
61
86
|
extension ViewLifecycleMethod: AnyViewDefinitionElement {}
|
|
62
87
|
|
|
88
|
+
// MARK: - ViewDefinitionFunctionElement
|
|
89
|
+
|
|
90
|
+
public protocol ViewDefinitionFunctionElement: AnyViewDefinitionElement {
|
|
91
|
+
associatedtype ViewType
|
|
92
|
+
}
|
|
93
|
+
extension AsyncFunctionComponent: ViewDefinitionFunctionElement {
|
|
94
|
+
public typealias ViewType = FirstArgType
|
|
95
|
+
}
|
|
96
|
+
extension ConcurrentFunctionDefinition: ViewDefinitionFunctionElement {
|
|
97
|
+
public typealias ViewType = FirstArgType
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
extension UIView: AnyArgument {}
|
|
101
|
+
|
|
63
102
|
/**
|
|
64
103
|
Creates a view definition describing the native view exported to React.
|
|
65
104
|
*/
|
|
@@ -91,35 +91,6 @@ public final class ViewModuleWrapper: RCTViewManager, DynamicModuleWrapperProtoc
|
|
|
91
91
|
return view
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
/**
|
|
95
|
-
The config for `proxiedProperties` prop. In Objective-C style, this function is generated by `RCT_CUSTOM_VIEW_PROPERTY` macro.
|
|
96
|
-
*/
|
|
97
|
-
@objc
|
|
98
|
-
public class func propConfig_proxiedProperties() -> [String] {
|
|
99
|
-
return ["NSDictionary", "__custom__"]
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
The setter for `proxiedProperties` prop. In Objective-C style, this function is generated by `RCT_CUSTOM_VIEW_PROPERTY` macro.
|
|
104
|
-
*/
|
|
105
|
-
@objc
|
|
106
|
-
public func set_proxiedProperties(_ json: Any, forView view: UIView, withDefaultView defaultView: UIView) {
|
|
107
|
-
guard let json = json as? [String: Any], let viewManager = wrappedModuleHolder.definition.viewManager else {
|
|
108
|
-
return
|
|
109
|
-
}
|
|
110
|
-
let props = viewManager.propsDict()
|
|
111
|
-
|
|
112
|
-
for (key, prop) in props {
|
|
113
|
-
let newValue = json[key] as Any
|
|
114
|
-
|
|
115
|
-
// TODO: @tsapeta: Figure out better way to rethrow errors from here.
|
|
116
|
-
// Adding `throws` keyword to the function results in different
|
|
117
|
-
// method signature in Objective-C. Maybe just call `RCTLogError`?
|
|
118
|
-
try? prop.set(value: Conversions.fromNSObject(newValue), onView: view)
|
|
119
|
-
}
|
|
120
|
-
viewManager.callLifecycleMethods(withType: .didUpdateProps, forView: view)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
94
|
public static let viewManagerAdapterPrefix = "ViewManagerAdapter_"
|
|
124
95
|
|
|
125
96
|
/**
|
|
@@ -32,9 +32,9 @@ class ClassComponentSpec: ExpoSpec {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
it("builds a class") {
|
|
35
|
-
let
|
|
35
|
+
let appContext = AppContext.create()
|
|
36
36
|
let klass = Class("") {}
|
|
37
|
-
let object = klass.build(
|
|
37
|
+
let object = try klass.build(appContext: appContext)
|
|
38
38
|
|
|
39
39
|
expect(object.hasProperty("prototype")) == true
|
|
40
40
|
expect(object.getProperty("prototype").kind) == .object
|
|
@@ -43,7 +43,7 @@ class ClassComponentSpec: ExpoSpec {
|
|
|
43
43
|
|
|
44
44
|
describe("module") {
|
|
45
45
|
let appContext = AppContext.create()
|
|
46
|
-
let runtime = appContext.runtime
|
|
46
|
+
let runtime = try! appContext.runtime
|
|
47
47
|
|
|
48
48
|
beforeSuite {
|
|
49
49
|
class ClassTestModule: Module {
|
|
@@ -67,72 +67,72 @@ class ClassComponentSpec: ExpoSpec {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
it("is a function") {
|
|
70
|
-
let klass = try runtime
|
|
71
|
-
expect(klass
|
|
70
|
+
let klass = try runtime.eval("expo.modules.ClassTest.MyClass")
|
|
71
|
+
expect(klass.isFunction()) == true
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
it("has a name") {
|
|
75
|
-
let klass = try runtime
|
|
76
|
-
expect(klass
|
|
75
|
+
let klass = try runtime.eval("expo.modules.ClassTest.MyClass.name")
|
|
76
|
+
expect(klass.getString()) == "MyClass"
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
it("has a prototype") {
|
|
80
|
-
let prototype = try runtime
|
|
81
|
-
expect(prototype
|
|
80
|
+
let prototype = try runtime.eval("expo.modules.ClassTest.MyClass.prototype")
|
|
81
|
+
expect(prototype.isObject()) == true
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
it("has keys in prototype") {
|
|
85
|
-
let prototypeKeys = try runtime
|
|
85
|
+
let prototypeKeys = try runtime.eval("Object.keys(expo.modules.ClassTest.MyClass.prototype)")
|
|
86
86
|
.getArray()
|
|
87
|
-
.map { $0.getString() }
|
|
87
|
+
.map { $0.getString() }
|
|
88
88
|
|
|
89
89
|
expect(prototypeKeys).to(contain("myFunction"))
|
|
90
90
|
expect(prototypeKeys).notTo(contain("__native_constructor__"))
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
it("is an instance of") {
|
|
94
|
-
let isInstanceOf = try runtime
|
|
94
|
+
let isInstanceOf = try runtime.eval([
|
|
95
95
|
"myObject = new expo.modules.ClassTest.MyClass()",
|
|
96
96
|
"myObject instanceof expo.modules.ClassTest.MyClass",
|
|
97
97
|
])
|
|
98
98
|
|
|
99
|
-
expect(isInstanceOf
|
|
99
|
+
expect(isInstanceOf.getBool()) == true
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
it("defines properties on initialization") {
|
|
103
103
|
// The properties are not specified in the prototype, but defined during initialization.
|
|
104
|
-
let object = try runtime
|
|
105
|
-
expect(object
|
|
106
|
-
expect(object
|
|
104
|
+
let object = try runtime.eval("new expo.modules.ClassTest.MyClass()").asObject()
|
|
105
|
+
expect(object.getPropertyNames()).to(contain("foo"))
|
|
106
|
+
expect(object.getProperty("foo").getString()) == "bar"
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
describe("class with associated type") {
|
|
111
111
|
let appContext = AppContext.create()
|
|
112
|
-
let runtime = appContext.runtime
|
|
112
|
+
let runtime = try! appContext.runtime
|
|
113
113
|
|
|
114
114
|
beforeSuite {
|
|
115
115
|
appContext.moduleRegistry.register(moduleType: ModuleWithCounterClass.self)
|
|
116
116
|
}
|
|
117
117
|
it("is defined") {
|
|
118
|
-
let isDefined = try
|
|
118
|
+
let isDefined = try runtime.eval("'Counter' in expo.modules.TestModule")
|
|
119
119
|
|
|
120
120
|
expect(isDefined.getBool()) == true
|
|
121
121
|
}
|
|
122
122
|
it("creates shared object") {
|
|
123
|
-
let jsObject = try
|
|
123
|
+
let jsObject = try runtime.eval("new expo.modules.TestModule.Counter(0)").getObject()
|
|
124
124
|
let nativeObject = SharedObjectRegistry.toNativeObject(jsObject)
|
|
125
125
|
|
|
126
126
|
expect(nativeObject).notTo(beNil())
|
|
127
127
|
}
|
|
128
128
|
it("registers shared object") {
|
|
129
129
|
let oldSize = SharedObjectRegistry.size
|
|
130
|
-
try
|
|
130
|
+
try runtime.eval("object = new expo.modules.TestModule.Counter(0)")
|
|
131
131
|
|
|
132
132
|
expect(SharedObjectRegistry.size) == oldSize + 1
|
|
133
133
|
}
|
|
134
134
|
it("calls function with owner") {
|
|
135
|
-
try runtime
|
|
135
|
+
try runtime.eval([
|
|
136
136
|
"object = new expo.modules.TestModule.Counter(0)",
|
|
137
137
|
"object.increment(1)",
|
|
138
138
|
])
|
|
@@ -140,7 +140,7 @@ class ClassComponentSpec: ExpoSpec {
|
|
|
140
140
|
}
|
|
141
141
|
it("creates with initial value") {
|
|
142
142
|
let initialValue = Int.random(in: 1..<100)
|
|
143
|
-
let value = try runtime
|
|
143
|
+
let value = try runtime.eval([
|
|
144
144
|
"object = new expo.modules.TestModule.Counter(\(initialValue))",
|
|
145
145
|
"object.getValue()",
|
|
146
146
|
])
|
|
@@ -149,7 +149,7 @@ class ClassComponentSpec: ExpoSpec {
|
|
|
149
149
|
expect(value.getInt()) == initialValue
|
|
150
150
|
}
|
|
151
151
|
it("gets shared object value") {
|
|
152
|
-
let value = try runtime
|
|
152
|
+
let value = try runtime.eval([
|
|
153
153
|
"object = new expo.modules.TestModule.Counter(0)",
|
|
154
154
|
"object.getValue()",
|
|
155
155
|
])
|
|
@@ -158,10 +158,10 @@ class ClassComponentSpec: ExpoSpec {
|
|
|
158
158
|
expect(value.isNumber()) == true
|
|
159
159
|
}
|
|
160
160
|
it("changes shared object") {
|
|
161
|
-
try
|
|
161
|
+
try runtime.eval("object = new expo.modules.TestModule.Counter(0)")
|
|
162
162
|
let incrementBy = Int.random(in: 1..<100)
|
|
163
|
-
let value = try runtime
|
|
164
|
-
let newValue = try runtime
|
|
163
|
+
let value = try runtime.eval("object.getValue()").asInt()
|
|
164
|
+
let newValue = try runtime.eval([
|
|
165
165
|
"object.increment(\(incrementBy))",
|
|
166
166
|
"object.getValue()",
|
|
167
167
|
])
|
|
@@ -172,7 +172,7 @@ class ClassComponentSpec: ExpoSpec {
|
|
|
172
172
|
|
|
173
173
|
it("gets value from the dynamic property") {
|
|
174
174
|
let initialValue = Int.random(in: 1..<100)
|
|
175
|
-
let value = try runtime
|
|
175
|
+
let value = try runtime.eval([
|
|
176
176
|
"object = new expo.modules.TestModule.Counter(\(initialValue))",
|
|
177
177
|
"object.currentValue"
|
|
178
178
|
])
|
|
@@ -180,6 +180,14 @@ class ClassComponentSpec: ExpoSpec {
|
|
|
180
180
|
expect(value.kind) == .number
|
|
181
181
|
expect(value.getInt()) == initialValue
|
|
182
182
|
}
|
|
183
|
+
|
|
184
|
+
it("initializes the shared object from native") {
|
|
185
|
+
let initialValue = Int.random(in: 1..<100)
|
|
186
|
+
let value = try runtime.eval("expo.modules.TestModule.newCounter(\(initialValue))")
|
|
187
|
+
|
|
188
|
+
expect(value.kind) == .object
|
|
189
|
+
expect(value.getObject().getProperty("currentValue").getInt()) == initialValue
|
|
190
|
+
}
|
|
183
191
|
}
|
|
184
192
|
}
|
|
185
193
|
}
|
|
@@ -191,6 +199,10 @@ fileprivate final class ModuleWithCounterClass: Module {
|
|
|
191
199
|
func definition() -> ModuleDefinition {
|
|
192
200
|
Name("TestModule")
|
|
193
201
|
|
|
202
|
+
Function("newCounter") { (initialValue: Int) in
|
|
203
|
+
return Counter(initialValue: initialValue)
|
|
204
|
+
}
|
|
205
|
+
|
|
194
206
|
Class(Counter.self) {
|
|
195
207
|
Constructor { (initialValue: Int) in
|
|
196
208
|
return Counter(initialValue: initialValue)
|