-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathindex.js
118 lines (99 loc) · 3.96 KB
/
index.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { NativeModules, NativeEventEmitter, Platform } from "react-native";
const RNSiriShortcuts = NativeModules.RNSiriShortcuts || {};
export type ShortcutOptions = {
/** The activity type with which the user activity object was created. */
activityType: string,
/** An optional, user-visible title for this activity, such as a document name or web page title. */
title?: string,
/** A set of keys that represent the minimal information about the activity that should be stored for later restoration. */
requiredUserInfoKeys?: Array<string>,
/** A dictionary containing app-specific state information needed to continue an activity on another device. */
userInfo?: any,
/** Indicates that the state of the activity needs to be updated. */
needsSave?: boolean,
/** A set of localized keywords that can help users find the activity in search results. */
keywords?: Array<string>,
/** A value used to identify the user activity. */
persistentIdentifier?: string,
/** A Boolean value that indicates whether the activity can be continued on another device using Handoff. */
isEligibleForHandoff?: boolean,
/** A Boolean value that indicates whether the activity should be added to the on-device index. */
isEligibleForSearch?: boolean,
/** A Boolean value that indicates whether the activity can be publicly accessed by all iOS users. */
isEligibleForPublicIndexing?: boolean,
/** The date after which the activity is no longer eligible for Handoff or indexing. In ms since Unix Epox */
expirationDate?: number,
/** Webpage to load in a browser to continue the activity. */
webpageURL?: string,
/** A Boolean value that determines whether Siri can suggest the user activity as a shortcut to the user. */
isEligibleForPrediction?: boolean,
/** A phrase suggested to the user when they create a shortcut. */
suggestedInvocationPhrase?: string
};
export type PresentShortcutCallbackData = {
status: "cancelled" | "added" | "deleted" | "updated",
phrase: ?string
};
export type ShortcutData = {
identifier: string,
phrase: string,
options?: ShortcutOptions
};
export type ShortcutInfo = {
activityType: string,
userInfo: ?object,
}
const noop = () => ({});
const safeCall = (func, minVersion = 12) => {
if (
Platform.OS !== "ios" ||
Number.parseFloat(Platform.Version, 10) < minVersion
) {
return noop;
}
return func;
};
export const SiriShortcutsEvent = Platform.select({
ios: new NativeEventEmitter(RNSiriShortcuts),
android: {
addListener: () => ({remove: () => {}}),
removeListener: () => {},
removeAllListeners: () => {},
removeCurrentListener: () => {},
removeSubscription: () => {},
listeners: () => {}
}
});
/**
* @deprecated Please use `donateShortcut` instead.
*/
export const createShortcut = (opts: ShortcutOptions) => donateShortcut(opts);
export const donateShortcut = safeCall(
(opts: ShortcutOptions) => RNSiriShortcuts.donateShortcut(opts),
9
);
export const suggestShortcuts = safeCall((opts: Array<ShortcutOptions>) =>
RNSiriShortcuts.suggestShortcuts(opts)
);
export const clearAllShortcuts = safeCall(() =>
RNSiriShortcuts.clearAllShortcuts()
);
export const clearShortcutsWithIdentifiers = safeCall(
(identifiers: Array<string>) =>
RNSiriShortcuts.clearShortcutsWithIdentifiers(identifiers)
);
export const supportsPresentShortcut =
Platform.OS === "ios" && Number.parseFloat(Platform.Version) >= 12;
export const presentShortcut = safeCall(
(opts: ShortcutOptions, callback: () => PresentShortcutCallbackData) =>
RNSiriShortcuts.presentShortcut(opts, callback)
);
export const getShortcuts = safeCall(() => RNSiriShortcuts.getShortcuts());
export const getInitialShortcut = safeCall(() => RNSiriShortcuts.getInitialShortcut(), 9);
export const addShortcutListener = (callback: (shortcut: ShortcutInfo) => void) => {
return SiriShortcutsEvent.addListener("SiriShortcutListener", callback);
}
export {
default as AddToSiriButton,
SiriButtonStyles,
} from "./AddToSiriButton";