expo-modules-core 0.7.0 → 0.9.1
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 +49 -0
- package/README.md +1 -1
- package/android/ExpoModulesCorePlugin.gradle +15 -0
- package/android/build.gradle +46 -32
- package/android/src/main/java/expo/modules/adapters/react/NativeModulesProxy.java +5 -5
- package/android/src/main/java/expo/modules/adapters/react/services/UIManagerModuleWrapper.java +13 -0
- package/android/src/main/java/expo/modules/core/ViewManager.java +9 -0
- package/android/src/main/java/expo/modules/core/interfaces/JavaScriptContextProvider.java +4 -0
- package/android/src/main/java/expo/modules/core/interfaces/ReactActivityHandler.java +37 -1
- package/android/src/main/java/expo/modules/core/interfaces/ReactNativeHostHandler.java +30 -0
- package/android/src/main/java/expo/modules/core/interfaces/services/UIManager.java +2 -0
- package/android/src/main/java/expo/modules/kotlin/AppContext.kt +13 -5
- package/android/src/main/java/expo/modules/kotlin/KPromiseWrapper.kt +2 -13
- package/android/src/main/java/expo/modules/kotlin/KotlinInteropModuleRegistry.kt +11 -5
- package/android/src/main/java/expo/modules/kotlin/ModuleHolder.kt +5 -1
- package/android/src/main/java/expo/modules/kotlin/ModuleRegistry.kt +17 -0
- package/android/src/main/java/expo/modules/kotlin/callbacks/ViewCallback.kt +14 -3
- package/android/src/main/java/expo/modules/kotlin/events/EventEmitter.kt +13 -0
- package/android/src/main/java/expo/modules/kotlin/events/KModuleEventEmitterWrapper.kt +102 -0
- package/android/src/main/java/expo/modules/kotlin/exception/CodedException.kt +25 -1
- package/android/src/main/java/expo/modules/kotlin/{methods/AnyMethod.kt → functions/AnyFunction.kt} +6 -5
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunction.kt +15 -0
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionBuilder.kt +170 -0
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionWithPromise.kt +15 -0
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncSuspendFunction.kt +36 -0
- package/android/src/main/java/expo/modules/kotlin/modules/Module.kt +14 -0
- package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +374 -41
- package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionData.kt +2 -2
- package/android/src/main/java/expo/modules/kotlin/records/FieldValidator.kt +139 -0
- package/android/src/main/java/expo/modules/kotlin/records/Record.kt +0 -39
- package/android/src/main/java/expo/modules/kotlin/records/RecordTypeConverter.kt +59 -10
- package/android/src/main/java/expo/modules/kotlin/records/Required.kt +5 -0
- package/android/src/main/java/expo/modules/kotlin/records/ValidationBinder.kt +110 -0
- package/android/src/main/java/expo/modules/kotlin/records/Validators.kt +61 -0
- package/android/src/main/java/expo/modules/kotlin/types/JSTypeConverter.kt +35 -0
- package/android/src/main/java/expo/modules/kotlin/types/JSTypeConverterHelper.kt +148 -0
- package/android/src/main/java/expo/modules/kotlin/types/TypeConverterProvider.kt +9 -1
- package/android/src/main/java/expo/modules/kotlin/views/GroupViewManagerWrapper.kt +49 -0
- package/android/src/main/java/expo/modules/kotlin/views/ViewGroupDefinition.kt +18 -0
- package/android/src/main/java/expo/modules/kotlin/views/ViewGroupDefinitionBuilder.kt +114 -0
- package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinition.kt +4 -1
- package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinitionBuilder.kt +56 -5
- package/android/src/main/java/expo/modules/kotlin/views/ViewManagerWrapperDelegate.kt +3 -0
- package/build/NativeModulesProxy.native.d.ts +0 -4
- package/build/NativeModulesProxy.native.d.ts.map +1 -1
- package/build/NativeModulesProxy.native.js +1 -14
- package/build/NativeModulesProxy.native.js.map +1 -1
- package/build/NativeModulesProxy.types.d.ts +0 -3
- package/build/NativeModulesProxy.types.d.ts.map +1 -1
- package/build/NativeModulesProxy.types.js.map +1 -1
- package/build/NativeViewManagerAdapter.native.d.ts.map +1 -1
- package/build/NativeViewManagerAdapter.native.js +9 -33
- package/build/NativeViewManagerAdapter.native.js.map +1 -1
- package/build/sweet/NativeErrorManager.js +1 -1
- package/build/sweet/NativeErrorManager.js.map +1 -1
- package/ios/AppDelegates/EXAppDelegatesLoader.m +4 -8
- package/ios/AppDelegates/ExpoAppDelegate.swift +4 -10
- package/ios/EXAppDefines.h +1 -0
- package/ios/EXAppDefines.m +6 -0
- package/ios/EXUtilities.h +2 -0
- package/ios/EXUtilities.m +12 -0
- package/ios/ExpoModulesCore.h +4 -0
- package/ios/ExpoModulesCore.podspec +4 -2
- package/ios/Interfaces/FileSystem/EXFileSystemInterface.h +1 -1
- package/ios/Interfaces/TaskManager/EXTaskServiceInterface.h +1 -0
- package/ios/JSI/{JSIConversions.h → EXJSIConversions.h} +4 -1
- package/ios/JSI/{JSIConversions.mm → EXJSIConversions.mm} +16 -5
- package/ios/JSI/{JSIInstaller.h → EXJSIInstaller.h} +3 -3
- package/ios/JSI/EXJSIInstaller.mm +17 -0
- package/ios/JSI/{ExpoModulesProxySpec.h → EXJSIUtils.h} +0 -9
- package/ios/JSI/{ExpoModulesProxySpec.mm → EXJSIUtils.mm} +4 -48
- package/ios/JSI/EXJavaScriptObject.h +97 -0
- package/ios/JSI/EXJavaScriptObject.mm +121 -0
- package/ios/JSI/{JavaScriptRuntime.h → EXJavaScriptRuntime.h} +27 -8
- package/ios/JSI/EXJavaScriptRuntime.mm +153 -0
- package/ios/JSI/EXJavaScriptValue.h +57 -0
- package/ios/JSI/EXJavaScriptValue.mm +166 -0
- package/ios/JSI/ExpoModulesHostObject.mm +2 -1
- package/ios/JSI/JavaScriptRuntime.swift +32 -0
- package/ios/JSI/JavaScriptValue.swift +94 -0
- package/ios/ModuleRegistryAdapter/EXModuleRegistryAdapter.m +1 -11
- package/ios/NativeModulesProxy/EXNativeModulesProxy.h +2 -2
- package/ios/NativeModulesProxy/EXNativeModulesProxy.mm +24 -22
- package/ios/ReactDelegates/EXReactCompatibleHelpers.h +18 -0
- package/ios/ReactDelegates/EXReactCompatibleHelpers.m +19 -0
- package/ios/ReactDelegates/ExpoReactDelegate.swift +2 -2
- package/ios/ReactDelegates/ExpoReactDelegateHandler.swift +1 -1
- package/ios/Swift/AppContext.swift +21 -2
- package/ios/Swift/Arguments/AnyArgumentType.swift +1 -1
- package/ios/Swift/Functions/AnyFunction.swift +5 -0
- package/ios/Swift/Functions/AsyncFunctionComponent.swift +182 -0
- package/ios/Swift/Functions/ConcreteFunction.swift +40 -68
- package/ios/Swift/Functions/SyncFunctionComponent.swift +181 -0
- package/ios/Swift/JavaScriptUtils.swift +56 -0
- package/ios/Swift/ModuleHolder.swift +17 -5
- package/ios/Swift/Modules/ModuleDefinitionComponents.swift +66 -44
- package/ios/Swift/ModulesProvider.swift +3 -10
- package/ios/Swift/Objects/ObjectDefinitionComponents.swift +49 -0
- package/ios/Swift/SwiftInteropBridge.swift +14 -5
- package/ios/Swift/Views/ComponentData.swift +2 -1
- package/ios/Swift/Views/ExpoView.swift +8 -0
- package/ios/Swift/Views/ViewManagerDefinitionComponents.swift +23 -0
- package/ios/Swift.h +5 -0
- package/ios/Tests/ArgumentTypeSpec.swift +2 -3
- package/ios/Tests/ConstantsSpec.swift +6 -7
- package/ios/Tests/ConvertiblesSpec.swift +2 -3
- package/ios/Tests/ExceptionsSpec.swift +2 -3
- package/ios/Tests/ExpoModulesSpec.swift +75 -0
- package/ios/Tests/FunctionSpec.swift +13 -15
- package/ios/Tests/FunctionWithConvertiblesSpec.swift +4 -5
- package/ios/Tests/JavaScriptObjectSpec.swift +97 -0
- package/ios/Tests/JavaScriptRuntimeSpec.swift +94 -0
- package/ios/Tests/ModuleEventListenersSpec.swift +15 -16
- package/ios/Tests/ModuleRegistrySpec.swift +2 -3
- package/ios/Tests/RecordSpec.swift +2 -3
- package/package.json +2 -2
- package/src/NativeModulesProxy.native.ts +2 -22
- package/src/NativeModulesProxy.types.ts +0 -8
- package/src/NativeViewManagerAdapter.native.tsx +12 -28
- package/src/sweet/NativeErrorManager.ts +1 -1
- package/android/src/main/java/expo/modules/kotlin/events/KEventEmitterWrapper.kt +0 -26
- package/android/src/main/java/expo/modules/kotlin/methods/Method.kt +0 -14
- package/android/src/main/java/expo/modules/kotlin/methods/PromiseMethod.kt +0 -15
- package/ios/JSI/JSIInstaller.mm +0 -34
- package/ios/JSI/JavaScriptObject.h +0 -60
- package/ios/JSI/JavaScriptObject.mm +0 -93
- package/ios/JSI/JavaScriptRuntime.mm +0 -102
- package/ios/NativeModulesProxy/EXComponentDataCompatibleWrapper.h +0 -16
- package/ios/NativeModulesProxy/EXComponentDataCompatibleWrapper.m +0 -28
|
@@ -12,6 +12,7 @@ extension AnyModule {
|
|
|
12
12
|
/**
|
|
13
13
|
Sets the name of the module that is exported to the JavaScript world.
|
|
14
14
|
*/
|
|
15
|
+
@available(*, deprecated, renamed: "Name")
|
|
15
16
|
public func name(_ name: String) -> AnyDefinition {
|
|
16
17
|
return ModuleNameDefinition(name: name)
|
|
17
18
|
}
|
|
@@ -21,6 +22,7 @@ extension AnyModule {
|
|
|
21
22
|
/**
|
|
22
23
|
Creates module's lifecycle listener that is called right after module initialization.
|
|
23
24
|
*/
|
|
25
|
+
@available(*, deprecated, renamed: "OnCreate")
|
|
24
26
|
public func onCreate(_ closure: @escaping () -> Void) -> AnyDefinition {
|
|
25
27
|
return EventListener(.moduleCreate, closure)
|
|
26
28
|
}
|
|
@@ -28,6 +30,7 @@ extension AnyModule {
|
|
|
28
30
|
/**
|
|
29
31
|
Creates module's lifecycle listener that is called when the module is about to be deallocated.
|
|
30
32
|
*/
|
|
33
|
+
@available(*, deprecated, renamed: "OnDestroy")
|
|
31
34
|
public func onDestroy(_ closure: @escaping () -> Void) -> AnyDefinition {
|
|
32
35
|
return EventListener(.moduleDestroy, closure)
|
|
33
36
|
}
|
|
@@ -35,6 +38,7 @@ extension AnyModule {
|
|
|
35
38
|
/**
|
|
36
39
|
Creates module's lifecycle listener that is called when the app context owning the module is about to be deallocated.
|
|
37
40
|
*/
|
|
41
|
+
@available(*, deprecated, renamed: "OnAppContextDestroys")
|
|
38
42
|
public func onAppContextDestroys(_ closure: @escaping () -> Void) -> AnyDefinition {
|
|
39
43
|
return EventListener(.appContextDestroys, closure)
|
|
40
44
|
}
|
|
@@ -42,6 +46,7 @@ extension AnyModule {
|
|
|
42
46
|
/**
|
|
43
47
|
Creates a listener that is called when the app is about to enter the foreground mode.
|
|
44
48
|
*/
|
|
49
|
+
@available(*, deprecated, renamed: "OnAppEntersBackground")
|
|
45
50
|
public func onAppEntersForeground(_ closure: @escaping () -> Void) -> AnyDefinition {
|
|
46
51
|
return EventListener(.appEntersForeground, closure)
|
|
47
52
|
}
|
|
@@ -49,6 +54,7 @@ extension AnyModule {
|
|
|
49
54
|
/**
|
|
50
55
|
Creates a listener that is called when the app becomes active again.
|
|
51
56
|
*/
|
|
57
|
+
@available(*, deprecated, renamed: "OnAppBecomesActive")
|
|
52
58
|
public func onAppBecomesActive(_ closure: @escaping () -> Void) -> AnyDefinition {
|
|
53
59
|
return EventListener(.appBecomesActive, closure)
|
|
54
60
|
}
|
|
@@ -56,6 +62,7 @@ extension AnyModule {
|
|
|
56
62
|
/**
|
|
57
63
|
Creates a listener that is called when the app enters the background mode.
|
|
58
64
|
*/
|
|
65
|
+
@available(*, deprecated, renamed: "OnAppEntersBackground")
|
|
59
66
|
public func onAppEntersBackground(_ closure: @escaping () -> Void) -> AnyDefinition {
|
|
60
67
|
return EventListener(.appEntersBackground, closure)
|
|
61
68
|
}
|
|
@@ -65,55 +72,70 @@ extension AnyModule {
|
|
|
65
72
|
/**
|
|
66
73
|
Creates the view manager definition that scopes other view-related definitions.
|
|
67
74
|
*/
|
|
75
|
+
@available(*, deprecated, renamed: "ViewManager")
|
|
68
76
|
public func viewManager(@ViewManagerDefinitionBuilder _ closure: @escaping () -> ViewManagerDefinition) -> AnyDefinition {
|
|
69
77
|
return closure()
|
|
70
78
|
}
|
|
71
79
|
}
|
|
72
80
|
|
|
73
|
-
//
|
|
74
|
-
public extension AnyModule {
|
|
75
|
-
/**
|
|
76
|
-
Function without arguments.
|
|
77
|
-
*/
|
|
78
|
-
@available(*, deprecated, renamed: "function")
|
|
79
|
-
func method<R>(
|
|
80
|
-
_ name: String,
|
|
81
|
-
_ closure: @escaping () -> R
|
|
82
|
-
) -> AnyFunction {
|
|
83
|
-
return ConcreteFunction(
|
|
84
|
-
name,
|
|
85
|
-
argTypes: [],
|
|
86
|
-
closure
|
|
87
|
-
)
|
|
88
|
-
}
|
|
81
|
+
// MARK: - Module name
|
|
89
82
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
_ closure: @escaping (A0) -> R
|
|
97
|
-
) -> AnyFunction {
|
|
98
|
-
return ConcreteFunction(
|
|
99
|
-
name,
|
|
100
|
-
argTypes: [ArgumentType(A0.self)],
|
|
101
|
-
closure
|
|
102
|
-
)
|
|
103
|
-
}
|
|
83
|
+
/**
|
|
84
|
+
Sets the name of the module that is exported to the JavaScript world.
|
|
85
|
+
*/
|
|
86
|
+
public func Name(_ name: String) -> AnyDefinition {
|
|
87
|
+
return ModuleNameDefinition(name: name)
|
|
88
|
+
}
|
|
104
89
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
90
|
+
// MARK: - Module's lifecycle
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
Creates module's lifecycle listener that is called right after module initialization.
|
|
94
|
+
*/
|
|
95
|
+
public func OnCreate(_ closure: @escaping () -> Void) -> AnyDefinition {
|
|
96
|
+
return EventListener(.moduleCreate, closure)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
Creates module's lifecycle listener that is called when the module is about to be deallocated.
|
|
101
|
+
*/
|
|
102
|
+
public func OnDestroy(_ closure: @escaping () -> Void) -> AnyDefinition {
|
|
103
|
+
return EventListener(.moduleDestroy, closure)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
Creates module's lifecycle listener that is called when the app context owning the module is about to be deallocated.
|
|
108
|
+
*/
|
|
109
|
+
public func OnAppContextDestroys(_ closure: @escaping () -> Void) -> AnyDefinition {
|
|
110
|
+
return EventListener(.appContextDestroys, closure)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
Creates a listener that is called when the app is about to enter the foreground mode.
|
|
115
|
+
*/
|
|
116
|
+
public func OnAppEntersForeground(_ closure: @escaping () -> Void) -> AnyDefinition {
|
|
117
|
+
return EventListener(.appEntersForeground, closure)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
Creates a listener that is called when the app becomes active again.
|
|
122
|
+
*/
|
|
123
|
+
public func OnAppBecomesActive(_ closure: @escaping () -> Void) -> AnyDefinition {
|
|
124
|
+
return EventListener(.appBecomesActive, closure)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
Creates a listener that is called when the app enters the background mode.
|
|
129
|
+
*/
|
|
130
|
+
public func OnAppEntersBackground(_ closure: @escaping () -> Void) -> AnyDefinition {
|
|
131
|
+
return EventListener(.appEntersBackground, closure)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// MARK: - View Manager
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
Creates the view manager definition that scopes other view-related definitions.
|
|
138
|
+
*/
|
|
139
|
+
public func ViewManager(@ViewManagerDefinitionBuilder _ closure: @escaping () -> ViewManagerDefinition) -> AnyDefinition {
|
|
140
|
+
return closure()
|
|
119
141
|
}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
In Objective-C code we do not do anything with it except passing it back to the Swift light side.
|
|
4
|
+
Swift protocol defining the requirements for modules providers.
|
|
6
5
|
*/
|
|
7
|
-
|
|
8
|
-
public protocol ModulesProviderObjCProtocol {}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
Swift protocol defining the requirements for modules providers. Extends its Objective-C counterpart `ModulesProviderObjCProtocol`.
|
|
12
|
-
*/
|
|
13
|
-
public protocol ModulesProviderProtocol: ModulesProviderObjCProtocol {
|
|
6
|
+
public protocol ModulesProviderProtocol {
|
|
14
7
|
func getModuleClasses() -> [AnyModule.Type]
|
|
15
8
|
|
|
16
9
|
/**
|
|
@@ -30,7 +23,7 @@ public protocol ModulesProviderProtocol: ModulesProviderObjCProtocol {
|
|
|
30
23
|
The proper implementation is generated by autolinking as part of `pod install` command.
|
|
31
24
|
*/
|
|
32
25
|
@objc
|
|
33
|
-
open class ModulesProvider: NSObject, ModulesProviderProtocol
|
|
26
|
+
open class ModulesProvider: NSObject, ModulesProviderProtocol {
|
|
34
27
|
open func getModuleClasses() -> [AnyModule.Type] {
|
|
35
28
|
return []
|
|
36
29
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
/**
|
|
7
7
|
Definition function setting the module's constants to export.
|
|
8
8
|
*/
|
|
9
|
+
@available(*, deprecated, renamed: "Constants")
|
|
9
10
|
public func constants(_ body: @escaping () -> [String: Any?]) -> AnyDefinition {
|
|
10
11
|
return ConstantsDefinition(body: body)
|
|
11
12
|
}
|
|
@@ -13,15 +14,31 @@ public func constants(_ body: @escaping () -> [String: Any?]) -> AnyDefinition {
|
|
|
13
14
|
/**
|
|
14
15
|
Definition function setting the module's constants to export.
|
|
15
16
|
*/
|
|
17
|
+
public func Constants(_ body: @escaping () -> [String: Any?]) -> AnyDefinition {
|
|
18
|
+
return ConstantsDefinition(body: body)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
Definition function setting the module's constants to export.
|
|
23
|
+
*/
|
|
24
|
+
@available(*, deprecated, renamed: "Constants")
|
|
16
25
|
public func constants(_ body: @autoclosure @escaping () -> [String: Any?]) -> AnyDefinition {
|
|
17
26
|
return ConstantsDefinition(body: body)
|
|
18
27
|
}
|
|
19
28
|
|
|
29
|
+
/**
|
|
30
|
+
Definition function setting the module's constants to export.
|
|
31
|
+
*/
|
|
32
|
+
public func Constants(_ body: @autoclosure @escaping () -> [String: Any?]) -> AnyDefinition {
|
|
33
|
+
return ConstantsDefinition(body: body)
|
|
34
|
+
}
|
|
35
|
+
|
|
20
36
|
// MARK: - Functions
|
|
21
37
|
|
|
22
38
|
/**
|
|
23
39
|
Function without arguments.
|
|
24
40
|
*/
|
|
41
|
+
@available(*, deprecated, renamed: "AsyncFunction")
|
|
25
42
|
public func function<R>(
|
|
26
43
|
_ name: String,
|
|
27
44
|
_ closure: @escaping () throws -> R
|
|
@@ -36,6 +53,7 @@ public func function<R>(
|
|
|
36
53
|
/**
|
|
37
54
|
Function with one argument.
|
|
38
55
|
*/
|
|
56
|
+
@available(*, deprecated, renamed: "AsyncFunction")
|
|
39
57
|
public func function<R, A0: AnyArgument>(
|
|
40
58
|
_ name: String,
|
|
41
59
|
_ closure: @escaping (A0) throws -> R
|
|
@@ -50,6 +68,7 @@ public func function<R, A0: AnyArgument>(
|
|
|
50
68
|
/**
|
|
51
69
|
Function with two arguments.
|
|
52
70
|
*/
|
|
71
|
+
@available(*, deprecated, renamed: "AsyncFunction")
|
|
53
72
|
public func function<R, A0: AnyArgument, A1: AnyArgument>(
|
|
54
73
|
_ name: String,
|
|
55
74
|
_ closure: @escaping (A0, A1) throws -> R
|
|
@@ -64,6 +83,7 @@ public func function<R, A0: AnyArgument, A1: AnyArgument>(
|
|
|
64
83
|
/**
|
|
65
84
|
Function with three arguments.
|
|
66
85
|
*/
|
|
86
|
+
@available(*, deprecated, renamed: "AsyncFunction")
|
|
67
87
|
public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument>(
|
|
68
88
|
_ name: String,
|
|
69
89
|
_ closure: @escaping (A0, A1, A2) throws -> R
|
|
@@ -82,6 +102,7 @@ public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument>(
|
|
|
82
102
|
/**
|
|
83
103
|
Function with four arguments.
|
|
84
104
|
*/
|
|
105
|
+
@available(*, deprecated, renamed: "AsyncFunction")
|
|
85
106
|
public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: AnyArgument>(
|
|
86
107
|
_ name: String,
|
|
87
108
|
_ closure: @escaping (A0, A1, A2, A3) throws -> R
|
|
@@ -101,6 +122,7 @@ public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: A
|
|
|
101
122
|
/**
|
|
102
123
|
Function with five arguments.
|
|
103
124
|
*/
|
|
125
|
+
@available(*, deprecated, renamed: "AsyncFunction")
|
|
104
126
|
public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: AnyArgument, A4: AnyArgument>(
|
|
105
127
|
_ name: String,
|
|
106
128
|
_ closure: @escaping (A0, A1, A2, A3, A4) throws -> R
|
|
@@ -121,6 +143,7 @@ public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: A
|
|
|
121
143
|
/**
|
|
122
144
|
Function with six arguments.
|
|
123
145
|
*/
|
|
146
|
+
@available(*, deprecated, renamed: "AsyncFunction")
|
|
124
147
|
public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: AnyArgument, A4: AnyArgument, A5: AnyArgument>(
|
|
125
148
|
_ name: String,
|
|
126
149
|
_ closure: @escaping (A0, A1, A2, A3, A4, A5) throws -> R
|
|
@@ -142,6 +165,7 @@ public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: A
|
|
|
142
165
|
/**
|
|
143
166
|
Function with seven arguments.
|
|
144
167
|
*/
|
|
168
|
+
@available(*, deprecated, renamed: "AsyncFunction")
|
|
145
169
|
public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: AnyArgument, A4: AnyArgument, A5: AnyArgument, A6: AnyArgument>(
|
|
146
170
|
_ name: String,
|
|
147
171
|
_ closure: @escaping (A0, A1, A2, A3, A4, A5, A6) throws -> R
|
|
@@ -164,6 +188,7 @@ public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: A
|
|
|
164
188
|
/**
|
|
165
189
|
Function with eight arguments.
|
|
166
190
|
*/
|
|
191
|
+
@available(*, deprecated, renamed: "AsyncFunction")
|
|
167
192
|
public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: AnyArgument, A4: AnyArgument, A5: AnyArgument, A6: AnyArgument, A7: AnyArgument>(
|
|
168
193
|
_ name: String,
|
|
169
194
|
_ closure: @escaping (A0, A1, A2, A3, A4, A5, A6, A7) throws -> R
|
|
@@ -189,20 +214,44 @@ public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: A
|
|
|
189
214
|
/**
|
|
190
215
|
Defines event names that the object can send to JavaScript.
|
|
191
216
|
*/
|
|
217
|
+
@available(*, deprecated, renamed: "Events")
|
|
192
218
|
public func events(_ names: String...) -> AnyDefinition {
|
|
193
219
|
return EventsDefinition(names: names)
|
|
194
220
|
}
|
|
195
221
|
|
|
222
|
+
/**
|
|
223
|
+
Defines event names that the object can send to JavaScript.
|
|
224
|
+
*/
|
|
225
|
+
public func Events(_ names: String...) -> AnyDefinition {
|
|
226
|
+
return EventsDefinition(names: names)
|
|
227
|
+
}
|
|
228
|
+
|
|
196
229
|
/**
|
|
197
230
|
Function that is invoked when the first event listener is added.
|
|
198
231
|
*/
|
|
232
|
+
@available(*, deprecated, renamed: "OnStartObserving")
|
|
199
233
|
public func onStartObserving(_ body: @escaping () -> Void) -> AnyFunction {
|
|
200
234
|
return ConcreteFunction("startObserving", argTypes: [], body)
|
|
201
235
|
}
|
|
202
236
|
|
|
237
|
+
/**
|
|
238
|
+
Function that is invoked when the first event listener is added.
|
|
239
|
+
*/
|
|
240
|
+
public func OnStartObserving(_ body: @escaping () -> Void) -> AnyFunction {
|
|
241
|
+
return ConcreteFunction("startObserving", argTypes: [], body)
|
|
242
|
+
}
|
|
243
|
+
|
|
203
244
|
/**
|
|
204
245
|
Function that is invoked when all event listeners are removed.
|
|
205
246
|
*/
|
|
247
|
+
@available(*, deprecated, renamed: "OnStopObserving")
|
|
206
248
|
public func onStopObserving(_ body: @escaping () -> Void) -> AnyFunction {
|
|
207
249
|
return ConcreteFunction("stopObserving", argTypes: [], body)
|
|
208
250
|
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
Function that is invoked when all event listeners are removed.
|
|
254
|
+
*/
|
|
255
|
+
public func OnStopObserving(_ body: @escaping () -> Void) -> AnyFunction {
|
|
256
|
+
return ConcreteFunction("stopObserving", argTypes: [], body)
|
|
257
|
+
}
|
|
@@ -11,9 +11,14 @@ public final class SwiftInteropBridge: NSObject {
|
|
|
11
11
|
appContext.moduleRegistry
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
internal init(appContext: AppContext) {
|
|
15
|
+
self.appContext = appContext
|
|
16
|
+
super.init()
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
@objc
|
|
15
|
-
public init(modulesProvider:
|
|
16
|
-
self.appContext = AppContext(withModulesProvider: modulesProvider
|
|
20
|
+
public init(modulesProvider: ModulesProvider, legacyModuleRegistry: EXModuleRegistry) {
|
|
21
|
+
self.appContext = AppContext(withModulesProvider: modulesProvider, legacyModuleRegistry: legacyModuleRegistry)
|
|
17
22
|
super.init()
|
|
18
23
|
}
|
|
19
24
|
|
|
@@ -83,9 +88,13 @@ public final class SwiftInteropBridge: NSObject {
|
|
|
83
88
|
}
|
|
84
89
|
|
|
85
90
|
@objc
|
|
86
|
-
public func
|
|
87
|
-
return registry.
|
|
88
|
-
|
|
91
|
+
public func viewManagersMetadata() -> [String: Any] {
|
|
92
|
+
return registry.reduce(into: [String: Any]()) { acc, holder in
|
|
93
|
+
if let viewManager = holder.definition.viewManager {
|
|
94
|
+
acc[holder.name] = [
|
|
95
|
+
"propsNames": viewManager.props.map { $0.name }
|
|
96
|
+
]
|
|
97
|
+
}
|
|
89
98
|
}
|
|
90
99
|
}
|
|
91
100
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright 2021-present 650 Industries. All rights reserved.
|
|
2
2
|
|
|
3
|
+
import React
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
Custom component data extending `RCTComponentData`. Its main purpose is to handle event-based props (callbacks),
|
|
6
7
|
but it also simplifies capturing the view config so we can omit some reflections that React Native executes.
|
|
7
8
|
*/
|
|
8
9
|
@objc(EXComponentData)
|
|
9
|
-
public final class ComponentData:
|
|
10
|
+
public final class ComponentData: RCTComponentData {
|
|
10
11
|
/**
|
|
11
12
|
Weak pointer to the holder of a module that the component data was created for.
|
|
12
13
|
*/
|
|
@@ -5,15 +5,24 @@
|
|
|
5
5
|
/**
|
|
6
6
|
Defines the factory creating a native view when the module is used as a view.
|
|
7
7
|
*/
|
|
8
|
+
@available(*, deprecated, renamed: "View")
|
|
8
9
|
public func view(_ closure: @escaping () -> UIView) -> ViewManagerDefinitionComponent {
|
|
9
10
|
return ViewFactory(closure)
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
/**
|
|
14
|
+
Defines the factory creating a native view when the module is used as a view.
|
|
15
|
+
*/
|
|
16
|
+
public func View(_ closure: @escaping () -> UIView) -> ViewManagerDefinitionComponent {
|
|
17
|
+
return ViewFactory(closure)
|
|
18
|
+
}
|
|
19
|
+
|
|
12
20
|
// MARK: Props
|
|
13
21
|
|
|
14
22
|
/**
|
|
15
23
|
Creates a view prop that defines its name and setter.
|
|
16
24
|
*/
|
|
25
|
+
@available(*, deprecated, renamed: "Prop")
|
|
17
26
|
public func prop<ViewType: UIView, PropType: AnyArgument>(
|
|
18
27
|
_ name: String,
|
|
19
28
|
_ setter: @escaping (ViewType, PropType) -> Void
|
|
@@ -24,3 +33,17 @@ public func prop<ViewType: UIView, PropType: AnyArgument>(
|
|
|
24
33
|
setter: setter
|
|
25
34
|
)
|
|
26
35
|
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
Creates a view prop that defines its name and setter.
|
|
39
|
+
*/
|
|
40
|
+
public func Prop<ViewType: UIView, PropType: AnyArgument>(
|
|
41
|
+
_ name: String,
|
|
42
|
+
_ setter: @escaping (ViewType, PropType) -> Void
|
|
43
|
+
) -> ViewManagerDefinitionComponent {
|
|
44
|
+
return ConcreteViewProp(
|
|
45
|
+
name: name,
|
|
46
|
+
propType: ArgumentType(PropType.self),
|
|
47
|
+
setter: setter
|
|
48
|
+
)
|
|
49
|
+
}
|
package/ios/Swift.h
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
// Copyright 2018-present 650 Industries. All rights reserved.
|
|
2
2
|
|
|
3
|
+
// The generated swift header may depend on some Objective-C declarations,
|
|
4
|
+
// adding dependency imports here to prevent declarations not found errors.
|
|
5
|
+
#import <ExpoModulesCore/EXDefines.h>
|
|
6
|
+
#import <ExpoModulesCore/RCTComponentData+Privates.h>
|
|
7
|
+
|
|
3
8
|
// When `use_frameworks!` is used, the generated Swift header is inside ExpoModulesCore module.
|
|
4
9
|
// Otherwise, it's available only locally with double-quoted imports.
|
|
5
10
|
#if __has_include(<ExpoModulesCore/ExpoModulesCore-Swift.h>)
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// Copyright 2021-present 650 Industries. All rights reserved.
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import Nimble
|
|
3
|
+
import ExpoModulesTestCore
|
|
5
4
|
|
|
6
5
|
@testable import ExpoModulesCore
|
|
7
6
|
|
|
8
|
-
class ArgumentTypeSpec:
|
|
7
|
+
class ArgumentTypeSpec: ExpoSpec {
|
|
9
8
|
override func spec() {
|
|
10
9
|
it("casts primitives") {
|
|
11
10
|
let type = ArgumentType(Int.self)
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import Nimble
|
|
1
|
+
import ExpoModulesTestCore
|
|
3
2
|
|
|
4
3
|
@testable import ExpoModulesCore
|
|
5
4
|
|
|
6
|
-
class ConstantsSpec:
|
|
5
|
+
class ConstantsSpec: ExpoSpec {
|
|
7
6
|
override func spec() {
|
|
8
7
|
let appContext = AppContext()
|
|
9
8
|
|
|
10
9
|
it("takes closure resolving to dictionary") {
|
|
11
10
|
let holder = mockModuleHolder(appContext) {
|
|
12
|
-
|
|
11
|
+
Constants {
|
|
13
12
|
return ["test": 123]
|
|
14
13
|
}
|
|
15
14
|
}
|
|
@@ -18,15 +17,15 @@ class ConstantsSpec: QuickSpec {
|
|
|
18
17
|
|
|
19
18
|
it("takes the dictionary") {
|
|
20
19
|
let holder = mockModuleHolder(appContext) {
|
|
21
|
-
|
|
20
|
+
Constants(["test": 123])
|
|
22
21
|
}
|
|
23
22
|
expect(holder.getConstants()["test"] as? Int) == 123
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
it("merges multiple constants definitions") {
|
|
27
26
|
let holder = mockModuleHolder(appContext) {
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
Constants(["test": 456, "test2": 789])
|
|
28
|
+
Constants(["test": 123])
|
|
30
29
|
}
|
|
31
30
|
let consts = holder.getConstants()
|
|
32
31
|
expect(consts["test"] as? Int) == 123
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// Copyright 2018-present 650 Industries. All rights reserved.
|
|
2
2
|
|
|
3
3
|
import CoreGraphics
|
|
4
|
-
import
|
|
5
|
-
import Nimble
|
|
4
|
+
import ExpoModulesTestCore
|
|
6
5
|
|
|
7
6
|
@testable import ExpoModulesCore
|
|
8
7
|
|
|
9
|
-
class ConvertiblesSpec:
|
|
8
|
+
class ConvertiblesSpec: ExpoSpec {
|
|
10
9
|
override func spec() {
|
|
11
10
|
describe("URL") {
|
|
12
11
|
it("converts from remote url") {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// Copyright 2021-present 650 Industries. All rights reserved.
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import Nimble
|
|
3
|
+
import ExpoModulesTestCore
|
|
5
4
|
|
|
6
5
|
@testable import ExpoModulesCore
|
|
7
6
|
|
|
8
|
-
final class ExceptionsSpec:
|
|
7
|
+
final class ExceptionsSpec: ExpoSpec {
|
|
9
8
|
override func spec() {
|
|
10
9
|
it("has name") {
|
|
11
10
|
let error = TestException()
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright 2022-present 650 Industries. All rights reserved.
|
|
2
|
+
|
|
3
|
+
import ExpoModulesTestCore
|
|
4
|
+
|
|
5
|
+
@testable import ExpoModulesCore
|
|
6
|
+
|
|
7
|
+
class ExpoModulesSpec: ExpoSpec {
|
|
8
|
+
override func spec() {
|
|
9
|
+
let appContext = AppContext.create()
|
|
10
|
+
let interopBridge = SwiftInteropBridge(appContext: appContext)
|
|
11
|
+
let runtime = appContext.runtime
|
|
12
|
+
let testModuleName = "TestModule"
|
|
13
|
+
let testFunctionName = "testFunction"
|
|
14
|
+
let constantsDict: [String: Any] = [
|
|
15
|
+
"expo": "is cool",
|
|
16
|
+
"sdk": 45,
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
beforeSuite {
|
|
20
|
+
try! appContext.installExpoModulesHostObject(interopBridge)
|
|
21
|
+
|
|
22
|
+
appContext.moduleRegistry.register(holder: mockModuleHolder(appContext) {
|
|
23
|
+
Name(testModuleName)
|
|
24
|
+
|
|
25
|
+
Constants(constantsDict)
|
|
26
|
+
|
|
27
|
+
Function(testFunctionName) { Double.pi }
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe("host object") {
|
|
32
|
+
it("is defined") {
|
|
33
|
+
expect(try! runtime?.eval("'ExpoModules' in this").asBool()) === true
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
it("has native module defined") {
|
|
37
|
+
expect(try! runtime?.eval("'\(testModuleName)' in ExpoModules").asBool()) === true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
it("can access native module") {
|
|
41
|
+
let nativeModule = try! runtime?.eval("ExpoModules.\(testModuleName)")
|
|
42
|
+
expect(nativeModule?.isUndefined()) == false
|
|
43
|
+
expect(nativeModule?.isObject()) == true
|
|
44
|
+
expect(nativeModule?.getRaw()).notTo(beNil())
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
it("has keys for registered modules") {
|
|
48
|
+
let registeredModuleNames = appContext.moduleRegistry.getModuleNames()
|
|
49
|
+
let keys = try! runtime?.eval("Object.keys(ExpoModules)").asArray().compactMap {
|
|
50
|
+
return try! $0?.asString()
|
|
51
|
+
}
|
|
52
|
+
expect(keys).to(contain(registeredModuleNames))
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe("module") {
|
|
57
|
+
it("exposes constants") {
|
|
58
|
+
let dict = try! runtime!.eval("ExpoModules.TestModule").asDict()
|
|
59
|
+
|
|
60
|
+
dict.forEach { (key: String, value: Any) in
|
|
61
|
+
expect(value) === dict[key]!
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
it("has function") {
|
|
66
|
+
expect(try! runtime?.eval("typeof ExpoModules.TestModule.\(testFunctionName)").asString()) == "function"
|
|
67
|
+
expect(try! runtime?.eval("ExpoModules.TestModule.\(testFunctionName)").isFunction()) == true
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
it("calls function") {
|
|
71
|
+
expect(try! runtime?.eval("ExpoModules.TestModule.\(testFunctionName)()").asDouble()) == Double.pi
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|