forked from achorein/expo-share-intent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExpoShareIntentModule.ts
55 lines (46 loc) · 1.63 KB
/
ExpoShareIntentModule.ts
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
53
54
55
import {
requireOptionalNativeModule,
EventEmitter,
Subscription,
} from "expo-modules-core";
import {
ChangeEventPayload,
StateEventPayload,
} from "./ExpoShareIntentModule.types";
import { getShareExtensionKey } from "./utils";
// Import the native module. it will be resolved on native platforms to ExpoShareIntentModule.ts
// It loads the native module object from the JSI or falls back to
// the bridge module (from NativeModulesProxy) if the remote debugger is on.
const ExpoShareIntentModule = requireOptionalNativeModule(
"ExpoShareIntentModule",
);
export default ExpoShareIntentModule;
export function getShareIntent(url = ""): string {
return ExpoShareIntentModule?.getShareIntent(url);
}
export function clearShareIntent(key: string) {
return ExpoShareIntentModule?.clearShareIntent(key ?? getShareExtensionKey());
}
export function hasShareIntent(key: string): boolean {
return ExpoShareIntentModule?.hasShareIntent(key ?? getShareExtensionKey());
}
const emitter = ExpoShareIntentModule
? new EventEmitter(ExpoShareIntentModule)
: null;
export function addErrorListener(
listener: (event: ChangeEventPayload) => void,
): Subscription | null {
return emitter?.addListener<ChangeEventPayload>("onError", listener) || null;
}
export function addChangeListener(
listener: (event: ChangeEventPayload) => void,
): Subscription | null {
return emitter?.addListener<ChangeEventPayload>("onChange", listener) || null;
}
export function addStateListener(
listener: (event: StateEventPayload) => void,
): Subscription | null {
return (
emitter?.addListener<StateEventPayload>("onStateChange", listener) || null
);
}