expo-modules-core 0.8.0 → 0.9.2

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.
Files changed (26) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/android/build.gradle +2 -2
  3. package/android/src/main/java/expo/modules/core/interfaces/ReactNativeHostHandler.java +11 -0
  4. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionBuilder.kt +127 -18
  5. package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +210 -26
  6. package/android/src/main/java/expo/modules/kotlin/views/ViewGroupDefinitionBuilder.kt +55 -5
  7. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinitionBuilder.kt +43 -5
  8. package/ios/NativeModulesProxy/EXNativeModulesProxy.mm +3 -0
  9. package/ios/Swift/AppContext.swift +1 -8
  10. package/ios/Swift/Arguments/AnyArgumentType.swift +1 -1
  11. package/ios/Swift/Functions/AnyFunction.swift +5 -0
  12. package/ios/Swift/Functions/AsyncFunctionComponent.swift +182 -0
  13. package/ios/Swift/Functions/ConcreteFunction.swift +34 -67
  14. package/ios/Swift/Functions/SyncFunctionComponent.swift +181 -0
  15. package/ios/Swift/JavaScriptUtils.swift +51 -6
  16. package/ios/Swift/ModuleHolder.swift +11 -10
  17. package/ios/Swift/Modules/ModuleDefinitionComponents.swift +66 -44
  18. package/ios/Swift/Objects/ObjectDefinitionComponents.swift +45 -172
  19. package/ios/Swift/Views/ViewManagerDefinitionComponents.swift +23 -0
  20. package/ios/Tests/ConstantsSpec.swift +4 -4
  21. package/ios/Tests/ExpoModulesSpec.swift +3 -4
  22. package/ios/Tests/FunctionSpec.swift +11 -12
  23. package/ios/Tests/FunctionWithConvertiblesSpec.swift +2 -2
  24. package/ios/Tests/ModuleEventListenersSpec.swift +13 -13
  25. package/package.json +2 -2
  26. package/ios/Swift/Functions/AsyncFunction.swift +0 -17
