@hortemo/expo-photos 1.0.0 → 3.0.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/ExpoPhotos.podspec +1 -1
- package/README.md +1 -0
- package/build/ExpoPhotos.types.d.ts +9 -2
- package/build/ExpoPhotos.types.d.ts.map +1 -1
- package/build/ExpoPhotos.types.js.map +1 -1
- package/build/ExpoPhotosModule.d.ts +2 -2
- package/build/ExpoPhotosModule.d.ts.map +1 -1
- package/build/ExpoPhotosModule.js.map +1 -1
- package/build/PHImageSource.d.ts +32 -0
- package/build/PHImageSource.d.ts.map +1 -0
- package/build/PHImageSource.js +46 -0
- package/build/PHImageSource.js.map +1 -0
- package/build/index.d.ts +2 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/expo-module.config.json +1 -2
- package/ios/ExpoPhotos.podspec +24 -0
- package/ios/ExpoPhotosImageLoader.swift +187 -0
- package/ios/ExpoPhotosModule.swift +41 -18
- package/package.json +11 -1
- package/src/ExpoPhotos.types.ts +12 -2
- package/src/ExpoPhotosModule.ts +2 -1
- package/src/PHImageSource.tsx +86 -0
- package/src/index.ts +2 -0
package/ExpoPhotos.podspec
CHANGED
package/README.md
CHANGED
|
@@ -16,3 +16,4 @@ npm install @hortemo/expo-photos
|
|
|
16
16
|
- `pickAssets(options: PickAssetsOptions): Promise<PHAsset[]>`
|
|
17
17
|
- `requestAuthorization(accessLevel: PHAccessLevel): Promise<PHAuthorizationStatus>`
|
|
18
18
|
- `presentLimitedLibraryPicker(): Promise<void>`
|
|
19
|
+
- `createPHImageSource(options: PHImageSourceOptions): ImageSourcePropType | undefined`
|
|
@@ -48,6 +48,8 @@ export interface CGSize {
|
|
|
48
48
|
width: number;
|
|
49
49
|
height: number;
|
|
50
50
|
}
|
|
51
|
+
export type PHImageManagerMaximumSize = "PHImageManagerMaximumSize";
|
|
52
|
+
export type RequestImageTargetSize = CGSize | PHImageManagerMaximumSize;
|
|
51
53
|
export declare enum PHImageRequestOptionsResizeMode {
|
|
52
54
|
None = 0,
|
|
53
55
|
Fast = 1,
|
|
@@ -149,11 +151,16 @@ export interface AVAssetExportSessionOptions {
|
|
|
149
151
|
}
|
|
150
152
|
export interface RequestImageOptions extends PHImageRequestOptions, SDImageCoderOptions {
|
|
151
153
|
localIdentifier: string;
|
|
152
|
-
targetSize:
|
|
154
|
+
targetSize: RequestImageTargetSize;
|
|
153
155
|
contentMode: PHImageContentMode;
|
|
154
|
-
outputURL
|
|
156
|
+
outputURL?: string;
|
|
155
157
|
timeout?: number;
|
|
156
158
|
}
|
|
159
|
+
export interface RequestImageResult {
|
|
160
|
+
size: CGSize;
|
|
161
|
+
scale: number;
|
|
162
|
+
imageOrientation: number;
|
|
163
|
+
}
|
|
157
164
|
export interface RequestVideoOptions extends PHVideoRequestOptions, AVAssetExportSessionOptions {
|
|
158
165
|
localIdentifier: string;
|
|
159
166
|
exportPreset: AVAssetExportPreset;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoPhotos.types.d.ts","sourceRoot":"","sources":["../src/ExpoPhotos.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,aAAa,EAAE,mBAAmB,CAAC;IACnC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,oBAAY,qBAAqB;IAC/B,aAAa,IAAI;IACjB,UAAU,IAAI;IACd,MAAM,IAAI;IACV,UAAU,IAAI;IACd,OAAO,IAAI;CACZ;AAED,oBAAY,aAAa;IACvB,OAAO,IAAI;IACX,SAAS,IAAI;CACd;AAED,oBAAY,gBAAgB;IAC1B,OAAO,IAAI;IACX,KAAK,IAAI;IACT,KAAK,IAAI;IACT,KAAK,IAAI;CACV;AAED,oBAAY,mBAAmB;IAC7B,IAAI,IAAI;IACR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BX;AA7BD,WAAY,mBAAmB;IAC7B,mEAA4C,CAAA;IAC5C,yEAAkD,CAAA;IAClD,2EAAoD,CAAA;IACpD,mFAA4D,CAAA;IAC5D,qGAA8E,CAAA;IAC9E,gEAAyC,CAAA;IACzC,gEAAyC,CAAA;IACzC,kEAA2C,CAAA;IAC3C,oEAA6C,CAAA;IAC7C,oEAA6C,CAAA;IAC7C,yEAAkD,CAAA;IAClD,yEAAkD,CAAA;IAClD,2FAAoE,CAAA;IACpE,2FAAoE,CAAA;IACpE,yEAAkD,CAAA;IAClD,yEAAkD,CAAA;IAClD,6EAAsD,CAAA;IACtD,2EAAoD,CAAA;IACpD,2EAAoD,CAAA;IACpD,6EAAsD,CAAA;IACtD,uEAAgD,CAAA;IAChD,6EAAsD,CAAA;IACtD,+EAAwD,CAAA;IACxD,uEAAgD,CAAA;IAChD,mFAA4D,CAAA;IAC5D,qFAA8D,CAAA;IAC9D,qEAA8C,CAAA;IAC9C,+DAAwC,CAAA;AAC1C,CAAC,EA7BW,mBAAmB,KAAnB,mBAAmB,QA6B9B;AAiCD,MAAM,CAAN,IAAY,cAIX;AAJD,WAAY,cAAc;IACxB,mCAAiB,CAAA;IACjB,mCAAiB,CAAA;IACjB,6BAAW,CAAA;AACb,CAAC,EAJW,cAAc,KAAd,cAAc,QAIzB","sourcesContent":["export interface PHAsset {\n localIdentifier: string;\n creationDate: number;\n mediaType: PHAssetMediaType;\n mediaSubtypes: PHAssetMediaSubtype;\n duration: number;\n}\n\nexport enum PHAuthorizationStatus {\n notDetermined = 0,\n restricted = 1,\n denied = 2,\n authorized = 3,\n limited = 4,\n}\n\nexport enum PHAccessLevel {\n addOnly = 1,\n readWrite = 2,\n}\n\nexport enum PHAssetMediaType {\n Unknown = 0,\n Image = 1,\n Video = 2,\n Audio = 3,\n}\n\nexport enum PHAssetMediaSubtype {\n None = 0,\n PhotoPanorama = 1 << 0,\n PhotoHDR = 1 << 1,\n PhotoScreenshot = 1 << 2,\n PhotoLive = 1 << 3,\n PhotoDepthEffect = 1 << 4,\n VideoStreamed = 1 << 16,\n VideoHighFrameRate = 1 << 17,\n VideoTimelapse = 1 << 18,\n VideoCinematic = 1 << 19,\n}\n\nexport interface NSSortDescriptor {\n key: string;\n ascending: boolean;\n}\n\nexport interface PHFetchOptions {\n predicate?: string;\n fetchLimit?: number;\n sortDescriptors?: NSSortDescriptor[];\n}\n\nexport type FetchAssetsOptions = PHFetchOptions;\n\nexport interface CGSize {\n width: number;\n height: number;\n}\n\nexport type PHImageManagerMaximumSize = \"PHImageManagerMaximumSize\";\n\nexport type RequestImageTargetSize = CGSize | PHImageManagerMaximumSize;\n\nexport enum PHImageRequestOptionsResizeMode {\n None = 0,\n Fast = 1,\n Exact = 2,\n}\n\nexport enum PHImageRequestOptionsDeliveryMode {\n Opportunistic = 0,\n HighQualityFormat = 1,\n FastFormat = 2,\n}\n\nexport enum PHImageContentMode {\n aspectFit = 0,\n aspectFill = 1,\n}\n\nexport interface PHImageRequestOptions {\n isNetworkAccessAllowed?: boolean;\n resizeMode?: PHImageRequestOptionsResizeMode;\n deliveryMode?: PHImageRequestOptionsDeliveryMode;\n}\n\nexport interface SDImageCoderOptions {\n encodeCompressionQuality?: number;\n encodeMaxFileSize?: number;\n}\n\nexport enum PHVideoRequestOptionsDeliveryMode {\n Automatic = 0,\n HighQualityFormat = 1,\n MediumQualityFormat = 2,\n FastFormat = 3,\n}\n\nexport interface PHVideoRequestOptions {\n isNetworkAccessAllowed?: boolean;\n deliveryMode?: PHVideoRequestOptionsDeliveryMode;\n}\n\nexport interface CMTimeRange {\n start: number;\n duration: number;\n}\n\nexport enum AVFileType {\n ac3 = \"public.ac3-audio\",\n aifc = \"public.aifc-audio\",\n aiff = \"public.aiff-audio\",\n AHAP = \"com.apple.itt\",\n amr = \"org.3gpp.adaptive-multi-rate-audio\",\n appleiTT = \"com.apple.itt\",\n au = \"public.au-audio\",\n avci = \"public.avci\",\n caf = \"com.apple.coreaudio-format\",\n dng = \"com.adobe.raw-image\",\n eac3 = \"public.eac3-audio\",\n heic = \"public.heic\",\n heif = \"public.heif\",\n jpg = \"public.jpeg\",\n m4a = \"com.apple.m4a-audio\",\n m4v = \"com.apple.m4v-video\",\n mobile3GPP = \"public.3gpp\",\n mobile3GPP2 = \"public.3gpp2\",\n mov = \"com.apple.quicktime-movie\",\n mp3 = \"public.mp3\",\n mp4 = \"public.mpeg-4\",\n SCC = \"com.scenarist.cc\",\n tif = \"public.tiff\",\n wav = \"com.microsoft.waveform-audio\",\n}\n\nexport enum AVAssetExportPreset {\n LowQuality = \"AVAssetExportPresetLowQuality\",\n MediumQuality = \"AVAssetExportPresetMediumQuality\",\n HighestQuality = \"AVAssetExportPresetHighestQuality\",\n HEVCHighestQuality = \"AVAssetExportPresetHEVCHighestQuality\",\n HEVCHighestQualityWithAlpha = \"AVAssetExportPresetHEVCHighestQualityWithAlpha\",\n AVC640x480 = \"AVAssetExportPreset640x480\",\n AVC960x540 = \"AVAssetExportPreset960x540\",\n AVC1280x720 = \"AVAssetExportPreset1280x720\",\n AVC1920x1080 = \"AVAssetExportPreset1920x1080\",\n AVC3840x2160 = \"AVAssetExportPreset3840x2160\",\n HEVC1920x1080 = \"AVAssetExportPresetHEVC1920x1080\",\n HEVC3840x2160 = \"AVAssetExportPresetHEVC3840x2160\",\n HEVC1920x1080WithAlpha = \"AVAssetExportPresetHEVC1920x1080WithAlpha\",\n HEVC3840x2160WithAlpha = \"AVAssetExportPresetHEVC3840x2160WithAlpha\",\n HEVC7680x4320 = \"AVAssetExportPresetHEVC7680x4320\",\n MVHEVC960x960 = \"AVAssetExportPresetMVHEVC960x960\",\n MVHEVC1440x1440 = \"AVAssetExportPresetMVHEVC1440x1440\",\n AppleM4V480pSD = \"AVAssetExportPresetAppleM4V480pSD\",\n AppleM4V720pHD = \"AVAssetExportPresetAppleM4V720pHD\",\n AppleM4V1080pHD = \"AVAssetExportPresetAppleM4V1080pHD\",\n AppleM4ViPod = \"AVAssetExportPresetAppleM4ViPod\",\n AppleM4VAppleTV = \"AVAssetExportPresetAppleM4VAppleTV\",\n AppleM4VCellular = \"AVAssetExportPresetAppleM4VCellular\",\n AppleM4VWiFi = \"AVAssetExportPresetAppleM4VWiFi\",\n AppleProRes422LPCM = \"AVAssetExportPresetAppleProRes422LPCM\",\n AppleProRes4444LPCM = \"AVAssetExportPresetAppleProRes4444LPCM\",\n Passthrough = \"AVAssetExportPresetPassthrough\",\n AppleM4A = \"AVAssetExportPresetAppleM4A\",\n}\n\nexport interface AVAssetExportSessionOptions {\n outputURL: string;\n outputFileType?: AVFileType;\n fileLengthLimit?: number;\n timeRange?: CMTimeRange;\n}\n\nexport interface RequestImageOptions\n extends PHImageRequestOptions,\n SDImageCoderOptions {\n localIdentifier: string;\n targetSize: RequestImageTargetSize;\n contentMode: PHImageContentMode;\n outputURL?: string;\n timeout?: number;\n}\n\nexport interface RequestImageResult {\n size: CGSize;\n scale: number;\n imageOrientation: number;\n}\n\nexport interface RequestVideoOptions\n extends PHVideoRequestOptions,\n AVAssetExportSessionOptions {\n localIdentifier: string;\n exportPreset: AVAssetExportPreset;\n timeout?: number;\n}\n\nexport enum PHPickerFilter {\n images = \"images\",\n videos = \"videos\",\n any = \"any\",\n}\n\nexport interface PickAssetsOptions {\n filter?: PHPickerFilter;\n selectionLimit?: number;\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NativeModule } from "expo-modules-core";
|
|
2
|
-
import type { FetchAssetsOptions, PHAuthorizationStatus, PHAccessLevel, PHAsset, PickAssetsOptions, RequestImageOptions, RequestVideoOptions } from "./ExpoPhotos.types";
|
|
2
|
+
import type { FetchAssetsOptions, PHAuthorizationStatus, PHAccessLevel, PHAsset, PickAssetsOptions, RequestImageOptions, RequestVideoOptions, RequestImageResult } from "./ExpoPhotos.types";
|
|
3
3
|
export declare class ExpoPhotosModule extends NativeModule {
|
|
4
4
|
fetchAssets(options: FetchAssetsOptions): Promise<PHAsset[]>;
|
|
5
|
-
requestImage(options: RequestImageOptions): Promise<
|
|
5
|
+
requestImage(options: RequestImageOptions): Promise<RequestImageResult>;
|
|
6
6
|
requestVideo(options: RequestVideoOptions): Promise<void>;
|
|
7
7
|
pickAssets(options: PickAssetsOptions): Promise<PHAsset[]>;
|
|
8
8
|
requestAuthorization(accessLevel: PHAccessLevel): Promise<PHAuthorizationStatus>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoPhotosModule.d.ts","sourceRoot":"","sources":["../src/ExpoPhotosModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAuB,MAAM,mBAAmB,CAAC;AACtE,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,aAAa,EACb,OAAO,EACP,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"ExpoPhotosModule.d.ts","sourceRoot":"","sources":["../src/ExpoPhotosModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAuB,MAAM,mBAAmB,CAAC;AACtE,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,aAAa,EACb,OAAO,EACP,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,YAAY;IACxD,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAC5D,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IACvE,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IACzD,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAC1D,oBAAoB,CAAC,WAAW,EAAE,aAAa,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAChF,2BAA2B,IAAI,OAAO,CAAC,IAAI,CAAC;CAC7C;;AAED,wBAAmE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoPhotosModule.js","sourceRoot":"","sources":["../src/ExpoPhotosModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"ExpoPhotosModule.js","sourceRoot":"","sources":["../src/ExpoPhotosModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAqBtE,eAAe,mBAAmB,CAAmB,YAAY,CAAC,CAAC","sourcesContent":["import { NativeModule, requireNativeModule } from \"expo-modules-core\";\nimport type {\n FetchAssetsOptions,\n PHAuthorizationStatus,\n PHAccessLevel,\n PHAsset,\n PickAssetsOptions,\n RequestImageOptions,\n RequestVideoOptions,\n RequestImageResult,\n} from \"./ExpoPhotos.types\";\n\nexport declare class ExpoPhotosModule extends NativeModule {\n fetchAssets(options: FetchAssetsOptions): Promise<PHAsset[]>;\n requestImage(options: RequestImageOptions): Promise<RequestImageResult>;\n requestVideo(options: RequestVideoOptions): Promise<void>;\n pickAssets(options: PickAssetsOptions): Promise<PHAsset[]>;\n requestAuthorization(accessLevel: PHAccessLevel): Promise<PHAuthorizationStatus>;\n presentLimitedLibraryPicker(): Promise<void>;\n}\n\nexport default requireNativeModule<ExpoPhotosModule>(\"ExpoPhotos\");\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ImageSourcePropType } from "react-native";
|
|
2
|
+
import { PHImageContentMode, PHImageRequestOptionsDeliveryMode, PHImageRequestOptionsResizeMode, RequestImageTargetSize } from "./ExpoPhotos.types";
|
|
3
|
+
export interface PHImageSourceOptions {
|
|
4
|
+
localIdentifier: string;
|
|
5
|
+
targetSize?: RequestImageTargetSize;
|
|
6
|
+
resizeMode?: PHImageRequestOptionsResizeMode;
|
|
7
|
+
deliveryMode?: PHImageRequestOptionsDeliveryMode;
|
|
8
|
+
contentMode?: PHImageContentMode;
|
|
9
|
+
isNetworkAccessAllowed?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a source object for React Native's Image component from a Photos library asset identifier.
|
|
13
|
+
*
|
|
14
|
+
* @param options - Configuration for image source, including the local identifier
|
|
15
|
+
* @returns A source object that can be used with the Image component's `source` prop, or undefined if no identifier is provided
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* import { Image } from 'react-native';
|
|
20
|
+
* import { createPHImageSource } from '@hortemo/expo-photos';
|
|
21
|
+
*
|
|
22
|
+
* <Image
|
|
23
|
+
* source={createPHImageSource({
|
|
24
|
+
* localIdentifier: asset.localIdentifier,
|
|
25
|
+
* targetSize: { width: 200, height: 200 },
|
|
26
|
+
* contentMode: PHImageContentMode.aspectFill,
|
|
27
|
+
* })}
|
|
28
|
+
* />
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function createPHImageSource(options: PHImageSourceOptions): ImageSourcePropType;
|
|
32
|
+
//# sourceMappingURL=PHImageSource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PHImageSource.d.ts","sourceRoot":"","sources":["../src/PHImageSource.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EACL,kBAAkB,EAClB,iCAAiC,EACjC,+BAA+B,EAC/B,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,oBAAoB;IACnC,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,sBAAsB,CAAC;IACpC,UAAU,CAAC,EAAE,+BAA+B,CAAC;IAC7C,YAAY,CAAC,EAAE,iCAAiC,CAAC;IACjD,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAwBD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,oBAAoB,GAC5B,mBAAmB,CAwBrB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const buildQueryString = (params) => {
|
|
2
|
+
const entries = Object.entries(params).filter(([, value]) => value !== undefined);
|
|
3
|
+
if (entries.length === 0) {
|
|
4
|
+
return "";
|
|
5
|
+
}
|
|
6
|
+
return ("?" +
|
|
7
|
+
entries
|
|
8
|
+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value ?? "")}`)
|
|
9
|
+
.join("&"));
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Creates a source object for React Native's Image component from a Photos library asset identifier.
|
|
13
|
+
*
|
|
14
|
+
* @param options - Configuration for image source, including the local identifier
|
|
15
|
+
* @returns A source object that can be used with the Image component's `source` prop, or undefined if no identifier is provided
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* import { Image } from 'react-native';
|
|
20
|
+
* import { createPHImageSource } from '@hortemo/expo-photos';
|
|
21
|
+
*
|
|
22
|
+
* <Image
|
|
23
|
+
* source={createPHImageSource({
|
|
24
|
+
* localIdentifier: asset.localIdentifier,
|
|
25
|
+
* targetSize: { width: 200, height: 200 },
|
|
26
|
+
* contentMode: PHImageContentMode.aspectFill,
|
|
27
|
+
* })}
|
|
28
|
+
* />
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function createPHImageSource(options) {
|
|
32
|
+
const { localIdentifier, resizeMode, deliveryMode, contentMode, isNetworkAccessAllowed, } = options;
|
|
33
|
+
const targetSize = options.targetSize && typeof options.targetSize === "object"
|
|
34
|
+
? `${options.targetSize.width}x${options.targetSize.height}`
|
|
35
|
+
: options.targetSize;
|
|
36
|
+
const query = buildQueryString({
|
|
37
|
+
localIdentifier,
|
|
38
|
+
targetSize,
|
|
39
|
+
resizeMode,
|
|
40
|
+
deliveryMode,
|
|
41
|
+
contentMode,
|
|
42
|
+
isNetworkAccessAllowed,
|
|
43
|
+
});
|
|
44
|
+
return { uri: `expo-photos://${query}` };
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=PHImageSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PHImageSource.js","sourceRoot":"","sources":["../src/PHImageSource.tsx"],"names":[],"mappings":"AAiBA,MAAM,gBAAgB,GAAG,CACvB,MAA6D,EACrD,EAAE;IACV,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAC3C,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CACnC,CAAC;IAEF,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,CACL,GAAG;QACH,OAAO;aACJ,GAAG,CACF,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CACf,GAAG,kBAAkB,CAAC,GAAG,CAAC,IAAI,kBAAkB,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAClE;aACA,IAAI,CAAC,GAAG,CAAC,CACb,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAA6B;IAE7B,MAAM,EACJ,eAAe,EACf,UAAU,EACV,YAAY,EACZ,WAAW,EACX,sBAAsB,GACvB,GAAG,OAAO,CAAC;IAEZ,MAAM,UAAU,GACd,OAAO,CAAC,UAAU,IAAI,OAAO,OAAO,CAAC,UAAU,KAAK,QAAQ;QAC1D,CAAC,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,IAAI,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE;QAC5D,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;IAEzB,MAAM,KAAK,GAAG,gBAAgB,CAAC;QAC7B,eAAe;QACf,UAAU;QACV,UAAU;QACV,YAAY;QACZ,WAAW;QACX,sBAAsB;KACvB,CAAC,CAAC;IAEH,OAAO,EAAE,GAAG,EAAE,iBAAiB,KAAK,EAAE,EAAE,CAAC;AAC3C,CAAC","sourcesContent":["import type { ImageSourcePropType } from \"react-native\";\nimport {\n PHImageContentMode,\n PHImageRequestOptionsDeliveryMode,\n PHImageRequestOptionsResizeMode,\n RequestImageTargetSize,\n} from \"./ExpoPhotos.types\";\n\nexport interface PHImageSourceOptions {\n localIdentifier: string;\n targetSize?: RequestImageTargetSize;\n resizeMode?: PHImageRequestOptionsResizeMode;\n deliveryMode?: PHImageRequestOptionsDeliveryMode;\n contentMode?: PHImageContentMode;\n isNetworkAccessAllowed?: boolean;\n}\n\nconst buildQueryString = (\n params: Record<string, string | number | boolean | undefined>\n): string => {\n const entries = Object.entries(params).filter(\n ([, value]) => value !== undefined\n );\n\n if (entries.length === 0) {\n return \"\";\n }\n\n return (\n \"?\" +\n entries\n .map(\n ([key, value]) =>\n `${encodeURIComponent(key)}=${encodeURIComponent(value ?? \"\")}`\n )\n .join(\"&\")\n );\n};\n\n/**\n * Creates a source object for React Native's Image component from a Photos library asset identifier.\n *\n * @param options - Configuration for image source, including the local identifier\n * @returns A source object that can be used with the Image component's `source` prop, or undefined if no identifier is provided\n *\n * @example\n * ```tsx\n * import { Image } from 'react-native';\n * import { createPHImageSource } from '@hortemo/expo-photos';\n *\n * <Image\n * source={createPHImageSource({\n * localIdentifier: asset.localIdentifier,\n * targetSize: { width: 200, height: 200 },\n * contentMode: PHImageContentMode.aspectFill,\n * })}\n * />\n * ```\n */\nexport function createPHImageSource(\n options: PHImageSourceOptions\n): ImageSourcePropType {\n const {\n localIdentifier,\n resizeMode,\n deliveryMode,\n contentMode,\n isNetworkAccessAllowed,\n } = options;\n\n const targetSize =\n options.targetSize && typeof options.targetSize === \"object\"\n ? `${options.targetSize.width}x${options.targetSize.height}`\n : options.targetSize;\n\n const query = buildQueryString({\n localIdentifier,\n targetSize,\n resizeMode,\n deliveryMode,\n contentMode,\n isNetworkAccessAllowed,\n });\n\n return { uri: `expo-photos://${query}` };\n}\n"]}
|
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,YAAY,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/build/index.js
CHANGED
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,cAAc,oBAAoB,CAAC","sourcesContent":["export { default } from \"./ExpoPhotosModule\";\nexport * from \"./ExpoPhotos.types\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["export { default } from \"./ExpoPhotosModule\";\nexport * from \"./ExpoPhotos.types\";\nexport { createPHImageSource } from \"./PHImageSource\";\nexport type { PHImageSourceOptions } from \"./PHImageSource\";\n"]}
|
package/expo-module.config.json
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'ExpoPhotos'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.description = package['description']
|
|
10
|
+
s.license = package['license']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.homepage = package['homepage']
|
|
13
|
+
s.platform = :ios, '15.0'
|
|
14
|
+
s.swift_version = '5.9'
|
|
15
|
+
s.source = { git: package['repository'] || 'https://github.com/hortemo/expo-photos' }
|
|
16
|
+
s.static_framework = true
|
|
17
|
+
|
|
18
|
+
s.dependency 'ExpoModulesCore'
|
|
19
|
+
s.dependency 'React-Core'
|
|
20
|
+
s.dependency 'SDWebImageWebPCoder', '0.15.0'
|
|
21
|
+
|
|
22
|
+
s.source_files = '**/*.{h,m,swift}'
|
|
23
|
+
s.requires_arc = true
|
|
24
|
+
end
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
#if canImport(React)
|
|
2
|
+
import Foundation
|
|
3
|
+
import Photos
|
|
4
|
+
import React
|
|
5
|
+
import UIKit
|
|
6
|
+
|
|
7
|
+
@objc(ExpoPhotosImageLoader)
|
|
8
|
+
class ExpoPhotosImageLoader: NSObject, RCTBridgeModule, RCTImageURLLoader {
|
|
9
|
+
static func moduleName() -> String! {
|
|
10
|
+
return "ExpoPhotosImageLoader"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static func requiresMainQueueSetup() -> Bool {
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// MARK: - Helper Functions
|
|
18
|
+
|
|
19
|
+
private static func queryItems(from url: URL) -> [String: String] {
|
|
20
|
+
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
|
|
21
|
+
let queryItems = components.queryItems else {
|
|
22
|
+
return [:]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var result: [String: String] = [:]
|
|
26
|
+
for item in queryItems {
|
|
27
|
+
if let value = item.value {
|
|
28
|
+
result[item.name] = value
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// MARK: - RCTImageURLLoader
|
|
35
|
+
|
|
36
|
+
func canLoadImageURL(_ requestURL: URL) -> Bool {
|
|
37
|
+
return requestURL.scheme?.caseInsensitiveCompare("expo-photos") == .orderedSame
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
func loaderPriority() -> Float {
|
|
41
|
+
return 1.0
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func loadImage(
|
|
45
|
+
for imageURL: URL,
|
|
46
|
+
size: CGSize,
|
|
47
|
+
scale: CGFloat,
|
|
48
|
+
resizeMode: RCTResizeMode,
|
|
49
|
+
progressHandler: RCTImageLoaderProgressBlock!,
|
|
50
|
+
partialLoadHandler: RCTImageLoaderPartialLoadBlock!,
|
|
51
|
+
completionHandler: @escaping RCTImageLoaderCompletionBlock
|
|
52
|
+
) -> RCTImageLoaderCancellationBlock! {
|
|
53
|
+
|
|
54
|
+
guard imageURL.scheme?.caseInsensitiveCompare("expo-photos") == .orderedSame else {
|
|
55
|
+
completionHandler(RCTErrorWithMessage("Unsupported image URL scheme for ExpoPhotos"), nil)
|
|
56
|
+
return {}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let queryParams = Self.queryItems(from: imageURL)
|
|
60
|
+
|
|
61
|
+
guard let localIdentifier = queryParams["localIdentifier"], !localIdentifier.isEmpty else {
|
|
62
|
+
completionHandler(RCTErrorWithMessage("Missing localIdentifier query parameter"), nil)
|
|
63
|
+
return {}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let assets = PHAsset.fetchAssets(withLocalIdentifiers: [localIdentifier], options: nil)
|
|
67
|
+
guard let asset = assets.firstObject else {
|
|
68
|
+
completionHandler(RCTErrorWithMessage("Failed to fetch PHAsset with local identifier \(localIdentifier)"), nil)
|
|
69
|
+
return {}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let imageOptions = PHImageRequestOptions()
|
|
73
|
+
|
|
74
|
+
var targetSize = size.applying(CGAffineTransform(scaleX: scale, y: scale))
|
|
75
|
+
|
|
76
|
+
if let targetSizeString = queryParams["targetSize"] {
|
|
77
|
+
if targetSizeString.caseInsensitiveCompare("PHImageManagerMaximumSize") == .orderedSame {
|
|
78
|
+
targetSize = PHImageManagerMaximumSize
|
|
79
|
+
} else {
|
|
80
|
+
let components = targetSizeString.lowercased().components(separatedBy: "x")
|
|
81
|
+
guard components.count == 2,
|
|
82
|
+
let width = Double(components[0]),
|
|
83
|
+
let height = Double(components[1]) else {
|
|
84
|
+
completionHandler(RCTErrorWithMessage("Invalid targetSize format. Expected WIDTHxHEIGHT or PHImageManagerMaximumSize."), nil)
|
|
85
|
+
return {}
|
|
86
|
+
}
|
|
87
|
+
targetSize = CGSize(width: width, height: height)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if let deliveryModeString = queryParams["deliveryMode"] {
|
|
92
|
+
guard let deliveryMode = PHImageRequestOptionsDeliveryMode.from(queryParam: deliveryModeString) else {
|
|
93
|
+
completionHandler(RCTErrorWithMessage("Invalid deliveryMode value."), nil)
|
|
94
|
+
return {}
|
|
95
|
+
}
|
|
96
|
+
imageOptions.deliveryMode = deliveryMode
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if let resizeModeString = queryParams["resizeMode"] {
|
|
100
|
+
guard let resizeMode = PHImageRequestOptionsResizeMode.from(queryParam: resizeModeString) else {
|
|
101
|
+
completionHandler(RCTErrorWithMessage("Invalid resizeMode value."), nil)
|
|
102
|
+
return {}
|
|
103
|
+
}
|
|
104
|
+
imageOptions.resizeMode = resizeMode
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if let isNetworkAccessAllowedString = queryParams["isNetworkAccessAllowed"] {
|
|
108
|
+
imageOptions.isNetworkAccessAllowed = Bool.from(queryParam: isNetworkAccessAllowedString)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
var contentMode: PHImageContentMode = .default
|
|
112
|
+
if let contentModeString = queryParams["contentMode"] {
|
|
113
|
+
guard let _contentMode = PHImageContentMode.from(queryParam: contentModeString) else {
|
|
114
|
+
completionHandler(RCTErrorWithMessage("Invalid contentMode value."), nil)
|
|
115
|
+
return {}
|
|
116
|
+
}
|
|
117
|
+
contentMode = _contentMode
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if let progressHandler = progressHandler {
|
|
121
|
+
imageOptions.progressHandler = { progress, error, stop, info in
|
|
122
|
+
let multiplier: Int64 = 1_000_000
|
|
123
|
+
progressHandler(Int64(progress * Double(multiplier)), multiplier)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let requestID = PHImageManager.default().requestImage(
|
|
128
|
+
for: asset,
|
|
129
|
+
targetSize: targetSize,
|
|
130
|
+
contentMode: contentMode,
|
|
131
|
+
options: imageOptions
|
|
132
|
+
) { result, info in
|
|
133
|
+
guard let info = info else {
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let isCancelled = (info[PHImageCancelledKey] as? NSNumber)?.boolValue ?? false
|
|
138
|
+
let isDegraded = (info[PHImageResultIsDegradedKey] as? NSNumber)?.boolValue ?? false
|
|
139
|
+
|
|
140
|
+
if isCancelled {
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if let result = result {
|
|
145
|
+
if isDegraded {
|
|
146
|
+
partialLoadHandler?(result)
|
|
147
|
+
} else {
|
|
148
|
+
completionHandler(nil, result)
|
|
149
|
+
}
|
|
150
|
+
} else if let error = info[PHImageErrorKey] as? Error {
|
|
151
|
+
completionHandler(error, nil)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
PHImageManager.default().cancelImageRequest(requestID)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// MARK: - RawRepresentable Extension
|
|
162
|
+
|
|
163
|
+
extension RawRepresentable where RawValue == Int {
|
|
164
|
+
static func from(queryParam string: String?) -> Self? {
|
|
165
|
+
guard let string = string, !string.isEmpty else {
|
|
166
|
+
return nil
|
|
167
|
+
}
|
|
168
|
+
guard let intValue = Int(string) else {
|
|
169
|
+
return nil
|
|
170
|
+
}
|
|
171
|
+
return Self(rawValue: intValue)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// MARK: - Bool Extension
|
|
176
|
+
|
|
177
|
+
extension Bool {
|
|
178
|
+
static func from(queryParam string: String?) -> Bool {
|
|
179
|
+
guard let string = string, !string.isEmpty else {
|
|
180
|
+
return false
|
|
181
|
+
}
|
|
182
|
+
return string.lowercased() == "true"
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
#endif
|
|
187
|
+
|
|
@@ -13,7 +13,7 @@ struct FetchAssetsOptions: Record {
|
|
|
13
13
|
|
|
14
14
|
struct RequestImageOptions: Record {
|
|
15
15
|
@Field var localIdentifier: String?
|
|
16
|
-
@Field var targetSize:
|
|
16
|
+
@Field var targetSize: TargetSize?
|
|
17
17
|
@Field var contentMode: PHImageContentMode?
|
|
18
18
|
@Field var isNetworkAccessAllowed: Bool?
|
|
19
19
|
@Field var deliveryMode: PHImageRequestOptionsDeliveryMode?
|
|
@@ -92,12 +92,11 @@ public class ExpoPhotos: Module {
|
|
|
92
92
|
return status.rawValue
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
AsyncFunction("requestImage") { (options: RequestImageOptions) async throws ->
|
|
95
|
+
AsyncFunction("requestImage") { (options: RequestImageOptions) async throws -> [String: Any] in
|
|
96
96
|
guard
|
|
97
97
|
let localIdentifier = options.localIdentifier,
|
|
98
|
-
let targetSize = options.targetSize,
|
|
99
|
-
let contentMode = options.contentMode
|
|
100
|
-
let outputURL = options.outputURL
|
|
98
|
+
let targetSize = options.targetSize?.value,
|
|
99
|
+
let contentMode = options.contentMode
|
|
101
100
|
else {
|
|
102
101
|
throw ExpoPhotosError.mandatoryFieldMissing
|
|
103
102
|
}
|
|
@@ -145,24 +144,35 @@ public class ExpoPhotos: Module {
|
|
|
145
144
|
}
|
|
146
145
|
}
|
|
147
146
|
|
|
148
|
-
|
|
147
|
+
if let outputURL = options.outputURL {
|
|
148
|
+
var imageCoderOptions: [SDImageCoderOption: Any] = [:]
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
if let encodeCompressionQuality = options.encodeCompressionQuality {
|
|
151
|
+
imageCoderOptions[.encodeCompressionQuality] = encodeCompressionQuality
|
|
152
|
+
}
|
|
153
153
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
if let encodeMaxFileSize = options.encodeMaxFileSize {
|
|
155
|
+
imageCoderOptions[.encodeMaxFileSize] = encodeMaxFileSize
|
|
156
|
+
}
|
|
157
157
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
158
|
+
guard
|
|
159
|
+
let data = SDImageWebPCoder.shared.encodedData(
|
|
160
|
+
with: image, format: .webP, options: imageCoderOptions)
|
|
161
|
+
else {
|
|
162
|
+
throw ExpoPhotosError.couldNotEncodeImage
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
try data.write(to: outputURL)
|
|
163
166
|
}
|
|
164
167
|
|
|
165
|
-
|
|
168
|
+
return [
|
|
169
|
+
"size": [
|
|
170
|
+
"width": image.size.width,
|
|
171
|
+
"height": image.size.height,
|
|
172
|
+
],
|
|
173
|
+
"scale": image.scale,
|
|
174
|
+
"imageOrientation": image.imageOrientation.rawValue,
|
|
175
|
+
]
|
|
166
176
|
}
|
|
167
177
|
|
|
168
178
|
AsyncFunction("requestVideo") { (options: RequestVideoOptions) async throws -> Void in
|
|
@@ -393,6 +403,19 @@ extension CMTimeRange: @retroactive Convertible {
|
|
|
393
403
|
}
|
|
394
404
|
}
|
|
395
405
|
|
|
406
|
+
struct TargetSize: Convertible {
|
|
407
|
+
let value: CGSize
|
|
408
|
+
|
|
409
|
+
static func convert(from value: Any?, appContext: AppContext) throws -> TargetSize {
|
|
410
|
+
if let sentinel = value as? String, sentinel == "PHImageManagerMaximumSize" {
|
|
411
|
+
return TargetSize(value: PHImageManagerMaximumSize)
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
let size = try CGSize.convert(from: value, appContext: appContext)
|
|
415
|
+
return TargetSize(value: size)
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
396
419
|
extension Convertible where Self: RawRepresentable, Self.RawValue == Int {
|
|
397
420
|
public static func convert(from value: Any?, appContext: AppContext) throws -> Self {
|
|
398
421
|
guard
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hortemo/expo-photos",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Expo module exposing advanced iOS Photos APIs.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -39,5 +39,15 @@
|
|
|
39
39
|
"expo": "*",
|
|
40
40
|
"react": "*",
|
|
41
41
|
"react-native": "*"
|
|
42
|
+
},
|
|
43
|
+
"codegenConfig": {
|
|
44
|
+
"name": "expo-photos",
|
|
45
|
+
"type": "modules",
|
|
46
|
+
"jsSrcsDir": "./src",
|
|
47
|
+
"ios": {
|
|
48
|
+
"modulesConformingToProtocol": {
|
|
49
|
+
"RCTImageURLLoader": "ExpoPhotosImageLoader"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
42
52
|
}
|
|
43
53
|
}
|
package/src/ExpoPhotos.types.ts
CHANGED
|
@@ -57,6 +57,10 @@ export interface CGSize {
|
|
|
57
57
|
height: number;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
export type PHImageManagerMaximumSize = "PHImageManagerMaximumSize";
|
|
61
|
+
|
|
62
|
+
export type RequestImageTargetSize = CGSize | PHImageManagerMaximumSize;
|
|
63
|
+
|
|
60
64
|
export enum PHImageRequestOptionsResizeMode {
|
|
61
65
|
None = 0,
|
|
62
66
|
Fast = 1,
|
|
@@ -171,12 +175,18 @@ export interface RequestImageOptions
|
|
|
171
175
|
extends PHImageRequestOptions,
|
|
172
176
|
SDImageCoderOptions {
|
|
173
177
|
localIdentifier: string;
|
|
174
|
-
targetSize:
|
|
178
|
+
targetSize: RequestImageTargetSize;
|
|
175
179
|
contentMode: PHImageContentMode;
|
|
176
|
-
outputURL
|
|
180
|
+
outputURL?: string;
|
|
177
181
|
timeout?: number;
|
|
178
182
|
}
|
|
179
183
|
|
|
184
|
+
export interface RequestImageResult {
|
|
185
|
+
size: CGSize;
|
|
186
|
+
scale: number;
|
|
187
|
+
imageOrientation: number;
|
|
188
|
+
}
|
|
189
|
+
|
|
180
190
|
export interface RequestVideoOptions
|
|
181
191
|
extends PHVideoRequestOptions,
|
|
182
192
|
AVAssetExportSessionOptions {
|
package/src/ExpoPhotosModule.ts
CHANGED
|
@@ -7,11 +7,12 @@ import type {
|
|
|
7
7
|
PickAssetsOptions,
|
|
8
8
|
RequestImageOptions,
|
|
9
9
|
RequestVideoOptions,
|
|
10
|
+
RequestImageResult,
|
|
10
11
|
} from "./ExpoPhotos.types";
|
|
11
12
|
|
|
12
13
|
export declare class ExpoPhotosModule extends NativeModule {
|
|
13
14
|
fetchAssets(options: FetchAssetsOptions): Promise<PHAsset[]>;
|
|
14
|
-
requestImage(options: RequestImageOptions): Promise<
|
|
15
|
+
requestImage(options: RequestImageOptions): Promise<RequestImageResult>;
|
|
15
16
|
requestVideo(options: RequestVideoOptions): Promise<void>;
|
|
16
17
|
pickAssets(options: PickAssetsOptions): Promise<PHAsset[]>;
|
|
17
18
|
requestAuthorization(accessLevel: PHAccessLevel): Promise<PHAuthorizationStatus>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { ImageSourcePropType } from "react-native";
|
|
2
|
+
import {
|
|
3
|
+
PHImageContentMode,
|
|
4
|
+
PHImageRequestOptionsDeliveryMode,
|
|
5
|
+
PHImageRequestOptionsResizeMode,
|
|
6
|
+
RequestImageTargetSize,
|
|
7
|
+
} from "./ExpoPhotos.types";
|
|
8
|
+
|
|
9
|
+
export interface PHImageSourceOptions {
|
|
10
|
+
localIdentifier: string;
|
|
11
|
+
targetSize?: RequestImageTargetSize;
|
|
12
|
+
resizeMode?: PHImageRequestOptionsResizeMode;
|
|
13
|
+
deliveryMode?: PHImageRequestOptionsDeliveryMode;
|
|
14
|
+
contentMode?: PHImageContentMode;
|
|
15
|
+
isNetworkAccessAllowed?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const buildQueryString = (
|
|
19
|
+
params: Record<string, string | number | boolean | undefined>
|
|
20
|
+
): string => {
|
|
21
|
+
const entries = Object.entries(params).filter(
|
|
22
|
+
([, value]) => value !== undefined
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (entries.length === 0) {
|
|
26
|
+
return "";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
"?" +
|
|
31
|
+
entries
|
|
32
|
+
.map(
|
|
33
|
+
([key, value]) =>
|
|
34
|
+
`${encodeURIComponent(key)}=${encodeURIComponent(value ?? "")}`
|
|
35
|
+
)
|
|
36
|
+
.join("&")
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates a source object for React Native's Image component from a Photos library asset identifier.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Configuration for image source, including the local identifier
|
|
44
|
+
* @returns A source object that can be used with the Image component's `source` prop, or undefined if no identifier is provided
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```tsx
|
|
48
|
+
* import { Image } from 'react-native';
|
|
49
|
+
* import { createPHImageSource } from '@hortemo/expo-photos';
|
|
50
|
+
*
|
|
51
|
+
* <Image
|
|
52
|
+
* source={createPHImageSource({
|
|
53
|
+
* localIdentifier: asset.localIdentifier,
|
|
54
|
+
* targetSize: { width: 200, height: 200 },
|
|
55
|
+
* contentMode: PHImageContentMode.aspectFill,
|
|
56
|
+
* })}
|
|
57
|
+
* />
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export function createPHImageSource(
|
|
61
|
+
options: PHImageSourceOptions
|
|
62
|
+
): ImageSourcePropType {
|
|
63
|
+
const {
|
|
64
|
+
localIdentifier,
|
|
65
|
+
resizeMode,
|
|
66
|
+
deliveryMode,
|
|
67
|
+
contentMode,
|
|
68
|
+
isNetworkAccessAllowed,
|
|
69
|
+
} = options;
|
|
70
|
+
|
|
71
|
+
const targetSize =
|
|
72
|
+
options.targetSize && typeof options.targetSize === "object"
|
|
73
|
+
? `${options.targetSize.width}x${options.targetSize.height}`
|
|
74
|
+
: options.targetSize;
|
|
75
|
+
|
|
76
|
+
const query = buildQueryString({
|
|
77
|
+
localIdentifier,
|
|
78
|
+
targetSize,
|
|
79
|
+
resizeMode,
|
|
80
|
+
deliveryMode,
|
|
81
|
+
contentMode,
|
|
82
|
+
isNetworkAccessAllowed,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return { uri: `expo-photos://${query}` };
|
|
86
|
+
}
|
package/src/index.ts
CHANGED