expo-modules-core 0.6.1 → 0.7.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.
Files changed (161) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +1 -1
  3. package/android/build.gradle +5 -5
  4. package/android/src/main/java/expo/modules/adapters/react/apploader/RNHeadlessAppLoader.kt +7 -1
  5. package/android/src/main/java/expo/modules/core/interfaces/ReactActivityLifecycleListener.java +23 -0
  6. package/android/src/main/java/expo/modules/kotlin/AppContext.kt +11 -1
  7. package/android/src/main/java/expo/modules/kotlin/DynamicExtenstions.kt +5 -3
  8. package/android/src/main/java/expo/modules/kotlin/KPromiseWrapper.kt +8 -2
  9. package/android/src/main/java/expo/modules/kotlin/KotlinInteropModuleRegistry.kt +13 -4
  10. package/android/src/main/java/expo/modules/kotlin/ModuleHolder.kt +7 -6
  11. package/android/src/main/java/expo/modules/kotlin/ModuleRegistry.kt +6 -1
  12. package/android/src/main/java/expo/modules/kotlin/Promise.kt +1 -1
  13. package/android/src/main/java/expo/modules/kotlin/callbacks/Callback.kt +5 -0
  14. package/android/src/main/java/expo/modules/kotlin/callbacks/ViewCallback.kt +28 -0
  15. package/android/src/main/java/expo/modules/kotlin/callbacks/ViewCallbackDelegate.kt +27 -0
  16. package/android/src/main/java/expo/modules/kotlin/defaultmodules/ErrorManagerModule.kt +25 -0
  17. package/android/src/main/java/expo/modules/kotlin/exception/CodedException.kt +68 -8
  18. package/android/src/main/java/expo/modules/kotlin/exception/ExceptionDecorator.kt +11 -0
  19. package/android/src/main/java/expo/modules/kotlin/methods/AnyMethod.kt +13 -14
  20. package/android/src/main/java/expo/modules/kotlin/modules/DefinitionMarker.kt +4 -0
  21. package/android/src/main/java/expo/modules/kotlin/modules/Module.kt +3 -2
  22. package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +44 -4
  23. package/android/src/main/java/expo/modules/kotlin/records/Record.kt +39 -0
  24. package/android/src/main/java/expo/modules/kotlin/records/RecordTypeConverter.kt +14 -7
  25. package/android/src/main/java/expo/modules/kotlin/types/ArrayTypeConverter.kt +11 -5
  26. package/android/src/main/java/expo/modules/kotlin/types/ListTypeConverter.kt +10 -4
  27. package/android/src/main/java/expo/modules/kotlin/types/MapTypeConverter.kt +12 -6
  28. package/android/src/main/java/expo/modules/kotlin/types/PairTypeConverter.kt +29 -13
  29. package/android/src/main/java/expo/modules/kotlin/types/TypeConverter.kt +2 -1
  30. package/android/src/main/java/expo/modules/kotlin/views/CallbacksDefinition.kt +3 -0
  31. package/android/src/main/java/expo/modules/kotlin/views/GroupViewManagerWrapper.kt +22 -0
  32. package/android/src/main/java/expo/modules/kotlin/views/SimpleViewManagerWrapper.kt +22 -0
  33. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinition.kt +27 -2
  34. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinitionBuilder.kt +29 -1
  35. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerWrapperDelegate.kt +59 -2
  36. package/build/EventEmitter.d.ts +1 -0
  37. package/build/EventEmitter.d.ts.map +1 -0
  38. package/build/NativeModulesProxy.d.ts +1 -0
  39. package/build/NativeModulesProxy.d.ts.map +1 -0
  40. package/build/NativeModulesProxy.native.d.ts +1 -0
  41. package/build/NativeModulesProxy.native.d.ts.map +1 -0
  42. package/build/NativeModulesProxy.types.d.ts +1 -0
  43. package/build/NativeModulesProxy.types.d.ts.map +1 -0
  44. package/build/NativeViewManagerAdapter.d.ts +1 -0
  45. package/build/NativeViewManagerAdapter.d.ts.map +1 -0
  46. package/build/NativeViewManagerAdapter.native.d.ts +1 -0
  47. package/build/NativeViewManagerAdapter.native.d.ts.map +1 -0
  48. package/build/PermissionsHook.d.ts +1 -0
  49. package/build/PermissionsHook.d.ts.map +1 -0
  50. package/build/PermissionsInterface.d.ts +1 -0
  51. package/build/PermissionsInterface.d.ts.map +1 -0
  52. package/build/Platform.d.ts +1 -0
  53. package/build/Platform.d.ts.map +1 -0
  54. package/build/SyntheticPlatformEmitter.d.ts +1 -0
  55. package/build/SyntheticPlatformEmitter.d.ts.map +1 -0
  56. package/build/SyntheticPlatformEmitter.web.d.ts +1 -0
  57. package/build/SyntheticPlatformEmitter.web.d.ts.map +1 -0
  58. package/build/deprecate.d.ts +1 -0
  59. package/build/deprecate.d.ts.map +1 -0
  60. package/build/environment/browser.d.ts +1 -0
  61. package/build/environment/browser.d.ts.map +1 -0
  62. package/build/environment/browser.web.d.ts +1 -0
  63. package/build/environment/browser.web.d.ts.map +1 -0
  64. package/build/errors/CodedError.d.ts +1 -0
  65. package/build/errors/CodedError.d.ts.map +1 -0
  66. package/build/errors/UnavailabilityError.d.ts +1 -0
  67. package/build/errors/UnavailabilityError.d.ts.map +1 -0
  68. package/build/index.d.ts +3 -0
  69. package/build/index.d.ts.map +1 -0
  70. package/build/index.js +2 -0
  71. package/build/index.js.map +1 -1
  72. package/build/requireNativeModule.d.ts +16 -0
  73. package/build/requireNativeModule.d.ts.map +1 -0
  74. package/build/requireNativeModule.js +18 -0
  75. package/build/requireNativeModule.js.map +1 -0
  76. package/build/sweet/NativeErrorManager.d.ts +3 -0
  77. package/build/sweet/NativeErrorManager.d.ts.map +1 -0
  78. package/build/sweet/NativeErrorManager.js +3 -0
  79. package/build/sweet/NativeErrorManager.js.map +1 -0
  80. package/build/sweet/setUpErrorManager.fx.d.ts +2 -0
  81. package/build/sweet/setUpErrorManager.fx.d.ts.map +1 -0
  82. package/build/sweet/setUpErrorManager.fx.js +11 -0
  83. package/build/sweet/setUpErrorManager.fx.js.map +1 -0
  84. package/ios/AppDelegates/ExpoAppDelegate.swift +27 -8
  85. package/ios/JSI/ExpoModulesHostObject.h +33 -0
  86. package/ios/JSI/ExpoModulesHostObject.mm +40 -0
  87. package/ios/JSI/ExpoModulesProxySpec.h +4 -0
  88. package/ios/JSI/ExpoModulesProxySpec.mm +1 -3
  89. package/ios/JSI/JSIConversions.h +2 -0
  90. package/ios/JSI/JSIConversions.mm +9 -0
  91. package/ios/JSI/JSIInstaller.h +10 -0
  92. package/ios/JSI/JSIInstaller.mm +14 -2
  93. package/ios/JSI/JavaScriptObject.h +60 -0
  94. package/ios/JSI/JavaScriptObject.mm +93 -0
  95. package/ios/JSI/JavaScriptRuntime.h +54 -0
  96. package/ios/JSI/JavaScriptRuntime.mm +102 -0
  97. package/ios/ModuleRegistryAdapter/EXModuleRegistryAdapter.m +2 -12
  98. package/ios/NativeModulesProxy/EXComponentDataCompatibleWrapper.h +16 -0
  99. package/ios/NativeModulesProxy/EXComponentDataCompatibleWrapper.m +28 -0
  100. package/ios/NativeModulesProxy/EXNativeModulesProxy.mm +90 -66
  101. package/ios/RCTComponentData+Privates.h +12 -0
  102. package/ios/ReactDelegates/ExpoReactDelegate.swift +2 -2
  103. package/ios/ReactDelegates/ExpoReactDelegateHandler.swift +3 -3
  104. package/ios/ReactDelegates/ModulePriorities.swift +1 -1
  105. package/ios/Swift/AppContext.swift +38 -4
  106. package/ios/Swift/Arguments/ArgumentType.swift +4 -0
  107. package/ios/Swift/Arguments/Convertibles.swift +13 -13
  108. package/ios/Swift/Arguments/Types/EnumArgumentType.swift +11 -17
  109. package/ios/Swift/Arguments/Types/PromiseArgumentType.swift +1 -1
  110. package/ios/Swift/Arguments/Types/RawArgumentType.swift +2 -2
  111. package/ios/Swift/Conversions.swift +51 -56
  112. package/ios/Swift/EventListener.swift +8 -10
  113. package/ios/Swift/Events/Callback.swift +66 -0
  114. package/ios/Swift/Events/Event.swift +43 -0
  115. package/ios/Swift/Exceptions/ChainableException.swift +51 -0
  116. package/ios/Swift/{CodedError.swift → Exceptions/CodedError.swift} +1 -12
  117. package/ios/Swift/Exceptions/Exception.swift +62 -0
  118. package/ios/Swift/Exceptions/ExceptionOrigin.swift +28 -0
  119. package/ios/Swift/Exceptions/GenericException.swift +20 -0
  120. package/ios/Swift/Exceptions/UnexpectedException.swift +16 -0
  121. package/ios/Swift/Functions/AnyFunction.swift +11 -1
  122. package/ios/Swift/Functions/ConcreteFunction.swift +37 -16
  123. package/ios/Swift/JavaScriptUtils.swift +43 -0
  124. package/ios/Swift/ModuleHolder.swift +53 -14
  125. package/ios/Swift/ModuleRegistry.swift +4 -1
  126. package/ios/Swift/Modules/AnyModule.swift +0 -1
  127. package/ios/Swift/Modules/ModuleDefinition.swift +4 -13
  128. package/ios/Swift/Modules/ModuleDefinitionBuilder.swift +0 -1
  129. package/ios/Swift/Modules/ModuleDefinitionComponents.swift +0 -188
  130. package/ios/Swift/ModulesProvider.swift +0 -1
  131. package/ios/Swift/Objects/ObjectDefinition.swift +30 -0
  132. package/ios/Swift/Objects/ObjectDefinitionComponents.swift +208 -0
  133. package/ios/Swift/Promise.swift +8 -3
  134. package/ios/Swift/Records/AnyField.swift +7 -0
  135. package/ios/Swift/Records/Field.swift +24 -19
  136. package/ios/Swift/Records/FieldOption.swift +1 -1
  137. package/ios/Swift/Records/Record.swift +12 -4
  138. package/ios/Swift/SwiftInteropBridge.swift +39 -10
  139. package/ios/Swift/Views/AnyViewProp.swift +1 -1
  140. package/ios/Swift/Views/ComponentData.swift +95 -0
  141. package/ios/Swift/Views/ConcreteViewProp.swift +6 -8
  142. package/ios/Swift/Views/ViewFactory.swift +1 -1
  143. package/ios/Swift/Views/ViewManagerDefinition.swift +23 -2
  144. package/ios/Swift/Views/ViewManagerDefinitionBuilder.swift +0 -1
  145. package/ios/Swift/Views/ViewManagerDefinitionComponents.swift +26 -0
  146. package/ios/Swift/Views/ViewModuleWrapper.swift +5 -2
  147. package/ios/Tests/ArgumentTypeSpec.swift +3 -4
  148. package/ios/Tests/ConstantsSpec.swift +4 -4
  149. package/ios/Tests/ConvertiblesSpec.swift +33 -33
  150. package/ios/Tests/ExceptionsSpec.swift +112 -0
  151. package/ios/Tests/FunctionSpec.swift +20 -22
  152. package/ios/Tests/FunctionWithConvertiblesSpec.swift +2 -2
  153. package/ios/Tests/Mocks/ModuleMocks.swift +1 -1
  154. package/ios/Tests/Mocks/ModulesProviderMock.swift +0 -1
  155. package/ios/Tests/ModuleEventListenersSpec.swift +1 -1
  156. package/ios/Tests/RecordSpec.swift +7 -17
  157. package/package.json +3 -3
  158. package/src/index.ts +4 -0
  159. package/src/requireNativeModule.ts +29 -0
  160. package/src/sweet/NativeErrorManager.ts +2 -0
  161. package/src/sweet/setUpErrorManager.fx.ts +12 -0
