@ng-native/device 0.22.2 → 0.23.0
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/dist/accessibility.d.ts +7 -0
- package/dist/accessibility.js +14 -2
- package/dist/accessibility.js.map +1 -1
- package/dist/app-lifecycle.d.ts +49 -0
- package/dist/app-lifecycle.js +67 -0
- package/dist/app-lifecycle.js.map +1 -0
- package/dist/app-state.d.ts +2 -0
- package/dist/app-state.js +2 -0
- package/dist/app-state.js.map +1 -1
- package/dist/app-windows.d.ts +321 -0
- package/dist/app-windows.js +526 -0
- package/dist/app-windows.js.map +1 -0
- package/dist/color-scheme.d.ts +2 -0
- package/dist/color-scheme.js +2 -0
- package/dist/color-scheme.js.map +1 -1
- package/dist/conditions.d.ts +11 -3
- package/dist/conditions.js +42 -9
- package/dist/conditions.js.map +1 -1
- package/dist/control-size.d.ts +6 -0
- package/dist/control-size.js +2 -0
- package/dist/control-size.js.map +1 -0
- package/dist/deep-links.d.ts +3 -1
- package/dist/deep-links.js +3 -1
- package/dist/deep-links.js.map +1 -1
- package/dist/desktop-options.d.ts +73 -0
- package/dist/desktop-options.js +182 -0
- package/dist/desktop-options.js.map +1 -0
- package/dist/desktop-permissions.d.ts +30 -0
- package/dist/desktop-permissions.js +169 -0
- package/dist/desktop-permissions.js.map +1 -0
- package/dist/dev-menu.d.ts +2 -2
- package/dist/dev-menu.js +3 -5
- package/dist/dev-menu.js.map +1 -1
- package/dist/dialogs.d.ts +9 -7
- package/dist/dialogs.js +15 -10
- package/dist/dialogs.js.map +1 -1
- package/dist/direction.d.ts +2 -0
- package/dist/direction.js +2 -0
- package/dist/direction.js.map +1 -1
- package/dist/dock.d.ts +48 -0
- package/dist/dock.js +70 -0
- package/dist/dock.js.map +1 -0
- package/dist/drag-and-drop.d.ts +67 -0
- package/dist/drag-and-drop.js +74 -0
- package/dist/drag-and-drop.js.map +1 -0
- package/dist/expo-view-name.d.ts +16 -0
- package/dist/expo-view-name.js +22 -0
- package/dist/expo-view-name.js.map +1 -0
- package/dist/hardware-back.d.ts +3 -10
- package/dist/hardware-back.js +4 -1
- package/dist/hardware-back.js.map +1 -1
- package/dist/index.d.ts +26 -2
- package/dist/index.js +26 -2
- package/dist/index.js.map +1 -1
- package/dist/interaction-observer.d.ts +117 -0
- package/dist/interaction-observer.js +241 -0
- package/dist/interaction-observer.js.map +1 -0
- package/dist/keyboard.d.ts +2 -8
- package/dist/keyboard.js +3 -0
- package/dist/keyboard.js.map +1 -1
- package/dist/layout-animation.d.ts +3 -1
- package/dist/layout-animation.js +3 -1
- package/dist/layout-animation.js.map +1 -1
- package/dist/menu-model.d.ts +108 -0
- package/dist/menu-model.js +259 -0
- package/dist/menu-model.js.map +1 -0
- package/dist/menu-template.d.ts +19 -0
- package/dist/menu-template.js +31 -0
- package/dist/menu-template.js.map +1 -0
- package/dist/menus.d.ts +225 -0
- package/dist/menus.js +341 -0
- package/dist/menus.js.map +1 -0
- package/dist/navigation-bar.d.ts +2 -12
- package/dist/navigation-bar.js +4 -1
- package/dist/navigation-bar.js.map +1 -1
- package/dist/os-support.d.ts +42 -0
- package/dist/os-support.js +207 -0
- package/dist/os-support.js.map +1 -0
- package/dist/os.d.ts +26 -5
- package/dist/os.js +35 -7
- package/dist/os.js.map +1 -1
- package/dist/own-host.d.ts +27 -0
- package/dist/own-host.js +79 -0
- package/dist/own-host.js.map +1 -0
- package/dist/processes.d.ts +116 -0
- package/dist/processes.js +177 -0
- package/dist/processes.js.map +1 -0
- package/dist/react-native.d.ts +19 -0
- package/dist/react-native.js.map +1 -1
- package/dist/safe-area.d.ts +12 -1
- package/dist/safe-area.js +16 -2
- package/dist/safe-area.js.map +1 -1
- package/dist/screen.d.ts +2 -0
- package/dist/screen.js +2 -0
- package/dist/screen.js.map +1 -1
- package/dist/sharing.d.ts +3 -1
- package/dist/sharing.js +8 -1
- package/dist/sharing.js.map +1 -1
- package/dist/shell.d.ts +33 -0
- package/dist/shell.js +73 -0
- package/dist/shell.js.map +1 -0
- package/dist/shortcut.d.ts +49 -0
- package/dist/shortcut.js +92 -0
- package/dist/shortcut.js.map +1 -0
- package/dist/sidebar-selection.d.ts +8 -0
- package/dist/sidebar-selection.js +9 -0
- package/dist/sidebar-selection.js.map +1 -0
- package/dist/spawn-rules.d.ts +108 -0
- package/dist/spawn-rules.js +313 -0
- package/dist/spawn-rules.js.map +1 -0
- package/dist/split-views.d.ts +7 -0
- package/dist/split-views.js +21 -0
- package/dist/split-views.js.map +1 -0
- package/dist/status-bar.d.ts +2 -12
- package/dist/status-bar.js +3 -0
- package/dist/status-bar.js.map +1 -1
- package/dist/tray.d.ts +63 -0
- package/dist/tray.js +76 -0
- package/dist/tray.js.map +1 -0
- package/dist/undo-stack.d.ts +64 -0
- package/dist/undo-stack.js +110 -0
- package/dist/undo-stack.js.map +1 -0
- package/dist/vibration.d.ts +3 -14
- package/dist/vibration.js +4 -1
- package/dist/vibration.js.map +1 -1
- package/dist/window-navigator.d.ts +25 -0
- package/dist/window-navigator.js +7 -0
- package/dist/window-navigator.js.map +1 -0
- package/dist/window-restore.d.ts +45 -0
- package/dist/window-restore.js +66 -0
- package/dist/window-restore.js.map +1 -0
- package/package.json +10 -2
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The permissions a macOS build declares, read from the Expo keys an app already sets for iOS: the
|
|
3
|
+
* usage strings in `ios.infoPlist` and each `expo-*` plugin's permission option. There is no
|
|
4
|
+
* second declaration for the desktop: an app that set `NSMicrophoneUsageDescription`, or
|
|
5
|
+
* expo-audio's `microphonePermission`, has declared the microphone on macOS too. Plain TypeScript
|
|
6
|
+
* with no imports, for the config plugin.
|
|
7
|
+
*/
|
|
8
|
+
/** What a macOS build declares for the permissions the app asks for. */
|
|
9
|
+
export interface MacosPermissions {
|
|
10
|
+
/** Info.plist usage strings, by key. */
|
|
11
|
+
readonly usageStrings: Readonly<Record<string, string>>;
|
|
12
|
+
/** The App Sandbox entitlements a `mas` build needs for them, sorted. */
|
|
13
|
+
readonly sandboxEntitlements: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
/** The part of an Expo config the permissions are read from. */
|
|
16
|
+
export interface ExpoPermissionConfig {
|
|
17
|
+
/** The app's name, which a plugin's default string and `$(PRODUCT_NAME)` stand for. */
|
|
18
|
+
readonly name?: string;
|
|
19
|
+
readonly ios?: {
|
|
20
|
+
readonly infoPlist?: Readonly<Record<string, unknown>>;
|
|
21
|
+
};
|
|
22
|
+
readonly plugins?: readonly unknown[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The usage strings and sandbox entitlements a macOS build declares, from the Expo config's
|
|
26
|
+
* `ios.infoPlist` and plugins. A plugin's option wins over the same key in `infoPlist`, which wins
|
|
27
|
+
* over the plugin's own default, as the plugin's iOS config does; `false` for an option leaves its
|
|
28
|
+
* key out. `$(PRODUCT_NAME)`, which Xcode fills in on iOS, is the app's name.
|
|
29
|
+
*/
|
|
30
|
+
export declare function macosPermissions(config: ExpoPermissionConfig): MacosPermissions;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The permissions a macOS build declares, read from the Expo keys an app already sets for iOS: the
|
|
3
|
+
* usage strings in `ios.infoPlist` and each `expo-*` plugin's permission option. There is no
|
|
4
|
+
* second declaration for the desktop: an app that set `NSMicrophoneUsageDescription`, or
|
|
5
|
+
* expo-audio's `microphonePermission`, has declared the microphone on macOS too. Plain TypeScript
|
|
6
|
+
* with no imports, for the config plugin.
|
|
7
|
+
*/
|
|
8
|
+
/** A plugin's default, as Expo writes it: `$(PRODUCT_NAME)` is the app's name. */
|
|
9
|
+
const allow = (what) => `Allow $(PRODUCT_NAME) to ${what}`;
|
|
10
|
+
const CAMERA = ['cameraPermission', 'NSCameraUsageDescription', allow('access your camera')];
|
|
11
|
+
const MICROPHONE = [
|
|
12
|
+
'microphonePermission',
|
|
13
|
+
'NSMicrophoneUsageDescription',
|
|
14
|
+
allow('access your microphone'),
|
|
15
|
+
];
|
|
16
|
+
const PHOTOS = [
|
|
17
|
+
'photosPermission',
|
|
18
|
+
'NSPhotoLibraryUsageDescription',
|
|
19
|
+
allow('access your photos'),
|
|
20
|
+
];
|
|
21
|
+
const LOCATION = (option, key) => [
|
|
22
|
+
option,
|
|
23
|
+
key,
|
|
24
|
+
allow('access your location'),
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* The usage strings each plugin writes, as its iOS config plugin does: the option's string, else
|
|
28
|
+
* what `ios.infoPlist` has, else the plugin's own default. Each default reads `Allow <app> to ...`.
|
|
29
|
+
*/
|
|
30
|
+
const PLUGIN_USAGE = {
|
|
31
|
+
'expo-camera': () => [CAMERA, MICROPHONE],
|
|
32
|
+
'expo-audio': () => [MICROPHONE],
|
|
33
|
+
'expo-image-picker': () => [PHOTOS, CAMERA, MICROPHONE],
|
|
34
|
+
'expo-media-library': () => [
|
|
35
|
+
PHOTOS,
|
|
36
|
+
['savePhotosPermission', 'NSPhotoLibraryAddUsageDescription', allow('save photos')],
|
|
37
|
+
],
|
|
38
|
+
'expo-location': () => [
|
|
39
|
+
LOCATION('locationAlwaysAndWhenInUsePermission', 'NSLocationAlwaysAndWhenInUseUsageDescription'),
|
|
40
|
+
LOCATION('locationAlwaysPermission', 'NSLocationAlwaysUsageDescription'),
|
|
41
|
+
LOCATION('locationWhenInUsePermission', 'NSLocationWhenInUseUsageDescription'),
|
|
42
|
+
],
|
|
43
|
+
'expo-calendar': (options) => [
|
|
44
|
+
['calendarPermission', 'NSCalendarsUsageDescription', allow('access your calendars')],
|
|
45
|
+
['remindersPermission', 'NSRemindersUsageDescription', allow('access your reminders')],
|
|
46
|
+
[
|
|
47
|
+
'remindersPermission',
|
|
48
|
+
'NSRemindersFullAccessUsageDescription',
|
|
49
|
+
allow('access your reminders'),
|
|
50
|
+
],
|
|
51
|
+
options['writeOnlyAccess']
|
|
52
|
+
? [
|
|
53
|
+
'writeOnlyCalendarPermission',
|
|
54
|
+
'NSCalendarsWriteOnlyAccessUsageDescription',
|
|
55
|
+
allow('add events to your calendars'),
|
|
56
|
+
]
|
|
57
|
+
: [
|
|
58
|
+
'calendarPermission',
|
|
59
|
+
'NSCalendarsFullAccessUsageDescription',
|
|
60
|
+
allow('access your calendars'),
|
|
61
|
+
],
|
|
62
|
+
],
|
|
63
|
+
'expo-contacts': () => [
|
|
64
|
+
['contactsPermission', 'NSContactsUsageDescription', allow('access your contacts')],
|
|
65
|
+
],
|
|
66
|
+
'expo-local-authentication': () => [
|
|
67
|
+
['faceIDPermission', 'NSFaceIDUsageDescription', allow('use Face ID')],
|
|
68
|
+
],
|
|
69
|
+
'expo-tracking-transparency': () => [
|
|
70
|
+
[
|
|
71
|
+
'userTrackingPermission',
|
|
72
|
+
'NSUserTrackingUsageDescription',
|
|
73
|
+
'Allow this app to collect app-related data that can be used for tracking you or your device.',
|
|
74
|
+
],
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* The App Sandbox entitlement each usage string needs in a sandboxed (`mas`) build, where macOS
|
|
79
|
+
* has one. A usage string with none, such as Face ID's, still goes in Info.plist.
|
|
80
|
+
*/
|
|
81
|
+
const SANDBOX_ENTITLEMENTS = {
|
|
82
|
+
NSCameraUsageDescription: 'com.apple.security.device.camera',
|
|
83
|
+
NSMicrophoneUsageDescription: 'com.apple.security.device.audio-input',
|
|
84
|
+
NSBluetoothAlwaysUsageDescription: 'com.apple.security.device.bluetooth',
|
|
85
|
+
NSPhotoLibraryUsageDescription: 'com.apple.security.personal-information.photos-library',
|
|
86
|
+
NSPhotoLibraryAddUsageDescription: 'com.apple.security.personal-information.photos-library',
|
|
87
|
+
NSLocationWhenInUseUsageDescription: 'com.apple.security.personal-information.location',
|
|
88
|
+
NSLocationAlwaysUsageDescription: 'com.apple.security.personal-information.location',
|
|
89
|
+
NSLocationAlwaysAndWhenInUseUsageDescription: 'com.apple.security.personal-information.location',
|
|
90
|
+
NSLocationUsageDescription: 'com.apple.security.personal-information.location',
|
|
91
|
+
NSCalendarsUsageDescription: 'com.apple.security.personal-information.calendars',
|
|
92
|
+
NSCalendarsFullAccessUsageDescription: 'com.apple.security.personal-information.calendars',
|
|
93
|
+
NSCalendarsWriteOnlyAccessUsageDescription: 'com.apple.security.personal-information.calendars',
|
|
94
|
+
NSRemindersUsageDescription: 'com.apple.security.personal-information.calendars',
|
|
95
|
+
NSRemindersFullAccessUsageDescription: 'com.apple.security.personal-information.calendars',
|
|
96
|
+
NSContactsUsageDescription: 'com.apple.security.personal-information.addressbook',
|
|
97
|
+
};
|
|
98
|
+
const USAGE_KEY = /^NS[A-Za-z]+UsageDescription$/;
|
|
99
|
+
/** The iOS location keys macOS's own takes its string from, in order of preference. */
|
|
100
|
+
const MACOS_LOCATION_FROM = [
|
|
101
|
+
'NSLocationWhenInUseUsageDescription',
|
|
102
|
+
'NSLocationAlwaysAndWhenInUseUsageDescription',
|
|
103
|
+
'NSLocationAlwaysUsageDescription',
|
|
104
|
+
];
|
|
105
|
+
/**
|
|
106
|
+
* The usage strings and sandbox entitlements a macOS build declares, from the Expo config's
|
|
107
|
+
* `ios.infoPlist` and plugins. A plugin's option wins over the same key in `infoPlist`, which wins
|
|
108
|
+
* over the plugin's own default, as the plugin's iOS config does; `false` for an option leaves its
|
|
109
|
+
* key out. `$(PRODUCT_NAME)`, which Xcode fills in on iOS, is the app's name.
|
|
110
|
+
*/
|
|
111
|
+
export function macosPermissions(config) {
|
|
112
|
+
const usageStrings = fromInfoPlist(config.ios?.infoPlist ?? {});
|
|
113
|
+
const defaulted = new Set();
|
|
114
|
+
for (const entry of config.plugins ?? [])
|
|
115
|
+
applyPlugin(usageStrings, defaulted, entry);
|
|
116
|
+
// macOS asks for location with NSLocationUsageDescription, which no iOS key or plugin option
|
|
117
|
+
// sets: it reads the app's own location string, one the app wrote before a plugin's default,
|
|
118
|
+
// unless the app gives the macOS key itself.
|
|
119
|
+
const location = [
|
|
120
|
+
...MACOS_LOCATION_FROM.filter((key) => !defaulted.has(key)),
|
|
121
|
+
...MACOS_LOCATION_FROM.filter((key) => defaulted.has(key)),
|
|
122
|
+
]
|
|
123
|
+
.map((key) => usageStrings[key])
|
|
124
|
+
.find(Boolean);
|
|
125
|
+
if (location !== undefined)
|
|
126
|
+
usageStrings['NSLocationUsageDescription'] ??= location;
|
|
127
|
+
const name = config.name ?? 'this app';
|
|
128
|
+
for (const [key, value] of Object.entries(usageStrings)) {
|
|
129
|
+
usageStrings[key] = value.replaceAll('$(PRODUCT_NAME)', name);
|
|
130
|
+
}
|
|
131
|
+
const entitlements = new Set(Object.keys(usageStrings)
|
|
132
|
+
.map((key) => SANDBOX_ENTITLEMENTS[key])
|
|
133
|
+
.filter((entitlement) => entitlement !== undefined));
|
|
134
|
+
return { usageStrings, sandboxEntitlements: [...entitlements].sort() };
|
|
135
|
+
}
|
|
136
|
+
/** The usage strings `ios.infoPlist` sets. */
|
|
137
|
+
function fromInfoPlist(infoPlist) {
|
|
138
|
+
const usageStrings = {};
|
|
139
|
+
for (const [key, value] of Object.entries(infoPlist)) {
|
|
140
|
+
if (USAGE_KEY.test(key) && typeof value === 'string' && value !== '')
|
|
141
|
+
usageStrings[key] = value;
|
|
142
|
+
}
|
|
143
|
+
return usageStrings;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Write the usage strings one `plugins` entry writes, or take away those it turns off. `defaulted`
|
|
147
|
+
* holds the keys that have a plugin's default rather than a string the app wrote.
|
|
148
|
+
*/
|
|
149
|
+
function applyPlugin(usageStrings, defaulted, entry) {
|
|
150
|
+
const [name, given] = Array.isArray(entry) ? entry : [entry, undefined];
|
|
151
|
+
const options = (typeof given === 'object' && given !== null ? given : {});
|
|
152
|
+
const usages = typeof name === 'string' ? PLUGIN_USAGE[name]?.(options) : undefined;
|
|
153
|
+
for (const [option, key, fallback] of usages ?? []) {
|
|
154
|
+
const value = options[option];
|
|
155
|
+
if (value === false) {
|
|
156
|
+
delete usageStrings[key];
|
|
157
|
+
defaulted.delete(key);
|
|
158
|
+
}
|
|
159
|
+
else if (typeof value === 'string' && value !== '') {
|
|
160
|
+
usageStrings[key] = value;
|
|
161
|
+
defaulted.delete(key);
|
|
162
|
+
}
|
|
163
|
+
else if (usageStrings[key] === undefined) {
|
|
164
|
+
usageStrings[key] = fallback;
|
|
165
|
+
defaulted.add(key);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=desktop-permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"desktop-permissions.js","sourceRoot":"","sources":["../src/desktop-permissions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,kFAAkF;AAClF,MAAM,KAAK,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,4BAA4B,IAAI,EAAE,CAAC;AAE3E,MAAM,MAAM,GAAU,CAAC,kBAAkB,EAAE,0BAA0B,EAAE,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC;AACpG,MAAM,UAAU,GAAU;IACxB,sBAAsB;IACtB,8BAA8B;IAC9B,KAAK,CAAC,wBAAwB,CAAC;CAChC,CAAC;AACF,MAAM,MAAM,GAAU;IACpB,kBAAkB;IAClB,gCAAgC;IAChC,KAAK,CAAC,oBAAoB,CAAC;CAC5B,CAAC;AACF,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,GAAW,EAAS,EAAE,CAAC;IACvD,MAAM;IACN,GAAG;IACH,KAAK,CAAC,sBAAsB,CAAC;CAC9B,CAAC;AAEF;;;GAGG;AACH,MAAM,YAAY,GAEd;IACF,aAAa,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC;IACzC,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC,UAAU,CAAC;IAChC,mBAAmB,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC;IACvD,oBAAoB,EAAE,GAAG,EAAE,CAAC;QAC1B,MAAM;QACN,C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C,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACxE,MAAM,OAAO,GAAG,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAGxE,CAAC;IACF,MAAM,MAAM,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACpF,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,IAAI,EAAE,EAAE,CAAC;QACnD,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAC9B,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YACpB,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;YACzB,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACxB,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;YACrD,YAAY,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YAC1B,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACxB,CAAC;aAAM,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;YAC3C,YAAY,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;YAC7B,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["/**\n * The permissions a macOS build declares, read from the Expo keys an app already sets for iOS: the\n * usage strings in `ios.infoPlist` and each `expo-*` plugin's permission option. There is no\n * second declaration for the desktop: an app that set `NSMicrophoneUsageDescription`, or\n * expo-audio's `microphonePermission`, has declared the microphone on macOS too. Plain TypeScript\n * with no imports, for the config plugin.\n */\n\n/** One usage string a plugin writes: the option it reads, the key, and its own default. */\ntype Usage = readonly [option: string, key: string, fallback: string];\n\n/** A plugin's default, as Expo writes it: `$(PRODUCT_NAME)` is the app's name. */\nconst allow = (what: string): string => `Allow $(PRODUCT_NAME) to ${what}`;\n\nconst CAMERA: Usage = ['cameraPermission', 'NSCameraUsageDescription', allow('access your camera')];\nconst MICROPHONE: Usage = [\n 'microphonePermission',\n 'NSMicrophoneUsageDescription',\n allow('access your microphone'),\n];\nconst PHOTOS: Usage = [\n 'photosPermission',\n 'NSPhotoLibraryUsageDescription',\n allow('access your photos'),\n];\nconst LOCATION = (option: string, key: string): Usage => [\n option,\n key,\n allow('access your location'),\n];\n\n/**\n * The usage strings each plugin writes, as its iOS config plugin does: the option's string, else\n * what `ios.infoPlist` has, else the plugin's own default. Each default reads `Allow <app> to ...`.\n */\nconst PLUGIN_USAGE: Readonly<\n Record<string, (options: Readonly<Record<string, unknown>>) => readonly Usage[]>\n> = {\n 'expo-camera': () => [CAMERA, MICROPHONE],\n 'expo-audio': () => [MICROPHONE],\n 'expo-image-picker': () => [PHOTOS, CAMERA, MICROPHONE],\n 'expo-media-library': () => [\n PHOTOS,\n ['savePhotosPermission', 'NSPhotoLibraryAddUsageDescription', allow('save photos')],\n ],\n 'expo-location': () => [\n LOCATION(\n 'locationAlwaysAndWhenInUsePermission',\n 'NSLocationAlwaysAndWhenInUseUsageDescription',\n ),\n LOCATION('locationAlwaysPermission', 'NSLocationAlwaysUsageDescription'),\n LOCATION('locationWhenInUsePermission', 'NSLocationWhenInUseUsageDescription'),\n ],\n 'expo-calendar': (options) => [\n ['calendarPermission', 'NSCalendarsUsageDescription', allow('access your calendars')],\n ['remindersPermission', 'NSRemindersUsageDescription', allow('access your reminders')],\n [\n 'remindersPermission',\n 'NSRemindersFullAccessUsageDescription',\n allow('access your reminders'),\n ],\n options['writeOnlyAccess']\n ? [\n 'writeOnlyCalendarPermission',\n 'NSCalendarsWriteOnlyAccessUsageDescription',\n allow('add events to your calendars'),\n ]\n : [\n 'calendarPermission',\n 'NSCalendarsFullAccessUsageDescription',\n allow('access your calendars'),\n ],\n ],\n 'expo-contacts': () => [\n ['contactsPermission', 'NSContactsUsageDescription', allow('access your contacts')],\n ],\n 'expo-local-authentication': () => [\n ['faceIDPermission', 'NSFaceIDUsageDescription', allow('use Face ID')],\n ],\n 'expo-tracking-transparency': () => [\n [\n 'userTrackingPermission',\n 'NSUserTrackingUsageDescription',\n 'Allow this app to collect app-related data that can be used for tracking you or your device.',\n ],\n ],\n};\n\n/**\n * The App Sandbox entitlement each usage string needs in a sandboxed (`mas`) build, where macOS\n * has one. A usage string with none, such as Face ID's, still goes in Info.plist.\n */\nconst SANDBOX_ENTITLEMENTS: Readonly<Record<string, string>> = {\n NSCameraUsageDescription: 'com.apple.security.device.camera',\n NSMicrophoneUsageDescription: 'com.apple.security.device.audio-input',\n NSBluetoothAlwaysUsageDescription: 'com.apple.security.device.bluetooth',\n NSPhotoLibraryUsageDescription: 'com.apple.security.personal-information.photos-library',\n NSPhotoLibraryAddUsageDescription: 'com.apple.security.personal-information.photos-library',\n NSLocationWhenInUseUsageDescription: 'com.apple.security.personal-information.location',\n NSLocationAlwaysUsageDescription: 'com.apple.security.personal-information.location',\n NSLocationAlwaysAndWhenInUseUsageDescription: 'com.apple.security.personal-information.location',\n NSLocationUsageDescription: 'com.apple.security.personal-information.location',\n NSCalendarsUsageDescription: 'com.apple.security.personal-information.calendars',\n NSCalendarsFullAccessUsageDescription: 'com.apple.security.personal-information.calendars',\n NSCalendarsWriteOnlyAccessUsageDescription: 'com.apple.security.personal-information.calendars',\n NSRemindersUsageDescription: 'com.apple.security.personal-information.calendars',\n NSRemindersFullAccessUsageDescription: 'com.apple.security.personal-information.calendars',\n NSContactsUsageDescription: 'com.apple.security.personal-information.addressbook',\n};\n\n/** What a macOS build declares for the permissions the app asks for. */\nexport interface MacosPermissions {\n /** Info.plist usage strings, by key. */\n readonly usageStrings: Readonly<Record<string, string>>;\n /** The App Sandbox entitlements a `mas` build needs for them, sorted. */\n readonly sandboxEntitlements: readonly string[];\n}\n\n/** The part of an Expo config the permissions are read from. */\nexport interface ExpoPermissionConfig {\n /** The app's name, which a plugin's default string and `$(PRODUCT_NAME)` stand for. */\n readonly name?: string;\n readonly ios?: { readonly infoPlist?: Readonly<Record<string, unknown>> };\n readonly plugins?: readonly unknown[];\n}\n\nconst USAGE_KEY = /^NS[A-Za-z]+UsageDescription$/;\n\n/** The iOS location keys macOS's own takes its string from, in order of preference. */\nconst MACOS_LOCATION_FROM = [\n 'NSLocationWhenInUseUsageDescription',\n 'NSLocationAlwaysAndWhenInUseUsageDescription',\n 'NSLocationAlwaysUsageDescription',\n] as const;\n\n/**\n * The usage strings and sandbox entitlements a macOS build declares, from the Expo config's\n * `ios.infoPlist` and plugins. A plugin's option wins over the same key in `infoPlist`, which wins\n * over the plugin's own default, as the plugin's iOS config does; `false` for an option leaves its\n * key out. `$(PRODUCT_NAME)`, which Xcode fills in on iOS, is the app's name.\n */\nexport function macosPermissions(config: ExpoPermissionConfig): MacosPermissions {\n const usageStrings = fromInfoPlist(config.ios?.infoPlist ?? {});\n const defaulted = new Set<string>();\n for (const entry of config.plugins ?? []) applyPlugin(usageStrings, defaulted, entry);\n // macOS asks for location with NSLocationUsageDescription, which no iOS key or plugin option\n // sets: it reads the app's own location string, one the app wrote before a plugin's default,\n // unless the app gives the macOS key itself.\n const location = [\n ...MACOS_LOCATION_FROM.filter((key) => !defaulted.has(key)),\n ...MACOS_LOCATION_FROM.filter((key) => defaulted.has(key)),\n ]\n .map((key) => usageStrings[key])\n .find(Boolean);\n if (location !== undefined) usageStrings['NSLocationUsageDescription'] ??= location;\n const name = config.name ?? 'this app';\n for (const [key, value] of Object.entries(usageStrings)) {\n usageStrings[key] = value.replaceAll('$(PRODUCT_NAME)', name);\n }\n const entitlements = new Set(\n Object.keys(usageStrings)\n .map((key) => SANDBOX_ENTITLEMENTS[key])\n .filter((entitlement): entitlement is string => entitlement !== undefined),\n );\n return { usageStrings, sandboxEntitlements: [...entitlements].sort() };\n}\n\n/** The usage strings `ios.infoPlist` sets. */\nfunction fromInfoPlist(infoPlist: Readonly<Record<string, unknown>>): Record<string, string> {\n const usageStrings: Record<string, string> = {};\n for (const [key, value] of Object.entries(infoPlist)) {\n if (USAGE_KEY.test(key) && typeof value === 'string' && value !== '') usageStrings[key] = value;\n }\n return usageStrings;\n}\n\n/**\n * Write the usage strings one `plugins` entry writes, or take away those it turns off. `defaulted`\n * holds the keys that have a plugin's default rather than a string the app wrote.\n */\nfunction applyPlugin(\n usageStrings: Record<string, string>,\n defaulted: Set<string>,\n entry: unknown,\n): void {\n const [name, given] = Array.isArray(entry) ? entry : [entry, undefined];\n const options = (typeof given === 'object' && given !== null ? given : {}) as Record<\n string,\n unknown\n >;\n const usages = typeof name === 'string' ? PLUGIN_USAGE[name]?.(options) : undefined;\n for (const [option, key, fallback] of usages ?? []) {\n const value = options[option];\n if (value === false) {\n delete usageStrings[key];\n defaulted.delete(key);\n } else if (typeof value === 'string' && value !== '') {\n usageStrings[key] = value;\n defaulted.delete(key);\n } else if (usageStrings[key] === undefined) {\n usageStrings[key] = fallback;\n defaulted.add(key);\n }\n }\n}\n"]}
|
package/dist/dev-menu.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* `addMenuItem` is a no-op there, but an app that registers twenty of them is still doing twenty
|
|
10
10
|
* things at startup for no reason.
|
|
11
11
|
*/
|
|
12
|
-
import { InjectionToken } from '@angular/core';
|
|
12
|
+
import { InjectionToken, type Signal } from '@angular/core';
|
|
13
13
|
import * as i0 from "@angular/core";
|
|
14
14
|
export interface NativeDevMenu {
|
|
15
15
|
addMenuItem(title: string, handler: () => unknown): void;
|
|
@@ -30,7 +30,7 @@ export declare class DevMenu {
|
|
|
30
30
|
static readonly SOURCE: InjectionToken<DevMenuSource>;
|
|
31
31
|
private readonly source;
|
|
32
32
|
/** Whether anything registered here will appear. False in a release build. */
|
|
33
|
-
|
|
33
|
+
readonly available: Signal<boolean>;
|
|
34
34
|
/**
|
|
35
35
|
* Add an item to the shake menu.
|
|
36
36
|
*
|
package/dist/dev-menu.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* `addMenuItem` is a no-op there, but an app that registers twenty of them is still doing twenty
|
|
10
10
|
* things at startup for no reason.
|
|
11
11
|
*/
|
|
12
|
-
import { InjectionToken, Service, inject } from '@angular/core';
|
|
12
|
+
import { InjectionToken, Service, inject, signal } from '@angular/core';
|
|
13
13
|
import { reactNative } from "./react-native.js";
|
|
14
14
|
import * as i0 from "@angular/core";
|
|
15
15
|
/**
|
|
@@ -50,9 +50,7 @@ export class DevMenu {
|
|
|
50
50
|
});
|
|
51
51
|
source = inject(DevMenu.SOURCE);
|
|
52
52
|
/** Whether anything registered here will appear. False in a release build. */
|
|
53
|
-
|
|
54
|
-
return this.source.development && this.source.menu !== null;
|
|
55
|
-
}
|
|
53
|
+
available = signal(this.source.development && this.source.menu !== null).asReadonly();
|
|
56
54
|
/**
|
|
57
55
|
* Add an item to the shake menu.
|
|
58
56
|
*
|
|
@@ -63,7 +61,7 @@ export class DevMenu {
|
|
|
63
61
|
* than being silently dropped.
|
|
64
62
|
*/
|
|
65
63
|
add(title, handler) {
|
|
66
|
-
if (!this.available)
|
|
64
|
+
if (!this.available())
|
|
67
65
|
return;
|
|
68
66
|
this.source.menu.addMenuItem(title, handler);
|
|
69
67
|
}
|
package/dist/dev-menu.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-menu.js","sourceRoot":"","sources":["../src/dev-menu.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"dev-menu.js","sourceRoot":"","sources":["../src/dev-menu.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EA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M,CAAC,WAAW,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CACrD,CAAC,UAAU,EAAE,CAAC;IAEf;;;;;;;;OAQG;IACH,GAAG,CAAC,KAAa,EAAE,OAAsB;QACvC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YAAE,OAAO;QAC9B,IAAI,CAAC,MAAM,CAAC,IAAK,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;IAED,sDAAsD;IACtD,MAAM,CAAC,MAAM,GAAG,sBAAsB;QACpC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;uGApCU,OAAO;wGAAP,OAAO;;2FAAP,OAAO;kBADnB,OAAO","sourcesContent":["/**\n * The developer menu, for the switches an app wants while it is being built.\n *\n * A feature flag, a fake slow network, \"log the current state\", \"clear the database\" - the things\n * a team otherwise builds a hidden settings screen for and then has to remember not to ship. These\n * go in the shake menu, which does not exist in a release build, so neither do they.\n *\n * `__DEV__` is checked rather than assumed: `DevSettings` exists in a release bundle and its\n * `addMenuItem` is a no-op there, but an app that registers twenty of them is still doing twenty\n * things at startup for no reason.\n */\n\nimport { InjectionToken, Service, inject, signal, type Signal } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport interface NativeDevMenu {\n addMenuItem(title: string, handler: () => unknown): void;\n reload(reason?: string): void;\n}\n\n/**\n * The menu, and whether there is one to add to.\n *\n * `__DEV__` travels with the module rather than being read from the global inside the class, so a\n * test can say \"this is a release build\" without writing to `globalThis` and putting it back.\n */\nexport interface DevMenuSource {\n readonly menu: NativeDevMenu | null;\n readonly development: boolean;\n}\n\n/**\n * React Native's menu, reloading the way Metro's Fast Refresh runtime does.\n *\n * `DevSettings.reload()` brings an app in Expo Go back without Expo's native modules (`Cannot find\n * native module 'ExpoFontLoader'`) until Expo Go is relaunched. In development `@ng-native/platform`\n * routes the refresh runtime's full reload through Expo's `reloadAppAsync()` in an Expo app, falling\n * back to React Native's, so this reloads through it. Neither this package nor the bundle it is in\n * names `expo` for that: an app on the web, or without Expo, has none to resolve. Outside\n * development, or without the runtime, it is React Native's reload, which does nothing in a release\n * build, where Expo's would restart the app.\n */\nfunction throughRefreshRuntime(settings: NativeDevMenu): NativeDevMenu {\n return {\n addMenuItem: (title, handler) => settings.addMenuItem(title, handler),\n reload: (reason) => {\n const scope = globalThis as {\n __METRO_GLOBAL_PREFIX__?: string;\n __DEV__?: boolean;\n } & Record<string, unknown>;\n const refresh = scope[`${scope.__METRO_GLOBAL_PREFIX__ ?? ''}__ReactRefresh`] as\n { performFullRefresh?: (reason: string) => void } | undefined;\n if (scope.__DEV__ === true && refresh?.performFullRefresh) {\n refresh.performFullRefresh(reason ?? 'requested by the app');\n } else settings.reload(reason);\n },\n };\n}\n\n@Service()\nexport class DevMenu {\n /** Overridden in a test to register items without a shake menu. */\n static readonly SOURCE = new InjectionToken<DevMenuSource>('angular-native.devMenuSource', {\n factory: () => {\n const settings = reactNative()?.DevSettings;\n return {\n menu: settings ? throughRefreshRuntime(settings) : null,\n development: (globalThis as { __DEV__?: boolean }).__DEV__ === true,\n };\n },\n });\n\n private readonly source = inject(DevMenu.SOURCE);\n\n /** Whether anything registered here will appear. False in a release build. */\n readonly available: Signal<boolean> = signal(\n this.source.development && this.source.menu !== null,\n ).asReadonly();\n\n /**\n * Add an item to the shake menu.\n *\n * `DevSettings.addMenuItem` already keys on `title` and swaps in the new handler without adding\n * a second native entry - it removes its own previous listener for that title before adding the\n * one just given - so registering the same title again, as a hot reload does when it re-runs the\n * constructor that calls `add()`, is exactly how the fresh handler replaces the stale one rather\n * than being silently dropped.\n */\n add(title: string, handler: () => unknown): void {\n if (!this.available()) return;\n this.source.menu!.addMenuItem(title, handler);\n }\n\n /** Reload the bundle, as the menu's own item does. */\n reload(reason = 'requested by the app'): void {\n this.source.menu?.reload(reason);\n }\n}\n"]}
|
package/dist/dialogs.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* has none. `choose` and `notify` pick per platform, so an app writes the intent rather than the
|
|
12
12
|
* platform - and the one thing neither can do is fail silently on the platform it is not for.
|
|
13
13
|
*/
|
|
14
|
-
import { InjectionToken } from '@angular/core';
|
|
14
|
+
import { InjectionToken, type Signal } from '@angular/core';
|
|
15
15
|
import { type ReactNative } from './react-native.ts';
|
|
16
16
|
import * as i0 from "@angular/core";
|
|
17
17
|
/** One choice in a dialog or an action sheet. */
|
|
@@ -47,6 +47,8 @@ export declare class Dialogs {
|
|
|
47
47
|
/** Overridden in a test to answer a dialog without one being shown. */
|
|
48
48
|
static readonly SOURCE: InjectionToken<NativeDialogs | null>;
|
|
49
49
|
private readonly native;
|
|
50
|
+
/** Whether React Native's module is here. Where it is not, every call is inert. */
|
|
51
|
+
readonly available: Signal<boolean>;
|
|
50
52
|
/** Say something, and wait until it has been read. Resolves when the dialog is dismissed. */
|
|
51
53
|
tell(title: string, message?: string, dismiss?: string): Promise<void>;
|
|
52
54
|
/**
|
|
@@ -65,9 +67,9 @@ export declare class Dialogs {
|
|
|
65
67
|
/**
|
|
66
68
|
* Ask for a line of text. Resolves to null if they cancelled.
|
|
67
69
|
*
|
|
68
|
-
* iOS only: `Alert.prompt` has no Android equivalent, and inventing one out of a modal
|
|
69
|
-
* text input would be a dialog that looks nothing like the platform's. On Android this
|
|
70
|
-
* to null so a caller can fall back to a screen of its own.
|
|
70
|
+
* iOS and macOS only: `Alert.prompt` has no Android equivalent, and inventing one out of a modal
|
|
71
|
+
* and a text input would be a dialog that looks nothing like the platform's. On Android this
|
|
72
|
+
* resolves to null so a caller can fall back to a screen of its own.
|
|
71
73
|
*/
|
|
72
74
|
ask(title: string, options?: {
|
|
73
75
|
message?: string;
|
|
@@ -101,9 +103,9 @@ export declare class Dialogs {
|
|
|
101
103
|
/**
|
|
102
104
|
* The platform's dialogs, from React Native's own modules.
|
|
103
105
|
*
|
|
104
|
-
* `Alert.prompt` and `ActionSheetIOS`
|
|
105
|
-
* left absent rather than shimmed, which is what lets `ask`, `choose` and `notify`
|
|
106
|
-
* what to do about it.
|
|
106
|
+
* `Alert.prompt` is iOS and macOS only, `ActionSheetIOS` iOS only and `ToastAndroid` Android
|
|
107
|
+
* only; each is left absent rather than shimmed, which is what lets `ask`, `choose` and `notify`
|
|
108
|
+
* above decide what to do about it.
|
|
107
109
|
*
|
|
108
110
|
* Which platform it is has to be asked outright, because React Native's own modules do not answer
|
|
109
111
|
* it. `react-native` exports `ActionSheetIOS` on Android too - the object is there and so is
|
package/dist/dialogs.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* has none. `choose` and `notify` pick per platform, so an app writes the intent rather than the
|
|
12
12
|
* platform - and the one thing neither can do is fail silently on the platform it is not for.
|
|
13
13
|
*/
|
|
14
|
-
import { InjectionToken, Service, inject } from '@angular/core';
|
|
14
|
+
import { InjectionToken, Service, inject, signal } from '@angular/core';
|
|
15
15
|
import { reactNative } from "./react-native.js";
|
|
16
16
|
import * as i0 from "@angular/core";
|
|
17
17
|
/**
|
|
@@ -26,6 +26,8 @@ export class Dialogs {
|
|
|
26
26
|
factory: () => dialogSource(reactNative()),
|
|
27
27
|
});
|
|
28
28
|
native = inject(Dialogs.SOURCE);
|
|
29
|
+
/** Whether React Native's module is here. Where it is not, every call is inert. */
|
|
30
|
+
available = signal(this.native !== null).asReadonly();
|
|
29
31
|
/** Say something, and wait until it has been read. Resolves when the dialog is dismissed. */
|
|
30
32
|
tell(title, message, dismiss = 'OK') {
|
|
31
33
|
return new Promise((resolve) => {
|
|
@@ -59,9 +61,9 @@ export class Dialogs {
|
|
|
59
61
|
/**
|
|
60
62
|
* Ask for a line of text. Resolves to null if they cancelled.
|
|
61
63
|
*
|
|
62
|
-
* iOS only: `Alert.prompt` has no Android equivalent, and inventing one out of a modal
|
|
63
|
-
* text input would be a dialog that looks nothing like the platform's. On Android this
|
|
64
|
-
* to null so a caller can fall back to a screen of its own.
|
|
64
|
+
* iOS and macOS only: `Alert.prompt` has no Android equivalent, and inventing one out of a modal
|
|
65
|
+
* and a text input would be a dialog that looks nothing like the platform's. On Android this
|
|
66
|
+
* resolves to null so a caller can fall back to a screen of its own.
|
|
65
67
|
*/
|
|
66
68
|
ask(title, options = {}) {
|
|
67
69
|
return new Promise((resolve) => {
|
|
@@ -108,7 +110,8 @@ export class Dialogs {
|
|
|
108
110
|
*
|
|
109
111
|
* Android's dialog holds three buttons: a negative, a neutral and a positive. Anything past
|
|
110
112
|
* that is dropped by the platform without a word, and a choice the user cannot see is worse
|
|
111
|
-
* than a list that refused to open, so it says so.
|
|
113
|
+
* than a list that refused to open, so it says so. A Mac's alert, the same call, has a
|
|
114
|
+
* button for every choice, with Cancel bound to Escape.
|
|
112
115
|
*/
|
|
113
116
|
const buttons = choices.map((choice, index) => ({
|
|
114
117
|
text: choice.label,
|
|
@@ -118,7 +121,7 @@ export class Dialogs {
|
|
|
118
121
|
if (cancelAt < 0) {
|
|
119
122
|
buttons.push({ text: 'Cancel', style: 'cancel', onPress: () => resolve(null) });
|
|
120
123
|
}
|
|
121
|
-
if (buttons.length > 3) {
|
|
124
|
+
if (this.native.platform === 'android' && buttons.length > 3) {
|
|
122
125
|
console.error(`[angular-native] Dialogs.choose was given ${choices.length} choices and Android shows ` +
|
|
123
126
|
'at most three buttons, counting the cancel. The rest will not appear. Use a ' +
|
|
124
127
|
'`ui-select` or an `action-sheet`-shaped list for anything longer.');
|
|
@@ -145,9 +148,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
|
|
|
145
148
|
/**
|
|
146
149
|
* The platform's dialogs, from React Native's own modules.
|
|
147
150
|
*
|
|
148
|
-
* `Alert.prompt` and `ActionSheetIOS`
|
|
149
|
-
* left absent rather than shimmed, which is what lets `ask`, `choose` and `notify`
|
|
150
|
-
* what to do about it.
|
|
151
|
+
* `Alert.prompt` is iOS and macOS only, `ActionSheetIOS` iOS only and `ToastAndroid` Android
|
|
152
|
+
* only; each is left absent rather than shimmed, which is what lets `ask`, `choose` and `notify`
|
|
153
|
+
* above decide what to do about it.
|
|
151
154
|
*
|
|
152
155
|
* Which platform it is has to be asked outright, because React Native's own modules do not answer
|
|
153
156
|
* it. `react-native` exports `ActionSheetIOS` on Android too - the object is there and so is
|
|
@@ -162,13 +165,15 @@ export function dialogSource(native) {
|
|
|
162
165
|
if (!native)
|
|
163
166
|
return null;
|
|
164
167
|
const ios = native.Platform.OS === 'ios';
|
|
168
|
+
// A Mac's alert module is iOS's, and React Native's `Alert.prompt` takes its iOS body there.
|
|
169
|
+
const apple = ios || native.Platform.OS === 'macos';
|
|
165
170
|
const android = native.Platform.OS === 'android';
|
|
166
171
|
return {
|
|
167
172
|
platform: native.Platform.OS,
|
|
168
173
|
alert: (title, message, buttons) => native.Alert.alert(title, message, [...buttons]),
|
|
169
174
|
// Buttons rather than a callback: given a callback, `Alert.prompt` answers OK alone, and the
|
|
170
175
|
// Cancel the native alert adds calls nothing, so a cancelled `ask` never settled.
|
|
171
|
-
...(
|
|
176
|
+
...(apple && native.Alert.prompt
|
|
172
177
|
? {
|
|
173
178
|
prompt: (title, message, onResult, defaultValue) => native.Alert.prompt(title, message, [
|
|
174
179
|
{ text: 'Cancel', style: 'cancel', onPress: () => onResult(null) },
|
package/dist/dialogs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialogs.js","sourceRoot":"","sources":["../src/dialogs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,WAAW,EAAoB,MAAM,mBAAmB,CAAC;;AAmClE;;;;;GAKG;AAEH,MAAM,OAAO,OAAO;IAClB,uEAAuE;IACvE,MAAM,CAAU,MAAM,GAAG,IAAI,cAAc,CAAuB,6BAA6B,EAAE;QAC/F,OAAO,EAAE,GAAG,EAAE,CAAC,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E,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE;iBAC1D,EACD,SAAS,EACT,YAAY,CACb;aACJ;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,GAAG,IAAI,MAAM,CAAC,cAAc;YAC9B,CAAC,CAAC;gBACE,WAAW,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,CACjC,MAAM,CAAC,cAAe,CAAC,0BAA0B,CAAC,OAAO,EAAE,QAAQ,CAAC;aACvE;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,OAAO,IAAI,MAAM,CAAC,YAAY;YAChC,CAAC,CAAC;gBACE,KAAK,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CACvB,MAAM,CAAC,YAAa,CAAC,IAAI,CACvB,OAAO,EACP,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,YAAa,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,YAAa,CAAC,KAAK,CAC9D;aACJ;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The platform's own dialogs: an alert, a confirmation, a prompt, an action sheet, a toast.\n *\n * All of these are callback APIs, and the reason to wrap them is that **a dialog is a question**.\n * `Alert.alert` hands its answer to one of several `onPress` callbacks, so asking something and\n * acting on the answer means splitting one thought across three functions. A promise puts it back\n * together, and `await` at the call site reads like what it is.\n *\n * The platform split is the other half. An action sheet is iOS's way of offering a short list of\n * choices and Android's is a dialog; a toast is Android's way of saying something small and iOS\n * has none. `choose` and `notify` pick per platform, so an app writes the intent rather than the\n * platform - and the one thing neither can do is fail silently on the platform it is not for.\n */\n\nimport { InjectionToken, Service, inject } from '@angular/core';\nimport { reactNative, type ReactNative } from './react-native.ts';\n\n/** One choice in a dialog or an action sheet. */\nexport interface Choice {\n readonly label: string;\n /** `cancel` is dismissal; `destructive` is the one the platform paints red. */\n readonly style?: 'default' | 'cancel' | 'destructive';\n}\n\nexport interface NativeDialogs {\n readonly platform: 'ios' | 'android' | string;\n alert(\n title: string,\n message: string | undefined,\n buttons: readonly { text: string; style?: string; onPress?: () => void }[],\n ): void;\n prompt?(\n title: string,\n message: string | undefined,\n onResult: (value: string | null) => void,\n defaultValue?: string,\n ): void;\n actionSheet?(\n options: {\n title?: string;\n message?: string;\n options: string[];\n cancelButtonIndex: number;\n destructiveButtonIndex?: number;\n },\n onSelect: (index: number) => void,\n ): void;\n toast?(message: string, long: boolean): void;\n}\n\n/**\n * `inject(Dialogs).confirm('Delete this?', { destructive: true })`.\n *\n * A dialog is a question, so every method here resolves to the answer rather than handing it to\n * one of several callbacks.\n */\n@Service()\nexport class Dialogs {\n /** Overridden in a test to answer a dialog without one being shown. */\n static readonly SOURCE = new InjectionToken<NativeDialogs | null>('angular-native.dialogSource', {\n factory: () => dialogSource(reactNative()),\n });\n\n private readonly native = inject(Dialogs.SOURCE);\n\n /** Say something, and wait until it has been read. Resolves when the dialog is dismissed. */\n tell(title: string, message?: string, dismiss = 'OK'): Promise<void> {\n return new Promise((resolve) => {\n if (!this.native) return resolve();\n this.native.alert(title, message, [{ text: dismiss, onPress: () => resolve() }]);\n });\n }\n\n /**\n * Ask something with two answers. Resolves to whether they agreed.\n *\n * `destructive` paints the confirm button as the platform paints a delete, and puts cancel where\n * the platform puts it - which on iOS is the *right*, so a confirmation dialog does not train\n * people to tap the wrong thing.\n */\n confirm(\n title: string,\n options: { message?: string; confirm?: string; cancel?: string; destructive?: boolean } = {},\n ): Promise<boolean> {\n const { message, confirm = 'OK', cancel = 'Cancel', destructive = false } = options;\n return new Promise((resolve) => {\n if (!this.native) return resolve(false);\n this.native.alert(title, message, [\n { text: cancel, style: 'cancel', onPress: () => resolve(false) },\n {\n text: confirm,\n style: destructive ? 'destructive' : 'default',\n onPress: () => resolve(true),\n },\n ]);\n });\n }\n\n /**\n * Ask for a line of text. Resolves to null if they cancelled.\n *\n * iOS only: `Alert.prompt` has no Android equivalent, and inventing one out of a modal and a\n * text input would be a dialog that looks nothing like the platform's. On Android this resolves\n * to null so a caller can fall back to a screen of its own.\n */\n ask(title: string, options: { message?: string; value?: string } = {}): Promise<string | null> {\n return new Promise((resolve) => {\n if (!this.native?.prompt) return resolve(null);\n this.native.prompt(title, options.message, resolve, options.value);\n });\n }\n\n /**\n * Offer a short list of choices. Resolves to the index chosen, or null if dismissed.\n *\n * An action sheet on iOS and a dialog on Android, because that is what each platform means by\n * this. A `cancel` choice is where the platform puts cancel rather than in the list.\n *\n * `message` is the smaller line under the title, the one that says what a destructive choice\n * does: the action sheet's message on iOS and the dialog's message on Android.\n */\n choose(\n title: string,\n choices: readonly Choice[],\n options: { message?: string } = {},\n ): Promise<number | null> {\n const { message } = options;\n const cancelAt = choices.findIndex((choice) => choice.style === 'cancel');\n const destructiveAt = choices.findIndex((choice) => choice.style === 'destructive');\n\n return new Promise((resolve) => {\n if (!this.native) return resolve(null);\n\n if (this.native.actionSheet) {\n // iOS wants cancel last and named by index; a list with none gets one, because an action\n // sheet with no way out is one the user has to guess at.\n const labels = choices.map((choice) => choice.label);\n const cancelIndex = cancelAt >= 0 ? cancelAt : labels.push('Cancel') - 1;\n this.native.actionSheet(\n {\n title,\n ...(message !== undefined ? { message } : {}),\n options: labels,\n cancelButtonIndex: cancelIndex,\n ...(destructiveAt >= 0 ? { destructiveButtonIndex: destructiveAt } : {}),\n },\n (index) => resolve(index === cancelIndex ? null : index),\n );\n return;\n }\n\n /*\n * Android's alert is put up `cancelable: false` by React Native, so a press outside does\n * nothing and neither does the back button. Without a cancel among the choices there is no\n * way at all to decline - the user has to pick something - so one is appended, exactly as\n * the iOS branch above does for the same reason.\n *\n * Android's dialog holds three buttons: a negative, a neutral and a positive. Anything past\n * that is dropped by the platform without a word, and a choice the user cannot see is worse\n * than a list that refused to open, so it says so.\n */\n const buttons = choices.map((choice, index) => ({\n text: choice.label,\n style: choice.style,\n onPress: () => resolve(choice.style === 'cancel' ? null : index),\n }));\n if (cancelAt < 0) {\n buttons.push({ text: 'Cancel', style: 'cancel', onPress: () => resolve(null) });\n }\n if (buttons.length > 3) {\n console.error(\n `[angular-native] Dialogs.choose was given ${choices.length} choices and Android shows ` +\n 'at most three buttons, counting the cancel. The rest will not appear. Use a ' +\n '`ui-select` or an `action-sheet`-shaped list for anything longer.',\n );\n }\n this.native.alert(title, message, buttons);\n });\n }\n\n /**\n * Say something small and transient.\n *\n * A toast on Android. iOS has no such thing and never has, so this does nothing there rather\n * than putting up a modal alert for something that did not warrant interrupting anyone - and an\n * app that must be seen should use `tell`.\n */\n notify(message: string, options: { long?: boolean } = {}): void {\n this.native?.toast?.(message, options.long ?? false);\n }\n}\n\n/**\n * The platform's dialogs, from React Native's own modules.\n *\n * `Alert.prompt` and `ActionSheetIOS` are iOS-only and `ToastAndroid` is Android-only; each is\n * left absent rather than shimmed, which is what lets `ask`, `choose` and `notify` above decide\n * what to do about it.\n *\n * Which platform it is has to be asked outright, because React Native's own modules do not answer\n * it. `react-native` exports `ActionSheetIOS` on Android too - the object is there and so is\n * `showActionSheetWithOptions`; only the TurboModule underneath is null, and the invariant that\n * catches that throws out of the promise `choose` returns, so a press did nothing at all and said\n * nothing about it. `Alert.prompt` is worse: it exists on Android and its body is one\n * `Platform.OS === 'ios'` check, so it returns having called no callback and the promise `ask`\n * returns never settles. `ToastAndroid` is the mirror image on iOS. Presence is not capability\n * here; only the platform name is.\n */\nexport function dialogSource(\n native: Pick<ReactNative, 'Platform' | 'Alert' | 'ActionSheetIOS' | 'ToastAndroid'> | null,\n): NativeDialogs | null {\n if (!native) return null;\n\n const ios = native.Platform.OS === 'ios';\n const android = native.Platform.OS === 'android';\n\n return {\n platform: native.Platform.OS,\n alert: (title, message, buttons) => native.Alert.alert(title, message, [...buttons]),\n // Buttons rather than a callback: given a callback, `Alert.prompt` answers OK alone, and the\n // Cancel the native alert adds calls nothing, so a cancelled `ask` never settled.\n ...(ios && native.Alert.prompt\n ? {\n prompt: (title, message, onResult, defaultValue) =>\n native.Alert.prompt!(\n title,\n message,\n [\n { text: 'Cancel', style: 'cancel', onPress: () => onResult(null) },\n { text: 'OK', onPress: (value) => onResult(value ?? '') },\n ],\n undefined,\n defaultValue,\n ),\n }\n : {}),\n ...(ios && native.ActionSheetIOS\n ? {\n actionSheet: (options, onSelect) =>\n native.ActionSheetIOS!.showActionSheetWithOptions(options, onSelect),\n }\n : {}),\n ...(android && native.ToastAndroid\n ? {\n toast: (message, long) =>\n native.ToastAndroid!.show(\n message,\n long ? native.ToastAndroid!.LONG : native.ToastAndroid!.SHORT,\n ),\n }\n : {}),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dialogs.js","sourceRoot":"","sources":["../src/dialogs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,WAAW,EAAoB,MAAM,mBAAmB,CAAC;;AAmClE;;;;;GAKG;AAEH,MAAM,OAAO,OAAO;IAClB,uEAAuE;IACvE,MAAM,CAAU,MAAM,GAAG,IAAI,cAAc,CAAuB,6BAA6B,EAAE;QAC/F,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;KAC3C,CAAC,CAAC;IAEc,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAEjD,mFAAmF;IAC1E,SAAS,GAAoB,MAAM,CAAC,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;IAEhF,6FAA6F;IAC7F,IAAI,CAAC,KAAa,EAAE,OAAgB,EAAE,OAAO,GAAG,IAAI;QAClD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,IAAI,CAAC,IAAI,CAAC,MAAM;gBAAE,OAAO,OAAO,EAAE,CAAC;YACnC,IAA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AG,CAAC,GAAG,IAAI,MAAM,CAAC,cAAc;YAC9B,CAAC,CAAC;gBACE,WAAW,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,CACjC,MAAM,CAAC,cAAe,CAAC,0BAA0B,CAAC,OAAO,EAAE,QAAQ,CAAC;aACvE;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,OAAO,IAAI,MAAM,CAAC,YAAY;YAChC,CAAC,CAAC;gBACE,KAAK,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CACvB,MAAM,CAAC,YAAa,CAAC,IAAI,CACvB,OAAO,EACP,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,YAAa,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,YAAa,CAAC,KAAK,CAC9D;aACJ;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The platform's own dialogs: an alert, a confirmation, a prompt, an action sheet, a toast.\n *\n * All of these are callback APIs, and the reason to wrap them is that **a dialog is a question**.\n * `Alert.alert` hands its answer to one of several `onPress` callbacks, so asking something and\n * acting on the answer means splitting one thought across three functions. A promise puts it back\n * together, and `await` at the call site reads like what it is.\n *\n * The platform split is the other half. An action sheet is iOS's way of offering a short list of\n * choices and Android's is a dialog; a toast is Android's way of saying something small and iOS\n * has none. `choose` and `notify` pick per platform, so an app writes the intent rather than the\n * platform - and the one thing neither can do is fail silently on the platform it is not for.\n */\n\nimport { InjectionToken, Service, inject, signal, type Signal } from '@angular/core';\nimport { reactNative, type ReactNative } from './react-native.ts';\n\n/** One choice in a dialog or an action sheet. */\nexport interface Choice {\n readonly label: string;\n /** `cancel` is dismissal; `destructive` is the one the platform paints red. */\n readonly style?: 'default' | 'cancel' | 'destructive';\n}\n\nexport interface NativeDialogs {\n readonly platform: 'ios' | 'android' | string;\n alert(\n title: string,\n message: string | undefined,\n buttons: readonly { text: string; style?: string; onPress?: () => void }[],\n ): void;\n prompt?(\n title: string,\n message: string | undefined,\n onResult: (value: string | null) => void,\n defaultValue?: string,\n ): void;\n actionSheet?(\n options: {\n title?: string;\n message?: string;\n options: string[];\n cancelButtonIndex: number;\n destructiveButtonIndex?: number;\n },\n onSelect: (index: number) => void,\n ): void;\n toast?(message: string, long: boolean): void;\n}\n\n/**\n * `inject(Dialogs).confirm('Delete this?', { destructive: true })`.\n *\n * A dialog is a question, so every method here resolves to the answer rather than handing it to\n * one of several callbacks.\n */\n@Service()\nexport class Dialogs {\n /** Overridden in a test to answer a dialog without one being shown. */\n static readonly SOURCE = new InjectionToken<NativeDialogs | null>('angular-native.dialogSource', {\n factory: () => dialogSource(reactNative()),\n });\n\n private readonly native = inject(Dialogs.SOURCE);\n\n /** Whether React Native's module is here. Where it is not, every call is inert. */\n readonly available: Signal<boolean> = signal(this.native !== null).asReadonly();\n\n /** Say something, and wait until it has been read. Resolves when the dialog is dismissed. */\n tell(title: string, message?: string, dismiss = 'OK'): Promise<void> {\n return new Promise((resolve) => {\n if (!this.native) return resolve();\n this.native.alert(title, message, [{ text: dismiss, onPress: () => resolve() }]);\n });\n }\n\n /**\n * Ask something with two answers. Resolves to whether they agreed.\n *\n * `destructive` paints the confirm button as the platform paints a delete, and puts cancel where\n * the platform puts it - which on iOS is the *right*, so a confirmation dialog does not train\n * people to tap the wrong thing.\n */\n confirm(\n title: string,\n options: { message?: string; confirm?: string; cancel?: string; destructive?: boolean } = {},\n ): Promise<boolean> {\n const { message, confirm = 'OK', cancel = 'Cancel', destructive = false } = options;\n return new Promise((resolve) => {\n if (!this.native) return resolve(false);\n this.native.alert(title, message, [\n { text: cancel, style: 'cancel', onPress: () => resolve(false) },\n {\n text: confirm,\n style: destructive ? 'destructive' : 'default',\n onPress: () => resolve(true),\n },\n ]);\n });\n }\n\n /**\n * Ask for a line of text. Resolves to null if they cancelled.\n *\n * iOS and macOS only: `Alert.prompt` has no Android equivalent, and inventing one out of a modal\n * and a text input would be a dialog that looks nothing like the platform's. On Android this\n * resolves to null so a caller can fall back to a screen of its own.\n */\n ask(title: string, options: { message?: string; value?: string } = {}): Promise<string | null> {\n return new Promise((resolve) => {\n if (!this.native?.prompt) return resolve(null);\n this.native.prompt(title, options.message, resolve, options.value);\n });\n }\n\n /**\n * Offer a short list of choices. Resolves to the index chosen, or null if dismissed.\n *\n * An action sheet on iOS and a dialog on Android, because that is what each platform means by\n * this. A `cancel` choice is where the platform puts cancel rather than in the list.\n *\n * `message` is the smaller line under the title, the one that says what a destructive choice\n * does: the action sheet's message on iOS and the dialog's message on Android.\n */\n choose(\n title: string,\n choices: readonly Choice[],\n options: { message?: string } = {},\n ): Promise<number | null> {\n const { message } = options;\n const cancelAt = choices.findIndex((choice) => choice.style === 'cancel');\n const destructiveAt = choices.findIndex((choice) => choice.style === 'destructive');\n\n return new Promise((resolve) => {\n if (!this.native) return resolve(null);\n\n if (this.native.actionSheet) {\n // iOS wants cancel last and named by index; a list with none gets one, because an action\n // sheet with no way out is one the user has to guess at.\n const labels = choices.map((choice) => choice.label);\n const cancelIndex = cancelAt >= 0 ? cancelAt : labels.push('Cancel') - 1;\n this.native.actionSheet(\n {\n title,\n ...(message !== undefined ? { message } : {}),\n options: labels,\n cancelButtonIndex: cancelIndex,\n ...(destructiveAt >= 0 ? { destructiveButtonIndex: destructiveAt } : {}),\n },\n (index) => resolve(index === cancelIndex ? null : index),\n );\n return;\n }\n\n /*\n * Android's alert is put up `cancelable: false` by React Native, so a press outside does\n * nothing and neither does the back button. Without a cancel among the choices there is no\n * way at all to decline - the user has to pick something - so one is appended, exactly as\n * the iOS branch above does for the same reason.\n *\n * Android's dialog holds three buttons: a negative, a neutral and a positive. Anything past\n * that is dropped by the platform without a word, and a choice the user cannot see is worse\n * than a list that refused to open, so it says so. A Mac's alert, the same call, has a\n * button for every choice, with Cancel bound to Escape.\n */\n const buttons = choices.map((choice, index) => ({\n text: choice.label,\n style: choice.style,\n onPress: () => resolve(choice.style === 'cancel' ? null : index),\n }));\n if (cancelAt < 0) {\n buttons.push({ text: 'Cancel', style: 'cancel', onPress: () => resolve(null) });\n }\n if (this.native.platform === 'android' && buttons.length > 3) {\n console.error(\n `[angular-native] Dialogs.choose was given ${choices.length} choices and Android shows ` +\n 'at most three buttons, counting the cancel. The rest will not appear. Use a ' +\n '`ui-select` or an `action-sheet`-shaped list for anything longer.',\n );\n }\n this.native.alert(title, message, buttons);\n });\n }\n\n /**\n * Say something small and transient.\n *\n * A toast on Android. iOS has no such thing and never has, so this does nothing there rather\n * than putting up a modal alert for something that did not warrant interrupting anyone - and an\n * app that must be seen should use `tell`.\n */\n notify(message: string, options: { long?: boolean } = {}): void {\n this.native?.toast?.(message, options.long ?? false);\n }\n}\n\n/**\n * The platform's dialogs, from React Native's own modules.\n *\n * `Alert.prompt` is iOS and macOS only, `ActionSheetIOS` iOS only and `ToastAndroid` Android\n * only; each is left absent rather than shimmed, which is what lets `ask`, `choose` and `notify`\n * above decide what to do about it.\n *\n * Which platform it is has to be asked outright, because React Native's own modules do not answer\n * it. `react-native` exports `ActionSheetIOS` on Android too - the object is there and so is\n * `showActionSheetWithOptions`; only the TurboModule underneath is null, and the invariant that\n * catches that throws out of the promise `choose` returns, so a press did nothing at all and said\n * nothing about it. `Alert.prompt` is worse: it exists on Android and its body is one\n * `Platform.OS === 'ios'` check, so it returns having called no callback and the promise `ask`\n * returns never settles. `ToastAndroid` is the mirror image on iOS. Presence is not capability\n * here; only the platform name is.\n */\nexport function dialogSource(\n native: Pick<ReactNative, 'Platform' | 'Alert' | 'ActionSheetIOS' | 'ToastAndroid'> | null,\n): NativeDialogs | null {\n if (!native) return null;\n\n const ios = native.Platform.OS === 'ios';\n // A Mac's alert module is iOS's, and React Native's `Alert.prompt` takes its iOS body there.\n const apple = ios || native.Platform.OS === 'macos';\n const android = native.Platform.OS === 'android';\n\n return {\n platform: native.Platform.OS,\n alert: (title, message, buttons) => native.Alert.alert(title, message, [...buttons]),\n // Buttons rather than a callback: given a callback, `Alert.prompt` answers OK alone, and the\n // Cancel the native alert adds calls nothing, so a cancelled `ask` never settled.\n ...(apple && native.Alert.prompt\n ? {\n prompt: (title, message, onResult, defaultValue) =>\n native.Alert.prompt!(\n title,\n message,\n [\n { text: 'Cancel', style: 'cancel', onPress: () => onResult(null) },\n { text: 'OK', onPress: (value) => onResult(value ?? '') },\n ],\n undefined,\n defaultValue,\n ),\n }\n : {}),\n ...(ios && native.ActionSheetIOS\n ? {\n actionSheet: (options, onSelect) =>\n native.ActionSheetIOS!.showActionSheetWithOptions(options, onSelect),\n }\n : {}),\n ...(android && native.ToastAndroid\n ? {\n toast: (message, long) =>\n native.ToastAndroid!.show(\n message,\n long ? native.ToastAndroid!.LONG : native.ToastAndroid!.SHORT,\n ),\n }\n : {}),\n };\n}\n"]}
|
package/dist/direction.d.ts
CHANGED
|
@@ -39,6 +39,8 @@ export declare class Direction implements DirectionContext {
|
|
|
39
39
|
/** Overridden in a test to flip the world, and by `mount` to read the document instead. */
|
|
40
40
|
static readonly SOURCE: InjectionToken<DirectionSource>;
|
|
41
41
|
private readonly source;
|
|
42
|
+
/** Whether the service is here: on every OS, where it answers what the OS reports. */
|
|
43
|
+
readonly available: Signal<boolean>;
|
|
42
44
|
private readonly direction;
|
|
43
45
|
readonly current: Signal<LayoutDirection>;
|
|
44
46
|
/** The same fact as a boolean, because most callers branch on it rather than switch. */
|
package/dist/direction.js
CHANGED
|
@@ -39,6 +39,8 @@ export class Direction {
|
|
|
39
39
|
factory: directionSource,
|
|
40
40
|
});
|
|
41
41
|
source = inject(Direction.SOURCE);
|
|
42
|
+
/** Whether the service is here: on every OS, where it answers what the OS reports. */
|
|
43
|
+
available = signal(true).asReadonly();
|
|
42
44
|
direction = signal(this.source.current(), /* @ts-ignore */
|
|
43
45
|
...(ngDevMode ? [{ debugName: "direction" }] : /* istanbul ignore next */ []));
|
|
44
46
|
current = this.direction.asReadonly();
|
package/dist/direction.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direction.js","sourceRoot":"","sources":["../src/direction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACL,UAAU,EACV,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,GAEP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAShD,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;IAExE,OAAO;QACL,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QACzD,yFAAyF;QACzF,uFAAuF;QACvF,6FAA6F;QAC7F,8FAA8F;QAC9F,+FAA+F;QAC/F,4CAA4C;QAC5C,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC;KAC1B,CAAC;AACJ,CAAC;AAgBD,MAAM,OAAO,SAAS;IACpB,2FAA2F;IAC3F,MAAM,CAAU,MAAM,GAAG,IAAI,cAAc,CAAkB,gCAAgC,EAAE;QAC7F,OAAO,EAAE,eAAe;KACzB,CAAC,CAAC;IAEc,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"direction.js","sourceRoot":"","sources":["../src/direction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACL,UAAU,EACV,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,GAEP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAShD,MAAM,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AAS,CAAC,CAAC,CACpE,CAAC;IACJ,CAAC;uGArBU,SAAS;wGAAT,SAAS;;2FAAT,SAAS;kBADrB,OAAO","sourcesContent":["/**\n * Which way round the world is: left to right, or right to left.\n *\n * The cascade already mirrors the *paint*. `direction: rtl` flips padding, text alignment and the\n * order boxes are laid out in, and Yoga inherits that down the shadow tree without anyone asking,\n * so a stylesheet needs nothing from this file.\n *\n * What the cascade cannot do is tell TypeScript which way round the world is, and this library\n * computes position in TypeScript in several places: `anchor.ts` resolves an `align` of `start`\n * against an edge, the slider maps a drag's x delta onto a value, and the drawer, the sheet and\n * the sidebar all name an edge. Every one of those is a decision made before a style exists, so\n * every one of them needs an answer here rather than in CSS. It is the same reason Angular's CDK\n * ships `Directionality` rather than leaving direction to the stylesheet.\n *\n * A directive can override it for a subtree the way `[dir]` does, by providing a\n * `DirectionContext` in `Direction`'s place.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n type Signal,\n} from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport type LayoutDirection = 'ltr' | 'rtl';\n\nexport interface DirectionSource {\n current(): LayoutDirection;\n subscribe(listener: (direction: LayoutDirection) => void): () => void;\n}\n\nexport function directionSource(): DirectionSource {\n const native = reactNative();\n if (!native) return { current: () => 'ltr', subscribe: () => () => {} };\n\n return {\n current: () => (native.I18nManager.isRTL ? 'rtl' : 'ltr'),\n // Nothing to subscribe to, and that is the platform rather than a gap here. React Native\n // settles the direction while the native side starts up, from the device's own locale;\n // `I18nManager.forceRTL` only takes effect after a restart, so `isRTL` cannot change under a\n // running app. The listener stays in the shape because the browser source genuinely does have\n // one - `document.dir` is a mutable attribute - and because a consumer should not have to know\n // which platform it is on to read a signal.\n subscribe: () => () => {},\n };\n}\n\n/**\n * The read side of a direction, which is all a consumer ever wants.\n *\n * Named separately from the service because a subtree's direction is not the device's:\n * a directive that overrides it for a subtree provides this in `Direction`'s place, exactly as\n * CDK's `Dir` implements `Directionality`. Everything that injects `Direction` gets whichever is\n * closest, and neither needs to know which it got.\n */\nexport interface DirectionContext {\n readonly current: Signal<LayoutDirection>;\n readonly rtl: Signal<boolean>;\n}\n\n@Service()\nexport class Direction implements DirectionContext {\n /** Overridden in a test to flip the world, and by `mount` to read the document instead. */\n static readonly SOURCE = new InjectionToken<DirectionSource>('angular-native.directionSource', {\n factory: directionSource,\n });\n\n private readonly source = inject(Direction.SOURCE);\n\n /** Whether the service is here: on every OS, where it answers what the OS reports. */\n readonly available: Signal<boolean> = signal(true).asReadonly();\n private readonly direction = signal<LayoutDirection>(this.source.current());\n\n readonly current: Signal<LayoutDirection> = this.direction.asReadonly();\n\n /** The same fact as a boolean, because most callers branch on it rather than switch. */\n readonly rtl: Signal<boolean> = computed(() => this.direction() === 'rtl');\n\n constructor() {\n inject(DestroyRef).onDestroy(\n this.source.subscribe((direction) => this.direction.set(direction)),\n );\n }\n}\n"]}
|
package/dist/dock.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app's Dock icon on macOS: a menu of the app's own above the standard one, and a bounce that
|
|
3
|
+
* asks for attention. Its badge is the Notifications badge count, from `@ng-native/expo`'s
|
|
4
|
+
* `Notifications.setBadge`, as an app icon's badge is on iOS. Absent on every other OS, where each
|
|
5
|
+
* call does nothing.
|
|
6
|
+
*
|
|
7
|
+
* The host contract, on the `NgNativeDock` module: `setMenu(entries)` takes the menu as
|
|
8
|
+
* `serializeMenu` makes it, or null for none; `bounce(critical)` answers an id that
|
|
9
|
+
* `cancelBounce(id)` takes; `{ type: 'menuSelect', id }` arrives on `ngNativeDock`.
|
|
10
|
+
*/
|
|
11
|
+
import { InjectionToken, type Signal } from '@angular/core';
|
|
12
|
+
import type { MenuEntry } from './menu-model.ts';
|
|
13
|
+
import { type NativeMenuEntry } from './menus.ts';
|
|
14
|
+
import * as i0 from "@angular/core";
|
|
15
|
+
export interface NativeDock {
|
|
16
|
+
setMenu(entries: readonly NativeMenuEntry[] | null): void;
|
|
17
|
+
bounce(critical: boolean): number;
|
|
18
|
+
cancelBounce(id: number): void;
|
|
19
|
+
subscribe(listener: (event: {
|
|
20
|
+
type: 'menuSelect';
|
|
21
|
+
id: string;
|
|
22
|
+
}) => void): () => void;
|
|
23
|
+
}
|
|
24
|
+
export declare class Dock {
|
|
25
|
+
/** Overridden in a test with a fake host. */
|
|
26
|
+
static readonly SOURCE: InjectionToken<NativeDock | null>;
|
|
27
|
+
private readonly native;
|
|
28
|
+
private actions;
|
|
29
|
+
private readonly unsubscribe;
|
|
30
|
+
/** Whether the app has a Dock icon: macOS. */
|
|
31
|
+
readonly available: Signal<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* Show `entries` in the Dock icon's menu, above the items macOS adds (Options, Show All Windows,
|
|
34
|
+
* Hide, Quit); an empty list or null takes them away. Items are `MenuItemModel`s, as a
|
|
35
|
+
* `<menu-item>` registers them.
|
|
36
|
+
*/
|
|
37
|
+
setMenu(entries: readonly MenuEntry[] | null): void;
|
|
38
|
+
/**
|
|
39
|
+
* Bounce the Dock icon until the app comes to the front: once, or with `critical` until then.
|
|
40
|
+
* Nothing while the app is in front. Answers the function that stops it.
|
|
41
|
+
*/
|
|
42
|
+
bounce(options?: {
|
|
43
|
+
critical?: boolean;
|
|
44
|
+
}): () => void;
|
|
45
|
+
ngOnDestroy(): void;
|
|
46
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<Dock, never>;
|
|
47
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
48
|
+
}
|