expo-modules-core 1.0.1 → 1.0.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.
package/CHANGELOG.md CHANGED
@@ -10,11 +10,18 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
- ## 1.0.1 — 2022-11-07
13
+ ## 1.0.2 — 2022-11-08
14
+
15
+ ### 💡 Others
16
+
17
+ - Rephrased the message of `ArgumentCastException` to use ordinal numbers. ([#19912](https://github.com/expo/expo/pull/19912) by [@tsapeta](https://github.com/tsapeta))
18
+
19
+ ## 1.0.1 - 2022-11-07
14
20
 
15
21
  ### 🐛 Bug fixes
16
22
 
17
23
  - Added a list of the acceptable enum values to the conversion error on Android. ([#19895](https://github.com/expo/expo/pull/19895) by [@lukmccall](https://github.com/lukmccall))
24
+ - Fixed `new NativeEventEmitter() was called with a non-null argument without the required addListener method.` warnings on Android with JSC. ([#19920](https://github.com/expo/expo/pull/19920) by [@kudo](https://github.com/kudo))
18
25
 
19
26
  ### 💡 Others
20
27
 
@@ -6,7 +6,7 @@ apply plugin: 'maven-publish'
6
6
  apply plugin: "de.undercouch.download"
7
7
 
8
8
  group = 'host.exp.exponent'
9
- version = '1.0.1'
9
+ version = '1.0.2'
10
10
 
11
11
  buildscript {
12
12
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
@@ -191,7 +191,7 @@ android {
191
191
  targetSdkVersion safeExtGet("targetSdkVersion", 31)
192
192
  consumerProguardFiles 'proguard-rules.pro'
193
193
  versionCode 1
194
- versionName "1.0.1"
194
+ versionName "1.0.2"
195
195
  buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled.toString()
196
196
 
197
197
  testInstrumentationRunner "expo.modules.TestRunner"
@@ -145,9 +145,19 @@ internal class ArgumentCastException(
145
145
  providedType: ReadableType,
146
146
  cause: CodedException,
147
147
  ) : DecoratedException(
148
- message = "Argument at index '$argIndex' couldn't be casted to type '$argDesiredType' (received '$providedType').",
148
+ message = "The ${formatOrdinalNumber(argIndex + 1)} argument cannot be cast to type $argDesiredType (received $providedType)",
149
149
  cause,
150
- )
150
+ ) {
151
+ companion object {
152
+ fun formatOrdinalNumber(number: Int) = "$number" + when {
153
+ (number % 100 in 11..13) -> "th"
154
+ (number % 10) == 1 -> "st"
155
+ (number % 10) == 2 -> "nd"
156
+ (number % 10) == 3 -> "rd"
157
+ else -> "th"
158
+ }
159
+ }
160
+ }
151
161
 
152
162
  internal class FieldCastException(
153
163
  fieldName: String,
@@ -43,6 +43,18 @@ open class ObjectDefinitionBuilder {
43
43
  internal var properties = mutableMapOf<String, PropertyComponentBuilder>()
44
44
 
45
45
  fun buildObject(): ObjectDefinitionData {
46
+ // Register stub functions to bypass react-native `NativeEventEmitter` warnings
47
+ // WARN `new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.
48
+ // WARN `new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.
49
+ eventsDefinition?.run {
50
+ if (!containsFunction("addListener")) {
51
+ Function("addListener") { _: String -> { } }
52
+ }
53
+ if (!containsFunction("removeListeners")) {
54
+ Function("removeListeners") { _: Int -> { } }
55
+ }
56
+ }
57
+
46
58
  return ObjectDefinitionData(
47
59
  constantsProvider,
48
60
  syncFunctions,
@@ -52,6 +64,12 @@ open class ObjectDefinitionBuilder {
52
64
  )
53
65
  }
54
66
 
67
+ private fun containsFunction(functionName: String): Boolean {
68
+ return syncFunctions.containsKey(functionName) ||
69
+ asyncFunctions.containsKey(functionName) ||
70
+ functionBuilders.containsKey(functionName)
71
+ }
72
+
55
73
  /**
56
74
  * Definition function setting the module's constants to export.
57
75
  */
@@ -1 +1 @@
1
- {"version":3,"file":"EventEmitter.d.ts","sourceRoot":"","sources":["../src/EventEmitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAI3E,aAAK,YAAY,GAAG;IAClB,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OAEG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,CAAC;AAEF,qBAAa,YAAY;IACvB,cAAc,SAAK;IACnB,aAAa,EAAE,YAAY,CAAC;IAC5B,aAAa,EAAE,kBAAkB,CAAC;gBAEtB,YAAY,EAAE,YAAY;IAqBtC,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,YAAY;IAgB7E,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAmB3C,kBAAkB,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI;IA0BpD,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;CAGhD"}
@@ -14,23 +14,6 @@ export class EventEmitter {
14
14
  nativeModule.addListener = (...args) => NativeModules.EXReactNativeEventEmitter.addProxiedListener(nativeModule.__expo_module_name__, ...args);
15
15
  nativeModule.removeListeners = (...args) => NativeModules.EXReactNativeEventEmitter.removeProxiedListeners(nativeModule.__expo_module_name__, ...args);
16
16
  }
17
- // Fix the `NativeEventEmitter` warnings on Android.
18
- // WARN `new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.
19
- // WARN `new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.
20
- if (Platform.OS === 'android') {
21
- Object.defineProperties(nativeModule, {
22
- addListener: {
23
- value: () => { },
24
- writable: true,
25
- enumerable: true,
26
- },
27
- removeListeners: {
28
- value: () => { },
29
- writable: true,
30
- enumerable: true,
31
- },
32
- });
33
- }
34
17
  this._nativeModule = nativeModule;
35
18
  this._eventEmitter = new NativeEventEmitter(nativeModule);
36
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"EventEmitter.js","sourceRoot":"","sources":["../src/EventEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,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AE;YAC9B,OAAO;SACR;QAED,IAAI,QAAQ,IAAI,yBAAyB,EAAE;YACzC,iEAAiE;YACjE,yBAAyB,CAAC,MAAM,EAAE,CAAC;SACpC;aAAM,IAAI,oBAAoB,IAAI,IAAI,CAAC,aAAa,EAAE;YACrD,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC,yBAA0B,CAAC,CAAC;SACnE;QACD,IAAI,CAAC,cAAc,EAAE,CAAC;QAEtB,2FAA2F;QAC3F,0CAA0C;QAC1C,OAAO,YAAY,CAAC,4BAA4B,CAAC,CAAC;QAElD,gDAAgD;QAChD,YAAY,CAAC,MAAM,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;QAE/B,IAAI,CAAC,IAAI,CAAC,cAAc,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE;YACrF,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,CAAC;SACpC;IACH,CAAC;IAED,IAAI,CAAC,SAAiB,EAAE,GAAG,MAAa;QACtC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,MAAM,CAAC,CAAC;IAChD,CAAC;CACF","sourcesContent":["import invariant from 'invariant';\nimport { NativeEventEmitter, NativeModules, Platform } from 'react-native';\n\nconst nativeEmitterSubscriptionKey = '@@nativeEmitterSubscription@@';\n\ntype NativeModule = {\n __expo_module_name__?: string;\n startObserving?: () => void;\n stopObserving?: () => void;\n addListener: (eventName: string) => void;\n removeListeners: (count: number) => void;\n};\n\n// @needsAudit\nexport type Subscription = {\n /**\n * A method to unsubscribe the listener.\n */\n remove: () => void;\n};\n\nexport class EventEmitter {\n _listenerCount = 0;\n _nativeModule: NativeModule;\n _eventEmitter: NativeEventEmitter;\n\n constructor(nativeModule: NativeModule) {\n // Expo modules installed through the JSI don't have `addListener` and `removeListeners` set,\n // so if someone wants to use them with `EventEmitter`, make sure to provide these functions\n // as they are required by `NativeEventEmitter`. This is only temporary — in the future\n // JSI modules will have event emitter built in.\n if (nativeModule.__expo_module_name__ && NativeModules.EXReactNativeEventEmitter) {\n nativeModule.addListener = (...args) =>\n NativeModules.EXReactNativeEventEmitter.addProxiedListener(\n nativeModule.__expo_module_name__,\n ...args\n );\n nativeModule.removeListeners = (...args) =>\n NativeModules.EXReactNativeEventEmitter.removeProxiedListeners(\n nativeModule.__expo_module_name__,\n ...args\n );\n }\n // Fix the `NativeEventEmitter` warnings on Android.\n // WARN `new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.\n // WARN `new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.\n if (Platform.OS === 'android') {\n Object.defineProperties(nativeModule, {\n addListener: {\n value: () => {},\n writable: true,\n enumerable: true,\n },\n removeListeners: {\n value: () => {},\n writable: true,\n enumerable: true,\n },\n });\n }\n\n this._nativeModule = nativeModule;\n this._eventEmitter = new NativeEventEmitter(nativeModule as any);\n }\n\n addListener<T>(eventName: string, listener: (event: T) => void): Subscription {\n if (!this._listenerCount && Platform.OS !== 'ios' && this._nativeModule.startObserving) {\n this._nativeModule.startObserving();\n }\n\n this._listenerCount++;\n const nativeEmitterSubscription = this._eventEmitter.addListener(eventName, listener);\n const subscription = {\n [nativeEmitterSubscriptionKey]: nativeEmitterSubscription,\n remove: () => {\n this.removeSubscription(subscription);\n },\n };\n return subscription;\n }\n\n removeAllListeners(eventName: string): void {\n // @ts-ignore: the EventEmitter interface has been changed in react-native@0.64.0\n const removedListenerCount = this._eventEmitter.listenerCount\n ? // @ts-ignore: this is available since 0.64\n this._eventEmitter.listenerCount(eventName)\n : // @ts-ignore: this is available in older versions\n this._eventEmitter.listeners(eventName).length;\n this._eventEmitter.removeAllListeners(eventName);\n this._listenerCount -= removedListenerCount;\n invariant(\n this._listenerCount >= 0,\n `EventEmitter must have a non-negative number of listeners`\n );\n\n if (!this._listenerCount && Platform.OS !== 'ios' && this._nativeModule.stopObserving) {\n this._nativeModule.stopObserving();\n }\n }\n\n removeSubscription(subscription: Subscription): void {\n const nativeEmitterSubscription = subscription[nativeEmitterSubscriptionKey];\n if (!nativeEmitterSubscription) {\n return;\n }\n\n if ('remove' in nativeEmitterSubscription) {\n // `react-native-web@0.17.1` doesn't support `removeSubscription`\n nativeEmitterSubscription.remove();\n } else if ('removeSubscription' in this._eventEmitter) {\n this._eventEmitter.removeSubscription(nativeEmitterSubscription!);\n }\n this._listenerCount--;\n\n // Ensure that the emitter's internal state remains correct even if `removeSubscription` is\n // called again with the same subscription\n delete subscription[nativeEmitterSubscriptionKey];\n\n // Release closed-over references to the emitter\n subscription.remove = () => {};\n\n if (!this._listenerCount && Platform.OS !== 'ios' && this._nativeModule.stopObserving) {\n this._nativeModule.stopObserving();\n }\n }\n\n emit(eventName: string, ...params: any[]): void {\n this._eventEmitter.emit(eventName, ...params);\n }\n}\n"]}
1
+ {"version":3,"file":"EventEmitter.js","sourceRoot":"","sources":["../src/EventEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE3E,MAAM,4BAA4B,GAAG,+BAA+B,CAAC;AAkBrE,MAAM,OAAO,YAAY;IACvB,cAAc,GAAG,CAAC,CAAC;IACnB,aAAa,CAAe;IAC5B,aAAa,CAAqB;IAElC,YAAY,YAA0B;QACpC,6FAA6F;QAC7F,4FAA4F;QAC5F,uFAAuF;QACvF,gDAAgD;QAChD,IAAI,YAAY,CAAC,oBAAoB,IAAI,aAAa,CAAC,yBAAyB,EAAE;YAChF,YAAY,CAAC,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CACrC,aAAa,CAAC,yBAAyB,CAAC,kBAAkB,CACxD,YAAY,CAAC,oBAAoB,EACjC,GAAG,IAAI,CACR,CAAC;YACJ,YAAY,CAAC,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CACzC,aAAa,CAAC,yBAAyB,C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,cAAc,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE;YACrF,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,CAAC;SACpC;IACH,CAAC;IAED,kBAAkB,CAAC,YAA0B;QAC3C,MAAM,yBAAyB,GAAG,YAAY,CAAC,4BAA4B,CAAC,CAAC;QAC7E,IAAI,CAAC,yBAAyB,EAAE;YAC9B,OAAO;SACR;QAED,IAAI,QAAQ,IAAI,yBAAyB,EAAE;YACzC,iEAAiE;YACjE,yBAAyB,CAAC,MAAM,EAAE,CAAC;SACpC;aAAM,IAAI,oBAAoB,IAAI,IAAI,CAAC,aAAa,EAAE;YACrD,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC,yBAA0B,CAAC,CAAC;SACnE;QACD,IAAI,CAAC,cAAc,EAAE,CAAC;QAEtB,2FAA2F;QAC3F,0CAA0C;QAC1C,OAAO,YAAY,CAAC,4BAA4B,CAAC,CAAC;QAElD,gDAAgD;QAChD,YAAY,CAAC,MAAM,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;QAE/B,IAAI,CAAC,IAAI,CAAC,cAAc,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE;YACrF,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,CAAC;SACpC;IACH,CAAC;IAED,IAAI,CAAC,SAAiB,EAAE,GAAG,MAAa;QACtC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,MAAM,CAAC,CAAC;IAChD,CAAC;CACF","sourcesContent":["import invariant from 'invariant';\nimport { NativeEventEmitter, NativeModules, Platform } from 'react-native';\n\nconst nativeEmitterSubscriptionKey = '@@nativeEmitterSubscription@@';\n\ntype NativeModule = {\n __expo_module_name__?: string;\n startObserving?: () => void;\n stopObserving?: () => void;\n addListener: (eventName: string) => void;\n removeListeners: (count: number) => void;\n};\n\n// @needsAudit\nexport type Subscription = {\n /**\n * A method to unsubscribe the listener.\n */\n remove: () => void;\n};\n\nexport class EventEmitter {\n _listenerCount = 0;\n _nativeModule: NativeModule;\n _eventEmitter: NativeEventEmitter;\n\n constructor(nativeModule: NativeModule) {\n // Expo modules installed through the JSI don't have `addListener` and `removeListeners` set,\n // so if someone wants to use them with `EventEmitter`, make sure to provide these functions\n // as they are required by `NativeEventEmitter`. This is only temporary — in the future\n // JSI modules will have event emitter built in.\n if (nativeModule.__expo_module_name__ && NativeModules.EXReactNativeEventEmitter) {\n nativeModule.addListener = (...args) =>\n NativeModules.EXReactNativeEventEmitter.addProxiedListener(\n nativeModule.__expo_module_name__,\n ...args\n );\n nativeModule.removeListeners = (...args) =>\n NativeModules.EXReactNativeEventEmitter.removeProxiedListeners(\n nativeModule.__expo_module_name__,\n ...args\n );\n }\n this._nativeModule = nativeModule;\n this._eventEmitter = new NativeEventEmitter(nativeModule as any);\n }\n\n addListener<T>(eventName: string, listener: (event: T) => void): Subscription {\n if (!this._listenerCount && Platform.OS !== 'ios' && this._nativeModule.startObserving) {\n this._nativeModule.startObserving();\n }\n\n this._listenerCount++;\n const nativeEmitterSubscription = this._eventEmitter.addListener(eventName, listener);\n const subscription = {\n [nativeEmitterSubscriptionKey]: nativeEmitterSubscription,\n remove: () => {\n this.removeSubscription(subscription);\n },\n };\n return subscription;\n }\n\n removeAllListeners(eventName: string): void {\n // @ts-ignore: the EventEmitter interface has been changed in react-native@0.64.0\n const removedListenerCount = this._eventEmitter.listenerCount\n ? // @ts-ignore: this is available since 0.64\n this._eventEmitter.listenerCount(eventName)\n : // @ts-ignore: this is available in older versions\n this._eventEmitter.listeners(eventName).length;\n this._eventEmitter.removeAllListeners(eventName);\n this._listenerCount -= removedListenerCount;\n invariant(\n this._listenerCount >= 0,\n `EventEmitter must have a non-negative number of listeners`\n );\n\n if (!this._listenerCount && Platform.OS !== 'ios' && this._nativeModule.stopObserving) {\n this._nativeModule.stopObserving();\n }\n }\n\n removeSubscription(subscription: Subscription): void {\n const nativeEmitterSubscription = subscription[nativeEmitterSubscriptionKey];\n if (!nativeEmitterSubscription) {\n return;\n }\n\n if ('remove' in nativeEmitterSubscription) {\n // `react-native-web@0.17.1` doesn't support `removeSubscription`\n nativeEmitterSubscription.remove();\n } else if ('removeSubscription' in this._eventEmitter) {\n this._eventEmitter.removeSubscription(nativeEmitterSubscription!);\n }\n this._listenerCount--;\n\n // Ensure that the emitter's internal state remains correct even if `removeSubscription` is\n // called again with the same subscription\n delete subscription[nativeEmitterSubscriptionKey];\n\n // Release closed-over references to the emitter\n subscription.remove = () => {};\n\n if (!this._listenerCount && Platform.OS !== 'ios' && this._nativeModule.stopObserving) {\n this._nativeModule.stopObserving();\n }\n }\n\n emit(eventName: string, ...params: any[]): void {\n this._eventEmitter.emit(eventName, ...params);\n }\n}\n"]}
@@ -63,7 +63,14 @@ internal class InvalidArgsNumberException: GenericException<(received: Int, expe
63
63
 
64
64
  internal class ArgumentCastException: GenericException<(index: Int, type: AnyDynamicType)> {
65
65
  override var reason: String {
66
- "Argument at index '\(param.index)' couldn't be cast to type \(param.type.description)"
66
+ "The \(formatOrdinalNumber(param.index + 1)) argument cannot be cast to type \(param.type.description)"
67
+ }
68
+
69
+ func formatOrdinalNumber(_ number: Int) -> String {
70
+ let formatter = NumberFormatter()
71
+ formatter.numberStyle = .ordinal
72
+ formatter.locale = Locale(identifier: "en_US")
73
+ return formatter.string(from: NSNumber(value: number)) ?? ""
67
74
  }
68
75
  }
69
76
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-modules-core",
3
- "version": "1.0.1",
3
+ "version": "1.0.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": "^3.0.0"
44
44
  },
45
- "gitHead": "029acef85addf3f25136a50d0a7a178bd0b109dc"
45
+ "gitHead": "4cfefb886fd394c376290f24dabf987cdd6e6ca0"
46
46
  }
@@ -41,24 +41,6 @@ export class EventEmitter {
41
41
  ...args
42
42
  );
43
43
  }
44
- // Fix the `NativeEventEmitter` warnings on Android.
45
- // WARN `new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.
46
- // WARN `new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.
47
- if (Platform.OS === 'android') {
48
- Object.defineProperties(nativeModule, {
49
- addListener: {
50
- value: () => {},
51
- writable: true,
52
- enumerable: true,
53
- },
54
- removeListeners: {
55
- value: () => {},
56
- writable: true,
57
- enumerable: true,
58
- },
59
- });
60
- }
61
-
62
44
  this._nativeModule = nativeModule;
63
45
  this._eventEmitter = new NativeEventEmitter(nativeModule as any);
64
46
  }