@@ -11,11 +11,11 @@ class FunctionSpec: QuickSpec {
11
11
  func testFunctionReturning<T: Equatable>(value returnValue: T) {
12
12
  waitUntil { done in
13
13
  mockModuleHolder(appContext) {
14
- $0.function(functionName) {
14
+ function(functionName) {
15
15
  return returnValue
16
16
  }
17
17
  }
18
- .call(function: functionName, args: []) { value, error in
18
+ .call(function: functionName, args: []) { value, _ in
19
19
  expect(value).notTo(beNil())
20
20
  expect(value).to(beAKindOf(T.self))
21
21
  expect(value as? T).to(equal(returnValue))
@@ -27,7 +27,7 @@ class FunctionSpec: QuickSpec {
27
27
  it("is called") {
28
28
  waitUntil { done in
29
29
  mockModuleHolder(appContext) {
30
- $0.function(functionName) {
30
+ function(functionName) {
31
31
  done()
32
32
  }
33
33
  }
@@ -42,7 +42,7 @@ class FunctionSpec: QuickSpec {
42
42
  }
43
43
 
44
44
  it("returns int values") {
45
- testFunctionReturning(value: 1234)
45
+ testFunctionReturning(value: 1_234)
46
46
  testFunctionReturning(value: [2, 1, 3, 7])
47
47
  }
48
48
 
@@ -60,7 +60,7 @@ class FunctionSpec: QuickSpec {
60
60
  let str: String? = nil
61
61
 
62
62
  mockModuleHolder(appContext) {
63
- $0.function(functionName) { (a: String?) in
63
+ function(functionName) { (a: String?) in
64
64
  expect(a == nil) == true
65
65
  }
66
66
  }
@@ -71,7 +71,7 @@ class FunctionSpec: QuickSpec {
71
71
  let array: [[String]] = [["expo"]]
72
72
 
73
73
  mockModuleHolder(appContext) {
74
- $0.function(functionName) { (a: [[String]]) in
74
+ function(functionName) { (a: [[String]]) in
75
75
  expect(a.first!.first) == array.first!.first
76
76
  }
77
77
  }
@@ -81,7 +81,7 @@ class FunctionSpec: QuickSpec {
81
81
  describe("converting dicts to records") {
82
82
  struct TestRecord: Record {
83
83
  @Field var property: String = "expo"
84
- @Field var optionalProperty: Int? = nil
84
+ @Field var optionalProperty: Int?
85
85
  @Field("propertyWithCustomKey") var customKeyProperty: String = "expo"
86
86
  }
87
87
  let dict = [
@@ -92,11 +92,11 @@ class FunctionSpec: QuickSpec {
92
92
  it("converts to simple record when passed as an argument") {
93
93
  waitUntil { done in
94
94
  mockModuleHolder(appContext) {
95
- $0.function(functionName) { (a: TestRecord) in
95
+ function(functionName) { (a: TestRecord) in
96
96
  return a.property
97
97
  }
98
98
  }
99
- .call(function: functionName, args: [dict]) { value, error in
99
+ .call(function: functionName, args: [dict]) { value, _ in
100
100
  expect(value).notTo(beNil())
101
101
  expect(value).to(beAKindOf(String.self))
102
102
  expect(value).to(be(dict["property"]))
@@ -108,11 +108,11 @@ class FunctionSpec: QuickSpec {
108
108
  it("converts to record with custom key") {
109
109
  waitUntil { done in
110
110
  mockModuleHolder(appContext) {
111
- $0.function(functionName) { (a: TestRecord) in
111
+ function(functionName) { (a: TestRecord) in
112
112
  return a.customKeyProperty
113
113
  }
114
114
  }
115
- .call(function: functionName, args: [dict]) { value, error in
115
+ .call(function: functionName, args: [dict]) { value, _ in
116
116
  expect(value).notTo(beNil())
117
117
  expect(value).to(beAKindOf(String.self))
118
118
  expect(value).to(be(dict["propertyWithCustomKey"]))
@@ -124,11 +124,11 @@ class FunctionSpec: QuickSpec {
124
124
  it("returns the record back") {
125
125
  waitUntil { done in
126
126
  mockModuleHolder(appContext) {
127
- $0.function(functionName) { (a: TestRecord) in
127
+ function(functionName) { (a: TestRecord) in
128
128
  return a.toDictionary()
129
129
  }
130
130
  }
131
- .call(function: functionName, args: [dict]) { value, error in
131
+ .call(function: functionName, args: [dict]) { value, _ in
132
132
  expect(value).notTo(beNil())
133
133
  expect(value).to(beAKindOf(Record.Dict.self))
134
134
 
@@ -145,16 +145,15 @@ class FunctionSpec: QuickSpec {
145
145
  it("throws when called with more arguments than expected") {
146
146
  waitUntil { done in
147
147
  mockModuleHolder(appContext) {
148
- $0.function(functionName) { (a: Int) in
148
+ function(functionName) { (_: Int) in
149
149
  return "something"
150
150
  }
151
151
  }
152
152
  // Function expects one argument, let's give it more.
153
- .call(function: functionName, args: [1, 2]) { value, error in
153
+ .call(function: functionName, args: [1, 2]) { _, error in
154
154
  expect(error).notTo(beNil())
155
- expect(error).to(beAKindOf(InvalidArgsNumberError.self))
156
- expect(error?.code).to(equal("ERR_INVALID_ARGS_NUMBER"))
157
- expect(error?.description).to(equal(InvalidArgsNumberError(received: 2, expected: 1).description))
155
+ expect(error).to(beAKindOf(FunctionCallException.self))
156
+ expect((error as! Exception).isCausedBy(InvalidArgsNumberException.self)) == true
158
157
  done()
159
158
  }
160
159
  }
@@ -163,16 +162,15 @@ class FunctionSpec: QuickSpec {
163
162
  it("throws when called with arguments of incompatible types") {
164
163
  waitUntil { done in
165
164
  mockModuleHolder(appContext) {
166
- $0.function(functionName) { (a: String) in
165
+ function(functionName) { (_: String) in
167
166
  return "something"
168
167
  }
169
168
  }
170
169
  // Function expects a string, let's give it a number.
171
170
  .call(function: functionName, args: [1]) { value, error in
172
171
  expect(error).notTo(beNil())
173
- expect(error).to(beAKindOf(Conversions.CastingError<String>.self))
174
- expect(error?.code).to(equal("ERR_CASTING_FAILED"))
175
- expect(error?.description).to(equal(Conversions.CastingError<String>(value: 1).description))
172
+ expect(error).to(beAKindOf(FunctionCallException.self))
173
+ expect((error as! Exception).isCausedBy(Conversions.CastingException<String>.self)) == true
176
174
  done()
177
175
  }
178
176
  }
@@ -18,7 +18,7 @@ class FunctionWithConvertiblesSpec: QuickSpec {
18
18
  let height = 592.1
19
19
 
20
20
  mockModuleHolder(appContext) {
21
- $0.function(functionName) { (point: CGPoint, size: CGSize, vector: CGVector, rect: CGRect) in
21
+ function(functionName) { (point: CGPoint, size: CGSize, vector: CGVector, rect: CGRect) in
22
22
  expect(point.x) == x
23
23
  expect(point.y) == y
24
24
  expect(size.width) == width
@@ -48,7 +48,7 @@ class FunctionWithConvertiblesSpec: QuickSpec {
48
48
  }
49
49
 
50
50
  mockModuleHolder(appContext) {
51
- $0.function(functionName) { (color1: CGColor, color2: CGColor, color3: CGColor, color4: CGColor) in
51
+ function(functionName) { (color1: CGColor, color2: CGColor, color3: CGColor, color4: CGColor) in
52
52
  testColorComponents(color1, 0x2A, 0x4B, 0x5D, 0xFF)
53
53
  testColorComponents(color2, 0x11, 0xFF, 0x00, 0xDD)
54
54
  testColorComponents(color3, 0x66, 0x00, 0xCC, 0xAA)
@@ -32,7 +32,7 @@ class CustomModule: Module {
32
32
  typealias MockedDefinitionFunc = (CustomModule) -> ModuleDefinition
33
33
 
34
34
  func mockModuleHolder(_ appContext: AppContext, @ModuleDefinitionBuilder _ definitionBody: @escaping () -> ModuleDefinition) -> ModuleHolder {
35
- return ModuleHolder(appContext: appContext, module: CustomModule(appContext: appContext, { module in definitionBody() }))
35
+ return ModuleHolder(appContext: appContext, module: CustomModule(appContext: appContext, { _ in definitionBody() }))
36
36
  }
37
37
 
38
38
  func mockModuleHolder(_ appContext: AppContext, @ModuleDefinitionBuilder _ definitionBody: @escaping (CustomModule) -> ModuleDefinition) -> ModuleHolder {
@@ -3,7 +3,6 @@ import ExpoModulesCore
3
3
  public class ModulesProviderMock: ModulesProvider {
4
4
  public override func getModuleClasses() -> [AnyModule.Type] {
5
5
  return [
6
-
7
6
  ]
8
7
  }
9
8
  }
@@ -21,7 +21,7 @@ class ModuleEventListenersSpec: QuickSpec {
21
21
 
22
22
  it("calls onCreate once the module instance is created") {
23
23
  waitUntil { done in
24
- let _ = mockModuleHolder(appContext) {
24
+ _ = mockModuleHolder(appContext) {
25
25
  $0.onCreate {
26
26
  done()
27
27
  }
@@ -7,7 +7,7 @@ class RecordSpec: QuickSpec {
7
7
  override func spec() {
8
8
  it("initializes with empty dictionary") {
9
9
  struct TestRecord: Record { }
10
- let _ = try TestRecord(from: [:])
10
+ _ = try TestRecord(from: [:])
11
11
  }
12
12
 
13
13
  it("works back and forth with a field") {
@@ -37,14 +37,9 @@ class RecordSpec: QuickSpec {
37
37
  @Field(.required) var a: Int
38
38
  }
39
39
 
40
- do {
41
- let _ = try TestRecord(from: [:])
42
- fail()
43
- } catch let error as CodedError {
44
- expect(error).to(beAKindOf(FieldRequiredError.self))
45
- expect(error.code).to(equal("ERR_FIELD_REQUIRED"))
46
- expect(error.description).to(equal(FieldRequiredError(fieldKey: "a").description))
47
- }
40
+ expect { try TestRecord(from: [:]) }.to(throwError { error in
41
+ expect(error).to(beAKindOf(FieldRequiredException.self))
42
+ })
48
43
  }
49
44
 
50
45
  it("throws when casting is not possible") {
@@ -53,14 +48,9 @@ class RecordSpec: QuickSpec {
53
48
  }
54
49
  let dict = ["a": "try with String instead of Int"]
55
50
 
56
- do {
57
- let _ = try TestRecord(from: dict)
58
- fail()
59
- } catch let error as CodedError {
60
- expect(error).to(beAKindOf(FieldInvalidTypeError.self))
61
- expect(error.code).to(equal("ERR_FIELD_INVALID_TYPE"))
62
- expect(error.description).to(equal(FieldInvalidTypeError(fieldKey: "a", value: dict["a"], desiredType: Int.self).description))
63
- }
51
+ expect { try TestRecord(from: dict) }.to(throwError { error in
52
+ expect(error).to(beAKindOf(FieldInvalidTypeException.self))
53
+ })
64
54
  }
65
55
  }
66
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-modules-core",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "The core of Expo Modules architecture",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "author": "650 Industries, Inc.",
32
32
  "license": "MIT",
33
- "homepage": "https://github.com/expo/expo/tree/master/packages/expo-modules-core",
33
+ "homepage": "https://github.com/expo/expo/tree/main/packages/expo-modules-core",
34
34
  "jest": {
35
35
  "preset": "expo-module-scripts"
36
36
  },
@@ -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": "cf8e7fde1b19e10dd9b74a8af0e9362ae8e14001"
45
+ "gitHead": "e1ff1a3d6bc62f374e6947a5e81428a1bb7cfa34"
46
46
  }
package/src/index.ts CHANGED
@@ -9,6 +9,8 @@ import SyntheticPlatformEmitter from './SyntheticPlatformEmitter';
9
9
  import { CodedError } from './errors/CodedError';
10
10
  import { UnavailabilityError } from './errors/UnavailabilityError';
11
11
 
12
+ import './sweet/setUpErrorManager.fx';
13
+
12
14
  export { default as deprecate } from './deprecate';
13
15
 
14
16
  export {
@@ -25,6 +27,8 @@ export {
25
27
  UnavailabilityError,
26
28
  };
27
29
 
30
+ export * from './requireNativeModule';
31
+
28
32
  /**
29
33
  * @deprecated renamed to `DeviceEventEmitter`
30
34
  */
@@ -0,0 +1,29 @@
1
+ import NativeModulesProxy from './NativeModulesProxy';
2
+
3
+ declare global {
4
+ // eslint-disable-next-line no-var
5
+ var ExpoModules:
6
+ | undefined
7
+ | {
8
+ [key: string]: any;
9
+ };
10
+ }
11
+
12
+ /**
13
+ * Imports the native module registered with given name. In the first place it tries to load
14
+ * the module installed through the JSI host object and then falls back to the bridge proxy module.
15
+ * Notice that the modules loaded from the proxy may not support some features like synchronous functions.
16
+ *
17
+ * @param moduleName Name of the requested native module.
18
+ * @returns Object representing the native module.
19
+ * @throws Error when there is no native module with given name.
20
+ */
21
+ export function requireNativeModule<ModuleType = any>(moduleName: string): ModuleType {
22
+ const nativeModule: ModuleType =
23
+ global.ExpoModules?.[moduleName] ?? NativeModulesProxy[moduleName];
24
+
25
+ if (!nativeModule) {
26
+ throw new Error(`Cannot find native module '${moduleName}'`);
27
+ }
28
+ return nativeModule;
29
+ }
@@ -0,0 +1,2 @@
1
+ import { NativeModulesProxy } from '..';
2
+ export default NativeModulesProxy.ExpoModulesCoreErrorManager;
@@ -0,0 +1,12 @@
1
+ import { EventEmitter } from '../EventEmitter';
2
+ import Platform from '../Platform';
3
+ import NativeErrorManager from './NativeErrorManager';
4
+
5
+ if (__DEV__ && Platform.OS === 'android' && NativeErrorManager) {
6
+ const onNewException = 'ExpoModulesCoreErrorManager.onNewException';
7
+ const eventEmitter = new EventEmitter(NativeErrorManager);
8
+
9
+ eventEmitter.addListener(onNewException, ({ message }: { message: string }) => {
10
+ console.error(message);
11
+ });
12
+ }