@a16n/web-sim 0.0.0-stage → 0.1.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/README.md +13 -2
- package/bin/cli.ts +255 -0
- package/bin/web-sim.js +39 -0
- package/overrides/@backpackapp-io/react-native-toast/overrides.ts +15 -0
- package/overrides/@react-native-firebase/app/overrides.ts +34 -0
- package/overrides/@tiktok-for-business/react-native-sdk/NativeTiktokSdk.ts +29 -0
- package/overrides/@tiktok-for-business/react-native-sdk/overrides.ts +9 -0
- package/overrides/expo-application/ExpoApplication.ts +81 -0
- package/overrides/expo-application/overrides.ts +16 -0
- package/overrides/expo-background-task/ExpoBackgroundTaskModule.ts +30 -0
- package/overrides/expo-background-task/overrides.ts +9 -0
- package/overrides/expo-constants/ExponentConstants.ts +66 -0
- package/overrides/expo-constants/overrides.ts +9 -0
- package/overrides/expo-device/ExpoDevice.ts +104 -0
- package/overrides/expo-device/overrides.ts +9 -0
- package/overrides/expo-glass-effect/GlassContainer.tsx +9 -0
- package/overrides/expo-glass-effect/GlassView.tsx +95 -0
- package/overrides/expo-glass-effect/availability.ts +14 -0
- package/overrides/expo-glass-effect/overrides.ts +14 -0
- package/overrides/expo-haptics/Haptics.ts +67 -0
- package/overrides/expo-haptics/overrides.ts +5 -0
- package/overrides/expo-mail-composer/ExpoMailComposer.ts +40 -0
- package/overrides/expo-mail-composer/overrides.ts +9 -0
- package/overrides/expo-mesh-gradient/MeshGradientView.tsx +44 -0
- package/overrides/expo-mesh-gradient/overrides.ts +9 -0
- package/overrides/expo-modules-core/overrides.ts +12 -0
- package/overrides/expo-navigation-bar/ExpoNavigationBar.ts +29 -0
- package/overrides/expo-navigation-bar/NavigationBar.ts +43 -0
- package/overrides/expo-navigation-bar/overrides.ts +12 -0
- package/overrides/expo-router/NativeStackView.tsx +74 -0
- package/overrides/expo-router/NativeTabsView.tsx +263 -0
- package/overrides/expo-router/SafeAreaProvider.ts +6 -0
- package/overrides/expo-router/overrides.ts +23 -0
- package/overrides/expo-router/statusBarRequests.ts +51 -0
- package/overrides/expo-screen-orientation/ExpoScreenOrientation.ts +173 -0
- package/overrides/expo-screen-orientation/overrides.ts +21 -0
- package/overrides/expo-sharing/SharingNativeModule.ts +21 -0
- package/overrides/expo-sharing/overrides.ts +9 -0
- package/overrides/expo-sms/ExpoSMS.ts +24 -0
- package/overrides/expo-sms/overrides.ts +9 -0
- package/overrides/expo-splash-screen/SplashScreen.ts +25 -0
- package/overrides/expo-splash-screen/overrides.ts +5 -0
- package/overrides/expo-status-bar/StatusBar.tsx +44 -0
- package/overrides/expo-status-bar/overrides.ts +5 -0
- package/overrides/expo-store-review/ExpoStoreReview.ts +18 -0
- package/overrides/expo-store-review/overrides.ts +9 -0
- package/overrides/expo-symbols/SymbolView.tsx +192 -0
- package/overrides/expo-symbols/overrides.ts +9 -0
- package/overrides/expo-system-ui/ExpoSystemUI.ts +34 -0
- package/overrides/expo-system-ui/overrides.ts +9 -0
- package/overrides/expo-task-manager/ExpoTaskManager.ts +39 -0
- package/overrides/expo-task-manager/overrides.ts +9 -0
- package/overrides/expo-tracking-transparency/ExpoTrackingTransparency.ts +30 -0
- package/overrides/expo-tracking-transparency/overrides.ts +11 -0
- package/overrides/expo-video/ExpoVideo.ts +16 -0
- package/overrides/expo-video/overrides.ts +9 -0
- package/overrides/lottie-react-native/LottieView.tsx +87 -0
- package/overrides/lottie-react-native/overrides.ts +9 -0
- package/overrides/react-native-pager-view/PagerViewNativeComponent.tsx +254 -0
- package/overrides/react-native-pager-view/overrides.ts +9 -0
- package/overrides/react-native-reanimated/overrides.ts +28 -0
- package/overrides/react-native-safe-area-context/NativeSafeAreaProvider.tsx +40 -0
- package/overrides/react-native-safe-area-context/overrides.ts +12 -0
- package/overrides/react-native-share/NativeRNShare.ts +22 -0
- package/overrides/react-native-share/overrides.ts +12 -0
- package/overrides/react-native-share/platform.ts +14 -0
- package/overrides/react-native-turbo-image/TurboImage.tsx +101 -0
- package/overrides/react-native-turbo-image/overrides.ts +9 -0
- package/overrides/react-native-web/RefreshControl.tsx +57 -0
- package/overrides/react-native-web/overrides.ts +153 -0
- package/overrides/react-native-web/useElementLayout.ts +140 -0
- package/package.json +78 -4
- package/plugins/battery/overrides/expo-battery/ExpoBattery.ts +57 -0
- package/plugins/battery/overrides/expo-battery/overrides.ts +9 -0
- package/plugins/battery/plugin.ts +8 -0
- package/plugins/battery/shell.tsx +56 -0
- package/plugins/battery/state.ts +11 -0
- package/plugins/biometrics/overrides/expo-local-authentication/ExpoLocalAuthentication.ts +90 -0
- package/plugins/biometrics/overrides/expo-local-authentication/overrides.ts +11 -0
- package/plugins/biometrics/plugin.ts +8 -0
- package/plugins/biometrics/shell.tsx +88 -0
- package/plugins/biometrics/state.ts +41 -0
- package/plugins/brightness/app.ts +5 -0
- package/plugins/brightness/overrides/expo-brightness/Brightness.ts +98 -0
- package/plugins/brightness/overrides/expo-brightness/overrides.ts +10 -0
- package/plugins/brightness/plugin.ts +9 -0
- package/plugins/brightness/shell.tsx +55 -0
- package/plugins/brightness/state.ts +19 -0
- package/plugins/calendar/calendar.ts +299 -0
- package/plugins/calendar/overrides/expo-calendar/ExpoCalendar.ts +358 -0
- package/plugins/calendar/overrides/expo-calendar/LegacyExpoCalendar.ts +163 -0
- package/plugins/calendar/overrides/expo-calendar/overrides.ts +14 -0
- package/plugins/calendar/plugin.ts +8 -0
- package/plugins/calendar/shell.tsx +123 -0
- package/plugins/camera/overrides/expo-camera/ExpoCamera.tsx +269 -0
- package/plugins/camera/overrides/expo-camera/ExpoCameraManager.ts +56 -0
- package/plugins/camera/overrides/expo-camera/overrides.ts +12 -0
- package/plugins/camera/plugin.ts +9 -0
- package/plugins/camera/shell.tsx +107 -0
- package/plugins/camera/state.ts +61 -0
- package/plugins/clipboard/overrides/expo-clipboard/ExpoClipboard.ts +138 -0
- package/plugins/clipboard/overrides/expo-clipboard/overrides.ts +9 -0
- package/plugins/clipboard/plugin.ts +8 -0
- package/plugins/clipboard/shell.tsx +122 -0
- package/plugins/clipboard/state.ts +93 -0
- package/plugins/clock/app.ts +25 -0
- package/plugins/clock/plugin.ts +8 -0
- package/plugins/clock/shell.tsx +225 -0
- package/plugins/clock/state.ts +12 -0
- package/plugins/contacts/contacts.ts +125 -0
- package/plugins/contacts/overrides/expo-contacts/ExpoContacts.ts +153 -0
- package/plugins/contacts/overrides/expo-contacts/ExpoContactsNext.ts +232 -0
- package/plugins/contacts/overrides/expo-contacts/overrides.ts +12 -0
- package/plugins/contacts/plugin.ts +8 -0
- package/plugins/contacts/shell.tsx +109 -0
- package/plugins/home-indicator/app.ts +5 -0
- package/plugins/home-indicator/plugin.ts +9 -0
- package/plugins/home-indicator/requests.ts +48 -0
- package/plugins/home-indicator/shell.tsx +68 -0
- package/plugins/home-indicator/state.ts +31 -0
- package/plugins/keep-awake/app.ts +5 -0
- package/plugins/keep-awake/overrides/expo-keep-awake/ExpoKeepAwake.ts +27 -0
- package/plugins/keep-awake/overrides/expo-keep-awake/overrides.ts +9 -0
- package/plugins/keep-awake/plugin.ts +9 -0
- package/plugins/keep-awake/shell.tsx +80 -0
- package/plugins/keep-awake/state.ts +12 -0
- package/plugins/keyboard/Keyboard.tsx +354 -0
- package/plugins/keyboard/app.ts +90 -0
- package/plugins/keyboard/controller.ts +384 -0
- package/plugins/keyboard/fields.ts +244 -0
- package/plugins/keyboard/icons.tsx +283 -0
- package/plugins/keyboard/keyboard.css +362 -0
- package/plugins/keyboard/layouts/android.ts +175 -0
- package/plugins/keyboard/layouts/index.ts +10 -0
- package/plugins/keyboard/layouts/ios.ts +219 -0
- package/plugins/keyboard/layouts/types.ts +80 -0
- package/plugins/keyboard/overrides/react-native-keyboard-controller/KeyboardController.tsx +470 -0
- package/plugins/keyboard/overrides/react-native-keyboard-controller/overrides.ts +9 -0
- package/plugins/keyboard/plugin.ts +13 -0
- package/plugins/keyboard/shell.tsx +133 -0
- package/plugins/keyboard/state.ts +92 -0
- package/plugins/keyboard/suggestions.ts +63 -0
- package/plugins/keyboard/taps.ts +77 -0
- package/plugins/keyboard/typing.ts +112 -0
- package/plugins/locale/app.ts +232 -0
- package/plugins/locale/locale.ts +143 -0
- package/plugins/locale/overrides/expo-localization/ExpoLocalization.ts +41 -0
- package/plugins/locale/overrides/expo-localization/overrides.ts +9 -0
- package/plugins/locale/plugin.ts +9 -0
- package/plugins/locale/shell.tsx +147 -0
- package/plugins/locale/state.ts +36 -0
- package/plugins/location/geo.ts +56 -0
- package/plugins/location/overrides/expo-location/ExpoLocation.ts +235 -0
- package/plugins/location/overrides/expo-location/overrides.ts +11 -0
- package/plugins/location/places.ts +38 -0
- package/plugins/location/plugin.ts +8 -0
- package/plugins/location/shell.tsx +188 -0
- package/plugins/location/state.ts +51 -0
- package/plugins/motion/overrides/expo-sensors/DeviceSensor.ts +169 -0
- package/plugins/motion/overrides/expo-sensors/ExponentPedometer.ts +54 -0
- package/plugins/motion/overrides/expo-sensors/overrides.ts +14 -0
- package/plugins/motion/plugin.ts +8 -0
- package/plugins/motion/sensors.ts +116 -0
- package/plugins/motion/shell.tsx +136 -0
- package/plugins/motion/state.ts +46 -0
- package/plugins/network/app.ts +400 -0
- package/plugins/network/overrides/expo-network/ExpoNetwork.ts +51 -0
- package/plugins/network/overrides/expo-network/overrides.ts +9 -0
- package/plugins/network/plugin.ts +8 -0
- package/plugins/network/shell.tsx +67 -0
- package/plugins/network/state.ts +29 -0
- package/plugins/notifications/center.ts +255 -0
- package/plugins/notifications/content.ts +36 -0
- package/plugins/notifications/overrides/expo-notifications/NotificationsModule.ts +175 -0
- package/plugins/notifications/overrides/expo-notifications/channels.ts +108 -0
- package/plugins/notifications/overrides/expo-notifications/getDevicePushTokenAsync.ts +19 -0
- package/plugins/notifications/overrides/expo-notifications/getExpoPushTokenAsync.ts +16 -0
- package/plugins/notifications/overrides/expo-notifications/overrides.ts +36 -0
- package/plugins/notifications/plugin.ts +8 -0
- package/plugins/notifications/shell.tsx +192 -0
- package/plugins/notifications/state.ts +56 -0
- package/plugins/notifications/tokens.ts +47 -0
- package/plugins/notifications/trigger.ts +107 -0
- package/plugins/permissions/plugin.ts +6 -0
- package/plugins/permissions/shell.tsx +50 -0
- package/plugins/permissions/state.ts +38 -0
- package/plugins/photos/appLibrary.ts +114 -0
- package/plugins/photos/library.ts +322 -0
- package/plugins/photos/overrides/expo-image-picker/ExponentImagePicker.ts +153 -0
- package/plugins/photos/overrides/expo-image-picker/overrides.ts +13 -0
- package/plugins/photos/overrides/expo-media-library/ExpoMediaLibrary.ts +235 -0
- package/plugins/photos/overrides/expo-media-library/NativeMediaLibraryModule.ts +318 -0
- package/plugins/photos/overrides/expo-media-library/overrides.ts +19 -0
- package/plugins/photos/plugin.ts +8 -0
- package/plugins/photos/samples.ts +367 -0
- package/plugins/photos/shell.tsx +164 -0
- package/plugins/photos/state.ts +88 -0
- package/plugins/storage/files.ts +351 -0
- package/plugins/storage/overrides/expo-file-system/ExpoFileSystem.ts +770 -0
- package/plugins/storage/overrides/expo-file-system/ExponentFileSystem.ts +196 -0
- package/plugins/storage/overrides/expo-file-system/overrides.ts +13 -0
- package/plugins/storage/overrides/expo-secure-store/ExpoSecureStore.ts +75 -0
- package/plugins/storage/overrides/expo-secure-store/overrides.ts +9 -0
- package/plugins/storage/plugin.ts +8 -0
- package/plugins/storage/reset.ts +136 -0
- package/plugins/storage/secure.ts +71 -0
- package/plugins/storage/shell.tsx +365 -0
- package/plugins/storage/state.ts +13 -0
- package/src/client/app/appDocument.ts +113 -0
- package/src/client/app/appFocus.ts +97 -0
- package/src/client/app/console.ts +118 -0
- package/src/client/app/fonts.ts +59 -0
- package/src/client/app/main.tsx +99 -0
- package/src/client/app/routeContext.ts +45 -0
- package/src/client/app/touch.ts +640 -0
- package/src/client/entry.ts +20 -0
- package/src/client/modules.d.ts +8 -0
- package/src/client/react-native/app.ts +57 -0
- package/src/client/react-native/deep.ts +13 -0
- package/src/client/react-native/keyboard.tsx +192 -0
- package/src/client/react-native/library.ts +256 -0
- package/src/client/shell/Cookies.tsx +95 -0
- package/src/client/shell/LogDrawer.tsx +415 -0
- package/src/client/shell/PhotoPicker.tsx +174 -0
- package/src/client/shell/PluginOverlays.tsx +42 -0
- package/src/client/shell/PluginPanels.tsx +82 -0
- package/src/client/shell/ResetApp.tsx +87 -0
- package/src/client/shell/Resizer.tsx +99 -0
- package/src/client/shell/Shell.tsx +531 -0
- package/src/client/shell/SystemBars.tsx +376 -0
- package/src/client/shell/SystemCamera.tsx +181 -0
- package/src/client/shell/SystemOverlay.tsx +422 -0
- package/src/client/shell/SystemSheets.tsx +462 -0
- package/src/client/shell/backdrop.ts +229 -0
- package/src/client/shell/control.ts +91 -0
- package/src/client/shell/events.ts +226 -0
- package/src/client/shell/geometry.ts +68 -0
- package/src/client/shell/host.ts +492 -0
- package/src/client/shell/icons.tsx +34 -0
- package/src/client/shell/logFeed.ts +102 -0
- package/src/client/shell/main.tsx +22 -0
- package/src/client/shell/permissionCopy.ts +169 -0
- package/src/client/shell/plugins.ts +266 -0
- package/src/client/shell/popout.ts +185 -0
- package/src/client/shell/popover.ts +27 -0
- package/src/client/shell/shell.css +878 -0
- package/src/client/shell/statusTime.ts +31 -0
- package/src/client/shell/tooltips.ts +104 -0
- package/src/client/virtual.d.ts +21 -0
- package/src/devices/catalog.ts +223 -0
- package/src/devices/types.ts +83 -0
- package/src/node/appInfo.ts +186 -0
- package/src/node/appSource.ts +138 -0
- package/src/node/config.ts +180 -0
- package/src/node/control.ts +144 -0
- package/src/node/doctor.ts +199 -0
- package/src/node/events/cli.ts +206 -0
- package/src/node/events/shared.ts +238 -0
- package/src/node/events/store.ts +266 -0
- package/src/node/index.ts +5 -0
- package/src/node/overrides/define.ts +56 -0
- package/src/node/overrides/packages.ts +136 -0
- package/src/node/overrides/platformPatch.ts +56 -0
- package/src/node/overrides/plugin.ts +166 -0
- package/src/node/overrides/registry.ts +258 -0
- package/src/node/paths.ts +18 -0
- package/src/node/platform.ts +171 -0
- package/src/node/plugins.ts +98 -0
- package/src/node/proxy.ts +421 -0
- package/src/node/server.ts +253 -0
- package/src/plugin/index.ts +33 -0
- package/src/plugin/types.ts +127 -0
- package/src/plugin/ui.tsx +562 -0
- package/src/runtime/clock.ts +112 -0
- package/src/runtime/draw.ts +196 -0
- package/src/runtime/index.ts +513 -0
- package/src/runtime/media.ts +379 -0
- package/src/runtime/records.ts +76 -0
- package/src/runtime/timezone.ts +81 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { CodedError } from 'expo'
|
|
2
|
+
import { getPermission, platform, requestPermission } from 'web-sim/runtime'
|
|
3
|
+
import {
|
|
4
|
+
createLibraryAlbum,
|
|
5
|
+
deleteFromLibrary,
|
|
6
|
+
deleteLibraryAlbums,
|
|
7
|
+
editLibraryAlbum,
|
|
8
|
+
type LibraryAlbum,
|
|
9
|
+
libraryAlbums,
|
|
10
|
+
type LibraryPhoto,
|
|
11
|
+
libraryPhoto,
|
|
12
|
+
libraryPhotos,
|
|
13
|
+
onLibraryChange,
|
|
14
|
+
photoDataUrl,
|
|
15
|
+
saveToLibrary,
|
|
16
|
+
setLibraryFavorite,
|
|
17
|
+
} from '../../appLibrary.ts'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The legacy `expo-media-library` API (`expo-media-library/legacy`) over the simulator's photo library, the same
|
|
21
|
+
* one the photo picker and the current API show. Assets' `uri`s are data URLs a `<Image>` can show, sized for lists;
|
|
22
|
+
* `getAssetInfoAsync` gives the full-size `localUri`.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
type AssetsOptions = {
|
|
26
|
+
first: number
|
|
27
|
+
after?: string
|
|
28
|
+
album?: string
|
|
29
|
+
sortBy: string[]
|
|
30
|
+
mediaType: string[]
|
|
31
|
+
createdAfter?: number
|
|
32
|
+
createdBefore?: number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function ensurePermission() {
|
|
36
|
+
if (!getPermission('photos').granted) {
|
|
37
|
+
throw new CodedError('E_NO_PERMISSIONS', 'Missing MEDIA_LIBRARY permissions.')
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function albumOf(id: string): LibraryAlbum {
|
|
42
|
+
const album = libraryAlbums().find((candidate) => candidate.id === id)
|
|
43
|
+
if (album === undefined) {
|
|
44
|
+
throw new CodedError('E_ALBUM_NOT_FOUND', `Album ${id} not found`)
|
|
45
|
+
}
|
|
46
|
+
return album
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function albumFor(photo: LibraryPhoto): string | undefined {
|
|
50
|
+
return libraryAlbums().find((album) => album.type === 'album' && album.assetIds.includes(photo.id))?.id
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function asset(photo: LibraryPhoto) {
|
|
54
|
+
return {
|
|
55
|
+
id: photo.id,
|
|
56
|
+
filename: photo.filename,
|
|
57
|
+
uri: (await photoDataUrl(photo, { maxSize: 800, quality: 0.8 })).uri,
|
|
58
|
+
mediaType: 'photo',
|
|
59
|
+
mediaSubtypes: [],
|
|
60
|
+
width: photo.width,
|
|
61
|
+
height: photo.height,
|
|
62
|
+
creationTime: photo.creationTime,
|
|
63
|
+
modificationTime: photo.creationTime,
|
|
64
|
+
duration: 0,
|
|
65
|
+
albumId: albumFor(photo),
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function album(album: LibraryAlbum) {
|
|
70
|
+
const photos = libraryPhotos().filter((photo) => album.assetIds.includes(photo.id))
|
|
71
|
+
return {
|
|
72
|
+
id: album.id,
|
|
73
|
+
title: album.title,
|
|
74
|
+
assetCount: album.assetIds.length,
|
|
75
|
+
...(platform() === 'ios' && {
|
|
76
|
+
type: album.type,
|
|
77
|
+
startTime: Math.min(...photos.map((photo) => photo.creationTime)),
|
|
78
|
+
endTime: Math.max(...photos.map((photo) => photo.creationTime)),
|
|
79
|
+
}),
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function libraryPermission(response: ReturnType<typeof getPermission>) {
|
|
84
|
+
return { ...response, accessPrivileges: response.granted ? 'all' : 'none' }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export default {
|
|
88
|
+
CHANGE_LISTENER_NAME: 'mediaLibraryDidChange',
|
|
89
|
+
MediaType: { audio: 'audio', photo: 'photo', video: 'video', unknown: 'unknown' },
|
|
90
|
+
SortBy: {
|
|
91
|
+
default: 'default',
|
|
92
|
+
mediaType: 'mediaType',
|
|
93
|
+
width: 'width',
|
|
94
|
+
height: 'height',
|
|
95
|
+
creationTime: 'creationTime',
|
|
96
|
+
modificationTime: 'modificationTime',
|
|
97
|
+
duration: 'duration',
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
async getPermissionsAsync(_writeOnly?: boolean) {
|
|
101
|
+
return libraryPermission(getPermission('photos'))
|
|
102
|
+
},
|
|
103
|
+
async requestPermissionsAsync(_writeOnly?: boolean) {
|
|
104
|
+
return libraryPermission(await requestPermission('photos'))
|
|
105
|
+
},
|
|
106
|
+
async presentPermissionsPickerAsync() {},
|
|
107
|
+
|
|
108
|
+
async getAssetsAsync(options: AssetsOptions) {
|
|
109
|
+
ensurePermission()
|
|
110
|
+
let photos = libraryPhotos()
|
|
111
|
+
if (!options.mediaType.includes('photo') && !options.mediaType.includes('all')) {
|
|
112
|
+
photos = []
|
|
113
|
+
}
|
|
114
|
+
if (options.album) {
|
|
115
|
+
const ids = new Set(albumOf(options.album).assetIds)
|
|
116
|
+
photos = photos.filter((photo) => ids.has(photo.id))
|
|
117
|
+
}
|
|
118
|
+
if (options.createdAfter !== undefined) {
|
|
119
|
+
photos = photos.filter((photo) => photo.creationTime > options.createdAfter!)
|
|
120
|
+
}
|
|
121
|
+
if (options.createdBefore !== undefined) {
|
|
122
|
+
photos = photos.filter((photo) => photo.creationTime < options.createdBefore!)
|
|
123
|
+
}
|
|
124
|
+
for (const sort of [...options.sortBy].reverse()) {
|
|
125
|
+
const [key, direction] = sort.split(' ')
|
|
126
|
+
const field = key === 'modificationTime' || key === 'default' ? 'creationTime' : key
|
|
127
|
+
if (field === 'creationTime' || field === 'width' || field === 'height') {
|
|
128
|
+
photos = [...photos].sort((a, b) => (direction === 'ASC' ? 1 : -1) * (a[field] - b[field]))
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const start = options.after === undefined ? 0 : photos.findIndex((photo) => photo.id === options.after) + 1
|
|
132
|
+
const page = photos.slice(start, start + options.first)
|
|
133
|
+
return {
|
|
134
|
+
assets: await Promise.all(page.map(asset)),
|
|
135
|
+
endCursor: page.at(-1)?.id ?? options.after ?? '',
|
|
136
|
+
hasNextPage: start + page.length < photos.length,
|
|
137
|
+
totalCount: photos.length,
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
async getAssetInfoAsync(id: string) {
|
|
142
|
+
ensurePermission()
|
|
143
|
+
const photo = libraryPhoto(id)
|
|
144
|
+
if (photo === null) {
|
|
145
|
+
throw new CodedError('E_ASSET_NOT_FOUND', `Asset ${id} not found`)
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
...(await asset(photo)),
|
|
149
|
+
localUri: (await photoDataUrl(photo)).uri,
|
|
150
|
+
location: photo.location ?? undefined,
|
|
151
|
+
exif: { PixelXDimension: photo.width, PixelYDimension: photo.height, Orientation: 1 },
|
|
152
|
+
isFavorite: photo.favorite,
|
|
153
|
+
isNetworkAsset: false,
|
|
154
|
+
orientation: 0,
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
async createAssetAsync(localUri: string, albumId?: string) {
|
|
159
|
+
ensurePermission()
|
|
160
|
+
return asset(await saveToLibrary(localUri, albumId || undefined))
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
async saveToLibraryAsync(localUri: string) {
|
|
164
|
+
// Saving needs only add access, which the photo library permission covers here.
|
|
165
|
+
ensurePermission()
|
|
166
|
+
await saveToLibrary(localUri)
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
async deleteAssetsAsync(ids: string[]) {
|
|
170
|
+
ensurePermission()
|
|
171
|
+
deleteFromLibrary(ids)
|
|
172
|
+
return true
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
async setAssetFavoriteAsync(id: string, isFavorite: boolean) {
|
|
176
|
+
ensurePermission()
|
|
177
|
+
setLibraryFavorite(id, isFavorite)
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
async getAlbumsAsync({ includeSmartAlbums = false }: { includeSmartAlbums?: boolean } = {}) {
|
|
181
|
+
ensurePermission()
|
|
182
|
+
return libraryAlbums()
|
|
183
|
+
.filter((candidate) => includeSmartAlbums || candidate.type === 'album')
|
|
184
|
+
.map(album)
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
async getAlbumAsync(title: string) {
|
|
188
|
+
ensurePermission()
|
|
189
|
+
const found = libraryAlbums().find((candidate) => candidate.title === title)
|
|
190
|
+
return found === undefined ? null : album(found)
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
async createAlbumAsync(title: string, assetId?: string, ...rest: unknown[]) {
|
|
194
|
+
ensurePermission()
|
|
195
|
+
const initialUri = rest.find((value): value is string => typeof value === 'string')
|
|
196
|
+
const ids = assetId ? [assetId] : initialUri ? [(await saveToLibrary(initialUri)).id] : []
|
|
197
|
+
return album(createLibraryAlbum(title, ids))
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
async deleteAlbumsAsync(ids: string[], deleteAssets = false) {
|
|
201
|
+
ensurePermission()
|
|
202
|
+
if (deleteAssets) {
|
|
203
|
+
deleteFromLibrary(ids.flatMap((id) => albumOf(id).assetIds))
|
|
204
|
+
}
|
|
205
|
+
deleteLibraryAlbums(ids)
|
|
206
|
+
return true
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
async addAssetsToAlbumAsync(assetIds: string[], albumId: string) {
|
|
210
|
+
ensurePermission()
|
|
211
|
+
editLibraryAlbum(albumId, { add: assetIds })
|
|
212
|
+
return true
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
async removeAssetsFromAlbumAsync(assetIds: string[], albumId: string) {
|
|
216
|
+
ensurePermission()
|
|
217
|
+
editLibraryAlbum(albumId, { remove: assetIds })
|
|
218
|
+
return true
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
async getMomentsAsync() {
|
|
222
|
+
ensurePermission()
|
|
223
|
+
return []
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
async migrateAlbumIfNeededAsync() {},
|
|
227
|
+
async albumNeedsMigrationAsync() {
|
|
228
|
+
return false
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
addListener(_eventName: string, listener: (event: unknown) => void) {
|
|
232
|
+
return { remove: onLibraryChange((change) => listener(platform() === 'android' ? {} : change)) }
|
|
233
|
+
},
|
|
234
|
+
removeAllListeners() {},
|
|
235
|
+
}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { CodedError } from 'expo'
|
|
2
|
+
import { getPermission, platform, requestPermission } from 'web-sim/runtime'
|
|
3
|
+
import {
|
|
4
|
+
createLibraryAlbum,
|
|
5
|
+
deleteFromLibrary,
|
|
6
|
+
deleteLibraryAlbums,
|
|
7
|
+
editLibraryAlbum,
|
|
8
|
+
type LibraryAlbum,
|
|
9
|
+
libraryAlbums,
|
|
10
|
+
type LibraryPhoto,
|
|
11
|
+
libraryPhoto,
|
|
12
|
+
libraryPhotos,
|
|
13
|
+
onLibraryChange,
|
|
14
|
+
photoDataUrl,
|
|
15
|
+
saveToLibrary,
|
|
16
|
+
setLibraryFavorite,
|
|
17
|
+
} from '../../appLibrary.ts'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* `expo-media-library`'s native module over the simulator's photo library: the same photos and albums the photo
|
|
21
|
+
* picker shows. Reading it needs the photo library permission, as on the device.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
function ensurePermission() {
|
|
25
|
+
if (!getPermission('photos').granted) {
|
|
26
|
+
throw new CodedError('ERR_NO_PERMISSIONS', 'Missing photo library permission')
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function photoOf(id: string): LibraryPhoto {
|
|
31
|
+
ensurePermission()
|
|
32
|
+
const photo = libraryPhoto(id)
|
|
33
|
+
if (photo === null) {
|
|
34
|
+
throw new CodedError('ERR_ASSET_NOT_FOUND', `Asset ${id} not found`)
|
|
35
|
+
}
|
|
36
|
+
return photo
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function albumOf(id: string): LibraryAlbum {
|
|
40
|
+
ensurePermission()
|
|
41
|
+
const album = libraryAlbums().find((candidate) => candidate.id === id)
|
|
42
|
+
if (album === undefined) {
|
|
43
|
+
throw new CodedError('ERR_ALBUM_NOT_FOUND', `Album ${id} not found`)
|
|
44
|
+
}
|
|
45
|
+
return album
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function metadata(photo: LibraryPhoto) {
|
|
49
|
+
return {
|
|
50
|
+
id: photo.id,
|
|
51
|
+
filename: photo.filename,
|
|
52
|
+
mediaType: 'image',
|
|
53
|
+
width: photo.width,
|
|
54
|
+
height: photo.height,
|
|
55
|
+
duration: null,
|
|
56
|
+
creationTime: photo.creationTime,
|
|
57
|
+
modificationTime: photo.creationTime,
|
|
58
|
+
isFavorite: photo.favorite,
|
|
59
|
+
mediaSubtypes: [],
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function libraryPermission(response: ReturnType<typeof getPermission>) {
|
|
64
|
+
return { ...response, accessPrivileges: response.granted ? 'all' : 'none' }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
class NativeAsset {
|
|
68
|
+
id: string
|
|
69
|
+
constructor(id: string) {
|
|
70
|
+
this.id = id
|
|
71
|
+
}
|
|
72
|
+
async getCreationTime() {
|
|
73
|
+
return photoOf(this.id).creationTime
|
|
74
|
+
}
|
|
75
|
+
async getModificationTime() {
|
|
76
|
+
return photoOf(this.id).creationTime
|
|
77
|
+
}
|
|
78
|
+
async getDuration() {
|
|
79
|
+
photoOf(this.id)
|
|
80
|
+
return null
|
|
81
|
+
}
|
|
82
|
+
async getFilename() {
|
|
83
|
+
return photoOf(this.id).filename
|
|
84
|
+
}
|
|
85
|
+
async getWidth() {
|
|
86
|
+
return photoOf(this.id).width
|
|
87
|
+
}
|
|
88
|
+
async getHeight() {
|
|
89
|
+
return photoOf(this.id).height
|
|
90
|
+
}
|
|
91
|
+
async getShape() {
|
|
92
|
+
const photo = photoOf(this.id)
|
|
93
|
+
return { width: photo.width, height: photo.height }
|
|
94
|
+
}
|
|
95
|
+
async getMediaType() {
|
|
96
|
+
photoOf(this.id)
|
|
97
|
+
return 'image'
|
|
98
|
+
}
|
|
99
|
+
async getMediaSubtypes() {
|
|
100
|
+
photoOf(this.id)
|
|
101
|
+
return []
|
|
102
|
+
}
|
|
103
|
+
async getLivePhotoVideoUri() {
|
|
104
|
+
return null
|
|
105
|
+
}
|
|
106
|
+
async getIsInCloud() {
|
|
107
|
+
return false
|
|
108
|
+
}
|
|
109
|
+
async getOrientation() {
|
|
110
|
+
return 0
|
|
111
|
+
}
|
|
112
|
+
async getUri() {
|
|
113
|
+
return (await photoDataUrl(photoOf(this.id))).uri
|
|
114
|
+
}
|
|
115
|
+
async getInfo() {
|
|
116
|
+
const photo = photoOf(this.id)
|
|
117
|
+
return { ...metadata(photo), uri: (await photoDataUrl(photo)).uri }
|
|
118
|
+
}
|
|
119
|
+
async getAlbums() {
|
|
120
|
+
photoOf(this.id)
|
|
121
|
+
return libraryAlbums()
|
|
122
|
+
.filter((album) => album.type === 'album' && album.assetIds.includes(this.id))
|
|
123
|
+
.map((album) => new NativeAlbum(album.id))
|
|
124
|
+
}
|
|
125
|
+
async getLocation() {
|
|
126
|
+
return photoOf(this.id).location
|
|
127
|
+
}
|
|
128
|
+
async getExif() {
|
|
129
|
+
const photo = photoOf(this.id)
|
|
130
|
+
return { PixelXDimension: photo.width, PixelYDimension: photo.height, Orientation: 1 }
|
|
131
|
+
}
|
|
132
|
+
async getFavorite() {
|
|
133
|
+
return photoOf(this.id).favorite
|
|
134
|
+
}
|
|
135
|
+
async setFavorite(isFavorite: boolean) {
|
|
136
|
+
photoOf(this.id)
|
|
137
|
+
setLibraryFavorite(this.id, isFavorite)
|
|
138
|
+
}
|
|
139
|
+
async delete() {
|
|
140
|
+
await NativeAsset.delete([this])
|
|
141
|
+
}
|
|
142
|
+
static async create(filePath: string, album?: NativeAlbum) {
|
|
143
|
+
ensurePermission()
|
|
144
|
+
return new NativeAsset((await saveToLibrary(filePath, album?.id)).id)
|
|
145
|
+
}
|
|
146
|
+
static async delete(assets: NativeAsset[]) {
|
|
147
|
+
ensurePermission()
|
|
148
|
+
deleteFromLibrary(assets.map((asset) => asset.id))
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
class NativeAlbum {
|
|
153
|
+
id: string
|
|
154
|
+
constructor(id: string) {
|
|
155
|
+
this.id = id
|
|
156
|
+
}
|
|
157
|
+
async getAssets() {
|
|
158
|
+
return albumOf(this.id).assetIds.map((id) => new NativeAsset(id))
|
|
159
|
+
}
|
|
160
|
+
async getTitle() {
|
|
161
|
+
return albumOf(this.id).title
|
|
162
|
+
}
|
|
163
|
+
async getAssetCount() {
|
|
164
|
+
return albumOf(this.id).assetIds.length
|
|
165
|
+
}
|
|
166
|
+
async getType() {
|
|
167
|
+
return albumOf(this.id).type
|
|
168
|
+
}
|
|
169
|
+
async delete() {
|
|
170
|
+
await NativeAlbum.delete([this])
|
|
171
|
+
}
|
|
172
|
+
async add(assets: NativeAsset | NativeAsset[]) {
|
|
173
|
+
albumOf(this.id)
|
|
174
|
+
editLibraryAlbum(this.id, { add: (Array.isArray(assets) ? assets : [assets]).map((asset) => asset.id) })
|
|
175
|
+
}
|
|
176
|
+
async removeAssets(assets: NativeAsset[]) {
|
|
177
|
+
albumOf(this.id)
|
|
178
|
+
editLibraryAlbum(this.id, { remove: assets.map((asset) => asset.id) })
|
|
179
|
+
}
|
|
180
|
+
static async create(name: string, assetsRefs: (string | NativeAsset)[] = [], _moveAssets?: boolean) {
|
|
181
|
+
ensurePermission()
|
|
182
|
+
const ids: string[] = []
|
|
183
|
+
for (const ref of assetsRefs) {
|
|
184
|
+
// A string is a file to add; an asset is one already in the library.
|
|
185
|
+
ids.push(typeof ref === 'string' ? (await saveToLibrary(ref)).id : ref.id)
|
|
186
|
+
}
|
|
187
|
+
return new NativeAlbum(createLibraryAlbum(name, ids).id)
|
|
188
|
+
}
|
|
189
|
+
static async delete(albums: NativeAlbum[], deleteAssets = false) {
|
|
190
|
+
ensurePermission()
|
|
191
|
+
if (deleteAssets) {
|
|
192
|
+
deleteFromLibrary(albums.flatMap((album) => albumOf(album.id).assetIds))
|
|
193
|
+
}
|
|
194
|
+
deleteLibraryAlbums(albums.map((album) => album.id))
|
|
195
|
+
}
|
|
196
|
+
static async get(title: string) {
|
|
197
|
+
ensurePermission()
|
|
198
|
+
const album = libraryAlbums().find((candidate) => candidate.title === title)
|
|
199
|
+
return album === undefined ? null : new NativeAlbum(album.id)
|
|
200
|
+
}
|
|
201
|
+
static async getAll() {
|
|
202
|
+
ensurePermission()
|
|
203
|
+
return libraryAlbums()
|
|
204
|
+
.filter((album) => album.type === 'album')
|
|
205
|
+
.map((album) => new NativeAlbum(album.id))
|
|
206
|
+
}
|
|
207
|
+
static async getAlbumsMetadata() {
|
|
208
|
+
ensurePermission()
|
|
209
|
+
return libraryAlbums()
|
|
210
|
+
.filter((album) => album.type === 'album')
|
|
211
|
+
.map((album) => ({ id: album.id, title: album.title, type: platform() === 'ios' ? album.type : null }))
|
|
212
|
+
}
|
|
213
|
+
static async getSmartAlbums() {
|
|
214
|
+
ensurePermission()
|
|
215
|
+
return libraryAlbums()
|
|
216
|
+
.filter((album) => album.type === 'smartAlbum')
|
|
217
|
+
.map((album) => new NativeAlbum(album.id))
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
type Comparable = 'creationTime' | 'modificationTime' | 'width' | 'height' | 'duration'
|
|
222
|
+
type Filter = (asset: ReturnType<typeof metadata>) => boolean
|
|
223
|
+
|
|
224
|
+
class NativeQuery {
|
|
225
|
+
filters: Filter[] = []
|
|
226
|
+
sort: { key: string; ascending: boolean }[] = []
|
|
227
|
+
count: number | null = null
|
|
228
|
+
skip = 0
|
|
229
|
+
albumId: string | null = null
|
|
230
|
+
|
|
231
|
+
private field(asset: ReturnType<typeof metadata>, field: string): unknown {
|
|
232
|
+
return (asset as Record<string, unknown>)[field]
|
|
233
|
+
}
|
|
234
|
+
eq(field: string, value: unknown) {
|
|
235
|
+
this.filters.push((asset) => this.field(asset, field) === value)
|
|
236
|
+
return this
|
|
237
|
+
}
|
|
238
|
+
within(field: string, values: unknown[]) {
|
|
239
|
+
this.filters.push((asset) => values.includes(this.field(asset, field)))
|
|
240
|
+
return this
|
|
241
|
+
}
|
|
242
|
+
contains(field: string, value: unknown) {
|
|
243
|
+
this.filters.push((asset) => (this.field(asset, field) as unknown[] | undefined)?.includes(value) ?? false)
|
|
244
|
+
return this
|
|
245
|
+
}
|
|
246
|
+
gt(field: Comparable, value: number) {
|
|
247
|
+
this.filters.push((asset) => Number(this.field(asset, field)) > value)
|
|
248
|
+
return this
|
|
249
|
+
}
|
|
250
|
+
gte(field: Comparable, value: number) {
|
|
251
|
+
this.filters.push((asset) => Number(this.field(asset, field)) >= value)
|
|
252
|
+
return this
|
|
253
|
+
}
|
|
254
|
+
lt(field: Comparable, value: number) {
|
|
255
|
+
this.filters.push((asset) => Number(this.field(asset, field)) < value)
|
|
256
|
+
return this
|
|
257
|
+
}
|
|
258
|
+
lte(field: Comparable, value: number) {
|
|
259
|
+
this.filters.push((asset) => Number(this.field(asset, field)) <= value)
|
|
260
|
+
return this
|
|
261
|
+
}
|
|
262
|
+
limit(limit: number) {
|
|
263
|
+
this.count = limit
|
|
264
|
+
return this
|
|
265
|
+
}
|
|
266
|
+
offset(offset: number) {
|
|
267
|
+
this.skip = offset
|
|
268
|
+
return this
|
|
269
|
+
}
|
|
270
|
+
orderBy(descriptors: string | { key: string; ascending?: boolean } | (string | { key: string; ascending?: boolean })[]) {
|
|
271
|
+
const list = Array.isArray(descriptors) ? descriptors : [descriptors]
|
|
272
|
+
this.sort = list.map((item) => (typeof item === 'string' ? { key: item, ascending: true } : { key: item.key, ascending: item.ascending ?? true }))
|
|
273
|
+
return this
|
|
274
|
+
}
|
|
275
|
+
album(album: NativeAlbum) {
|
|
276
|
+
this.albumId = album.id
|
|
277
|
+
return this
|
|
278
|
+
}
|
|
279
|
+
private run() {
|
|
280
|
+
ensurePermission()
|
|
281
|
+
const inAlbum = this.albumId === null ? null : new Set(albumOf(this.albumId).assetIds)
|
|
282
|
+
let assets = libraryPhotos()
|
|
283
|
+
.filter((photo) => inAlbum === null || inAlbum.has(photo.id))
|
|
284
|
+
.map(metadata)
|
|
285
|
+
.filter((asset) => this.filters.every((filter) => filter(asset)))
|
|
286
|
+
for (const { key, ascending } of [...this.sort].reverse()) {
|
|
287
|
+
assets = [...assets].sort((a, b) => {
|
|
288
|
+
const order = Number(this.field(a, key) ?? 0) - Number(this.field(b, key) ?? 0)
|
|
289
|
+
return ascending ? order : -order
|
|
290
|
+
})
|
|
291
|
+
}
|
|
292
|
+
return assets.slice(this.skip, this.count === null ? undefined : this.skip + this.count)
|
|
293
|
+
}
|
|
294
|
+
async exe() {
|
|
295
|
+
return this.run().map((asset) => new NativeAsset(asset.id))
|
|
296
|
+
}
|
|
297
|
+
async exeForMetadata() {
|
|
298
|
+
return this.run()
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export const NativeMediaLibraryModule = {
|
|
303
|
+
Asset: NativeAsset,
|
|
304
|
+
Album: NativeAlbum,
|
|
305
|
+
Query: NativeQuery,
|
|
306
|
+
async getPermissionsAsync(_writeOnly?: boolean, _granular?: string[]) {
|
|
307
|
+
return libraryPermission(getPermission('photos'))
|
|
308
|
+
},
|
|
309
|
+
async requestPermissionsAsync(_writeOnly?: boolean, _granular?: string[]) {
|
|
310
|
+
return libraryPermission(await requestPermission('photos'))
|
|
311
|
+
},
|
|
312
|
+
async presentPermissionsPicker(_mediaTypes?: string[]) {},
|
|
313
|
+
addListener(eventName: string, listener: (event: unknown) => void) {
|
|
314
|
+
return { remove: eventName === 'mediaLibraryDidChange' ? onLibraryChange(listener) : () => undefined }
|
|
315
|
+
},
|
|
316
|
+
removeAllListeners(_eventName: string) {},
|
|
317
|
+
}
|
|
318
|
+
export { NativeAsset, NativeAlbum, NativeQuery }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineOverrides } from '../../../../src/node/overrides/define.ts'
|
|
2
|
+
import { simulatedPlatform } from '../../../../src/node/overrides/platformPatch.ts'
|
|
3
|
+
|
|
4
|
+
export default defineOverrides('expo-media-library', [
|
|
5
|
+
{
|
|
6
|
+
versions: '>=58 <59',
|
|
7
|
+
note: "the photos panel's library and albums, the same the photo picker shows; what the app saves shows in the panel",
|
|
8
|
+
files: {
|
|
9
|
+
'build/next/native/NativeMediaLibraryModule.web.js': './NativeMediaLibraryModule.ts',
|
|
10
|
+
'build/legacy/ExpoMediaLibrary.web.js': './ExpoMediaLibrary.ts',
|
|
11
|
+
},
|
|
12
|
+
patch: [
|
|
13
|
+
simulatedPlatform('build/next/js/AssetAlbum.js'),
|
|
14
|
+
simulatedPlatform('build/next/js/Permissions.js'),
|
|
15
|
+
simulatedPlatform('build/next/js/Query.js'),
|
|
16
|
+
simulatedPlatform('build/legacy/MediaLibrary.js'),
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
])
|