@applicaster/zapp-react-native-utils 11.1.1 → 12.0.0-alpha.4534459584
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0-alpha.4534459584",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "
|
|
31
|
+
"@applicaster/applicaster-types": "12.0.0-alpha.4534459584",
|
|
32
32
|
"buffer": "^5.2.1",
|
|
33
33
|
"camelize": "^1.0.0",
|
|
34
34
|
"create-react-context": "^0.2.3",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { DeviceEventEmitter, NativeModules, Platform } from "react-native";
|
|
3
|
+
|
|
4
|
+
const { ReactNativeEventBusBridge } = NativeModules;
|
|
5
|
+
|
|
6
|
+
export const useListenEventBusEvent = (
|
|
7
|
+
subscriptionID: string, // subsciption ID to manage it, will be used as a event name for DeviceEventEmitter
|
|
8
|
+
source: string,
|
|
9
|
+
events: string[],
|
|
10
|
+
handler: (event) => void
|
|
11
|
+
) => {
|
|
12
|
+
React.useEffect(() => {
|
|
13
|
+
// TODO: remove after implementing ReactNativeEventBusBridge on iOS
|
|
14
|
+
if (Platform.OS === "android") {
|
|
15
|
+
// subscribe to DeviceEventEmitter using subsciption ID
|
|
16
|
+
const sub = DeviceEventEmitter.addListener(
|
|
17
|
+
subscriptionID,
|
|
18
|
+
handler
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
// ask native to start routing these events to RN
|
|
22
|
+
ReactNativeEventBusBridge.subscribe(subscriptionID, { [source]: events });
|
|
23
|
+
|
|
24
|
+
return () => {
|
|
25
|
+
ReactNativeEventBusBridge.unsubscribe(subscriptionID); // ask EventBus to stop routing these events to RN
|
|
26
|
+
sub.remove(); // stop listening to DeviceEventEmitter
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}, []);
|
|
30
|
+
};
|