react-native-notify-kit 10.4.5 → 10.4.6

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.
@@ -5,8 +5,9 @@ export interface NativeModuleConfig {
5
5
  nativeEvents: string[];
6
6
  }
7
7
  export default class NotifeeNativeModule {
8
- private _nativeModule;
9
- private _nativeEmitter;
8
+ private readonly _config;
9
+ private _nativeModule?;
10
+ private _nativeEmitter?;
10
11
  constructor(config: NativeModuleConfig);
11
12
  get emitter(): import("react-native/Libraries/vendor/emitter/EventEmitter").default;
12
13
  get native(): Spec;
@@ -4,23 +4,46 @@
4
4
  import NotifeeJSEventEmitter from './NotifeeJSEventEmitter';
5
5
  import { NativeEventEmitter, TurboModuleRegistry } from 'react-native';
6
6
  export default class NotifeeNativeModule {
7
+ _config;
7
8
  _nativeModule;
8
9
  _nativeEmitter;
9
10
  constructor(config) {
10
- this._nativeModule = TurboModuleRegistry.getEnforcing(config.nativeModuleName);
11
- // @ts-ignore - change here needs resolution https://github.com/DefinitelyTyped/DefinitelyTyped/pull/49560/files
12
- this._nativeEmitter = new NativeEventEmitter(this.native);
13
- for (let i = 0; i < config.nativeEvents.length; i++) {
14
- const eventName = config.nativeEvents[i];
15
- this._nativeEmitter.addListener(eventName, (payload) => {
16
- this.emitter.emit(eventName, payload);
17
- });
18
- }
11
+ // Defer all native access out of the constructor. The default export of this package is a
12
+ // singleton constructed at module-evaluation time, so resolving the TurboModule here meant
13
+ // it ran the instant `react-native-notify-kit` was imported. On the New Architecture in
14
+ // bridgeless mode, importing the package early (e.g. registering `onBackgroundEvent` at the
15
+ // top of index.js, before the app root mounts) executes before TurboModules are installed,
16
+ // so `getEnforcing` throws "NotifeeApiModule could not be found" / "runtime not ready" and
17
+ // the module is unusable for the whole session. Resolving lazily on first `.native` access
18
+ // defers it until a notifee method actually runs, when the TurboModule is available.
19
+ this._config = config;
19
20
  }
20
21
  get emitter() {
21
22
  return NotifeeJSEventEmitter;
22
23
  }
23
24
  get native() {
25
+ if (!this._nativeModule || !this._nativeEmitter) {
26
+ const nativeModule = TurboModuleRegistry.getEnforcing(this._config.nativeModuleName);
27
+ // @ts-ignore - change here needs resolution https://github.com/DefinitelyTyped/DefinitelyTyped/pull/49560/files
28
+ const nativeEmitter = new NativeEventEmitter(nativeModule);
29
+ const subscriptions = [];
30
+ try {
31
+ for (let i = 0; i < this._config.nativeEvents.length; i++) {
32
+ const eventName = this._config.nativeEvents[i];
33
+ subscriptions.push(nativeEmitter.addListener(eventName, (payload) => {
34
+ this.emitter.emit(eventName, payload);
35
+ }));
36
+ }
37
+ }
38
+ catch (error) {
39
+ for (let i = 0; i < subscriptions.length; i++) {
40
+ subscriptions[i].remove();
41
+ }
42
+ throw error;
43
+ }
44
+ this._nativeModule = nativeModule;
45
+ this._nativeEmitter = nativeEmitter;
46
+ }
24
47
  return this._nativeModule;
25
48
  }
26
49
  }
@@ -1 +1 @@
1
- {"version":3,"file":"NotifeeNativeModule.js","sourceRoot":"","sources":["../src/NotifeeNativeModule.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAqB,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAS1F,MAAM,CAAC,OAAO,OAAO,mBAAmB;IAC9B,aAAa,CAAO;IACpB,cAAc,CAAqB;IAE3C,YAAmB,MAA0B;QAC3C,IAAI,CAAC,aAAa,GAAG,mBAAmB,CAAC,YAAY,CAAO,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAErF,gHAAgH;QAChH,IAAI,CAAC,cAAc,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,MAAyC,CAAC,CAAC;QAC7F,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACpD,MAAM,SAAS,GAAG,MAAM,CAAC,YAAY,CAAC,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ACH,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;oBAC1D,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;oBAC/C,aAAa,CAAC,IAAI,CAChB,aAAa,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC,OAAY,EAAE,EAAE;wBACpD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;oBACxC,CAAC,CAAC,CACH,CAAC;gBACJ,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;oBAC9C,aAAa,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC5B,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;YAED,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;YAClC,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACtC,CAAC;QACD,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;CACF"}
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "10.4.5";
1
+ export declare const version = "10.4.6";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // Generated by genversion.
2
- export const version = '10.4.5';
2
+ export const version = '10.4.6';
3
3
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-notify-kit",
3
- "version": "10.4.5",
3
+ "version": "10.4.6",
4
4
  "author": "Marco Crupi",
5
5
  "description": "Maintained Notifee-compatible React Native notifications library for Android, iOS, FCM Mode, rich notifications, foreground services, and Expo CNG development builds.",
6
6
  "main": "dist/index.js",
@@ -13,20 +13,20 @@ export interface NativeModuleConfig {
13
13
  }
14
14
 
15
15
  export default class NotifeeNativeModule {
16
- private _nativeModule: Spec;
17
- private _nativeEmitter: NativeEventEmitter;
16
+ private readonly _config: NativeModuleConfig;
17
+ private _nativeModule?: Spec;
18
+ private _nativeEmitter?: NativeEventEmitter;
18
19
 
19
20
  public constructor(config: NativeModuleConfig) {
20
- this._nativeModule = TurboModuleRegistry.getEnforcing<Spec>(config.nativeModuleName);
21
-
22
- // @ts-ignore - change here needs resolution https://github.com/DefinitelyTyped/DefinitelyTyped/pull/49560/files
23
- this._nativeEmitter = new NativeEventEmitter(this.native as EventSubscription['subscriber']);
24
- for (let i = 0; i < config.nativeEvents.length; i++) {
25
- const eventName = config.nativeEvents[i];
26
- this._nativeEmitter.addListener(eventName, (payload: any) => {
27
- this.emitter.emit(eventName, payload);
28
- });
29
- }
21
+ // Defer all native access out of the constructor. The default export of this package is a
22
+ // singleton constructed at module-evaluation time, so resolving the TurboModule here meant
23
+ // it ran the instant `react-native-notify-kit` was imported. On the New Architecture in
24
+ // bridgeless mode, importing the package early (e.g. registering `onBackgroundEvent` at the
25
+ // top of index.js, before the app root mounts) executes before TurboModules are installed,
26
+ // so `getEnforcing` throws "NotifeeApiModule could not be found" / "runtime not ready" and
27
+ // the module is unusable for the whole session. Resolving lazily on first `.native` access
28
+ // defers it until a notifee method actually runs, when the TurboModule is available.
29
+ this._config = config;
30
30
  }
31
31
 
32
32
  public get emitter() {
@@ -34,6 +34,32 @@ export default class NotifeeNativeModule {
34
34
  }
35
35
 
36
36
  public get native(): Spec {
37
+ if (!this._nativeModule || !this._nativeEmitter) {
38
+ const nativeModule = TurboModuleRegistry.getEnforcing<Spec>(this._config.nativeModuleName);
39
+
40
+ // @ts-ignore - change here needs resolution https://github.com/DefinitelyTyped/DefinitelyTyped/pull/49560/files
41
+ const nativeEmitter = new NativeEventEmitter(nativeModule as EventSubscription['subscriber']);
42
+ const subscriptions: EventSubscription[] = [];
43
+
44
+ try {
45
+ for (let i = 0; i < this._config.nativeEvents.length; i++) {
46
+ const eventName = this._config.nativeEvents[i];
47
+ subscriptions.push(
48
+ nativeEmitter.addListener(eventName, (payload: any) => {
49
+ this.emitter.emit(eventName, payload);
50
+ }),
51
+ );
52
+ }
53
+ } catch (error) {
54
+ for (let i = 0; i < subscriptions.length; i++) {
55
+ subscriptions[i].remove();
56
+ }
57
+ throw error;
58
+ }
59
+
60
+ this._nativeModule = nativeModule;
61
+ this._nativeEmitter = nativeEmitter;
62
+ }
37
63
  return this._nativeModule;
38
64
  }
39
65
  }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '10.4.5';
2
+ export const version = '10.4.6';