-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathindex.tsx
52 lines (46 loc) · 1.31 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {
NativeEventEmitter,
NativeModule,
NativeModules,
Platform,
TurboModule,
} from 'react-native';
import { onStoreAction } from './bridge';
const LINKING_ERROR =
"The package 'sovran-react-native' doesn't seem to be linked. Make sure: \n\n" +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo managed workflow\n';
const Sovran = NativeModules.Sovran as NativeModule;
type NativeModuleConstants = { ON_STORE_ACTION: string };
if (Sovran !== undefined && Sovran !== null) {
const { ON_STORE_ACTION } = ((
Sovran as unknown as TurboModule
).getConstants?.() as NativeModuleConstants) ?? {
ON_STORE_ACTION: '',
};
const SovranBridge = new NativeEventEmitter(Sovran);
// Listen to Native events
SovranBridge.addListener(
ON_STORE_ACTION,
(event: { type: string; payload: unknown }) => {
void (async () => {
try {
await onStoreAction(event.type, event.payload);
} catch (error) {
console.warn(error);
}
})();
}
);
} else {
console.warn(LINKING_ERROR);
}
export {
createStore,
type Store,
type Notify,
type Unsubscribe,
} from './store';
export { registerBridgeStore } from './bridge';
export * from './persistor';