@@ -10,7 +10,7 @@ class FunctionSpec: ExpoSpec {
10
10
  func testFunctionReturning<T: Equatable>(value returnValue: T) {
11
11
  waitUntil { done in
12
12
  mockModuleHolder(appContext) {
13
- function(functionName) {
13
+ AsyncFunction(functionName) {
14
14
  return returnValue
15
15
  }
16
16
  }
@@ -26,7 +26,7 @@ class FunctionSpec: ExpoSpec {
26
26
  it("is called") {
27
27
  waitUntil { done in
28
28
  mockModuleHolder(appContext) {
29
- function(functionName) {
29
+ AsyncFunction(functionName) {
30
30
  done()
31
31
  }
32
32
  }
@@ -59,7 +59,7 @@ class FunctionSpec: ExpoSpec {
59
59
  let str: String? = nil
60
60
 
61
61
  mockModuleHolder(appContext) {
62
- function(functionName) { (a: String?) in
62
+ AsyncFunction(functionName) { (a: String?) in
63
63
  expect(a == nil) == true
64
64
  }
65
65
  }
@@ -70,7 +70,7 @@ class FunctionSpec: ExpoSpec {
70
70
  let array: [[String]] = [["expo"]]
71
71
 
72
72
  mockModuleHolder(appContext) {
73
- function(functionName) { (a: [[String]]) in
73
+ AsyncFunction(functionName) { (a: [[String]]) in
74
74
  expect(a.first!.first) == array.first!.first
75
75
  }
76
76
  }
@@ -91,7 +91,7 @@ class FunctionSpec: ExpoSpec {
91
91
  it("converts to simple record when passed as an argument") {
92
92
  waitUntil { done in
93
93
  mockModuleHolder(appContext) {
94
- function(functionName) { (a: TestRecord) in
94
+ AsyncFunction(functionName) { (a: TestRecord) in
95
95
  return a.property
96
96
  }
97
97
  }
@@ -107,7 +107,7 @@ class FunctionSpec: ExpoSpec {
107
107
  it("converts to record with custom key") {
108
108
  waitUntil { done in
109
109
  mockModuleHolder(appContext) {
110
- function(functionName) { (a: TestRecord) in
110
+ AsyncFunction(functionName) { (a: TestRecord) in
111
111
  return a.customKeyProperty
112
112
  }
113
113
  }
@@ -123,7 +123,7 @@ class FunctionSpec: ExpoSpec {
123
123
  it("returns the record back") {
124
124
  waitUntil { done in
125
125
  mockModuleHolder(appContext) {
126
- function(functionName) { (a: TestRecord) in
126
+ AsyncFunction(functionName) { (a: TestRecord) in
127
127
  return a.toDictionary()
128
128
  }
129
129
  }
@@ -144,15 +144,14 @@ class FunctionSpec: ExpoSpec {
144
144
  it("throws when called with more arguments than expected") {
145
145
  waitUntil { done in
146
146
  mockModuleHolder(appContext) {
147
- function(functionName) { (_: Int) in
147
+ AsyncFunction(functionName) { (_: Int) in
148
148
  return "something"
149
149
  }
150
150
  }
151
151
  // Function expects one argument, let's give it more.
152
152
  .call(function: functionName, args: [1, 2]) { _, error in
153
153
  expect(error).notTo(beNil())
154
- expect(error).to(beAKindOf(FunctionCallException.self))
155
- expect((error as! Exception).isCausedBy(InvalidArgsNumberException.self)) == true
154
+ expect(error).to(beAKindOf(InvalidArgsNumberException.self))
156
155
  done()
157
156
  }
158
157
  }
@@ -161,14 +160,14 @@ class FunctionSpec: ExpoSpec {
161
160
  it("throws when called with arguments of incompatible types") {
162
161
  waitUntil { done in
163
162
  mockModuleHolder(appContext) {
164
- function(functionName) { (_: String) in
163
+ AsyncFunction(functionName) { (_: String) in
165
164
  return "something"
166
165
  }
167
166
  }
168
167
  // Function expects a string, let's give it a number.
169
168
  .call(function: functionName, args: [1]) { value, error in
170
169
  expect(error).notTo(beNil())
171
- expect(error).to(beAKindOf(FunctionCallException.self))
170
+ expect(error).to(beAKindOf(ArgumentCastException.self))
172
171
  expect((error as! Exception).isCausedBy(Conversions.CastingException<String>.self)) == true
173
172
  done()
174
173
  }
@@ -17,7 +17,7 @@ class FunctionWithConvertiblesSpec: ExpoSpec {
17
17
  let height = 592.1
18
18
 
19
19
  mockModuleHolder(appContext) {
20
- function(functionName) { (point: CGPoint, size: CGSize, vector: CGVector, rect: CGRect) in
20
+ AsyncFunction(functionName) { (point: CGPoint, size: CGSize, vector: CGVector, rect: CGRect) in
21
21
  expect(point.x) == x
22
22
  expect(point.y) == y
23
23
  expect(size.width) == width
@@ -47,7 +47,7 @@ class FunctionWithConvertiblesSpec: ExpoSpec {
47
47
  }
48
48
 
49
49
  mockModuleHolder(appContext) {
50
- function(functionName) { (color1: CGColor, color2: CGColor, color3: CGColor, color4: CGColor) in
50
+ AsyncFunction(functionName) { (color1: CGColor, color2: CGColor, color3: CGColor, color4: CGColor) in
51
51
  testColorComponents(color1, 0x2A, 0x4B, 0x5D, 0xFF)
52
52
  testColorComponents(color2, 0x11, 0xFF, 0x00, 0xDD)
53
53
  testColorComponents(color3, 0x66, 0x00, 0xCC, 0xAA)
@@ -18,22 +18,22 @@ class ModuleEventListenersSpec: ExpoSpec {
18
18
  appContext = AppContext()
19
19
  }
20
20
 
21
- it("calls onCreate once the module instance is created") {
21
+ it("calls OnCreate once the module instance is created") {
22
22
  waitUntil { done in
23
23
  _ = mockModuleHolder(appContext) {
24
- $0.onCreate {
24
+ OnCreate {
25
25
  done()
26
26
  }
27
27
  }
28
28
  }
29
29
  }
30
30
 
31
- it("calls onDestroy once the module is about to be deallocated") {
31
+ it("calls OnDestroy once the module is about to be deallocated") {
32
32
  waitUntil { done in
33
33
  let moduleName = "mockedModule"
34
34
  let holder = mockModuleHolder(appContext) {
35
- $0.name(moduleName)
36
- $0.onDestroy {
35
+ Name(moduleName)
36
+ OnDestroy {
37
37
  done()
38
38
  }
39
39
  }
@@ -44,10 +44,10 @@ class ModuleEventListenersSpec: ExpoSpec {
44
44
  }
45
45
  }
46
46
 
47
- it("calls onAppContextDestroys once the context destroys") {
47
+ it("calls OnAppContextDestroys once the context destroys") {
48
48
  waitUntil { done in
49
49
  let holder = mockModuleHolder(appContext) {
50
- $0.onAppContextDestroys {
50
+ OnAppContextDestroys {
51
51
  done()
52
52
  }
53
53
  }
@@ -69,10 +69,10 @@ class ModuleEventListenersSpec: ExpoSpec {
69
69
  }
70
70
  }
71
71
 
72
- it("calls onAppEntersForeground when system's willEnterForegroundNotification is sent") {
72
+ it("calls OnAppEntersForeground when system's willEnterForegroundNotification is sent") {
73
73
  waitUntil { done in
74
74
  let holder = mockModuleHolder(appContext) {
75
- $0.onAppEntersForeground {
75
+ OnAppEntersForeground {
76
76
  done()
77
77
  }
78
78
  }
@@ -81,10 +81,10 @@ class ModuleEventListenersSpec: ExpoSpec {
81
81
  }
82
82
  }
83
83
 
84
- it("calls onAppBecomesActive when system's didBecomeActiveNotification is sent") {
84
+ it("calls OnAppBecomesActive when system's didBecomeActiveNotification is sent") {
85
85
  waitUntil { done in
86
86
  let holder = mockModuleHolder(appContext) {
87
- $0.onAppBecomesActive {
87
+ OnAppBecomesActive {
88
88
  done()
89
89
  }
90
90
  }
@@ -93,10 +93,10 @@ class ModuleEventListenersSpec: ExpoSpec {
93
93
  }
94
94
  }
95
95
 
96
- it("calls onAppEntersBackground when system's didEnterBackgroundNotification is sent") {
96
+ it("calls OnAppEntersBackground when system's didEnterBackgroundNotification is sent") {
97
97
  waitUntil { done in
98
98
  let holder = mockModuleHolder(appContext) {
99
- $0.onAppEntersBackground {
99
+ OnAppEntersBackground {
100
100
  done()
101
101
  }
102
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-modules-core",
3
- "version": "0.8.0",
3
+ "version": "0.9.2",
4
4
  "description": "The core of Expo Modules architecture",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -42,5 +42,5 @@
42
42
  "@testing-library/react-hooks": "^7.0.1",
43
43
  "expo-module-scripts": "^2.0.0"
44
44
  },
45
- "gitHead": "22dce752354bb429c84851bc4389abe47a766b1f"
45
+ "gitHead": "464933d2189a33b02375b47cd655e87f5694afb4"
46
46
  }
@@ -1,17 +0,0 @@
1
- // Copyright 2022-present 650 Industries. All rights reserved.
2
-
3
- /**
4
- Represents a function that can only be called asynchronously, thus its JavaScript equivalent returns a Promise.
5
-
6
- - ToDo: Move some asynchronous logic from `ConcreteFunction` (like `call(args:promise:)`) to this class and drop the `isAsync` property.
7
- */
8
- public final class AsyncFunction<Args, ReturnType>: ConcreteFunction<Args, ReturnType> {
9
- override init(
10
- _ name: String,
11
- argTypes: [AnyArgumentType],
12
- _ closure: @escaping ConcreteFunction<Args, ReturnType>.ClosureType
13
- ) {
14
- super.init(name, argTypes: argTypes, closure)
15
- self.isAsync = true
16
- }
17
- }