From 053dd8cc2104f8a3140a4e2231f399712e209374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Poizat?= Date: Fri, 8 Sep 2023 11:24:24 +0200 Subject: [PATCH] feat(iOS): Include assets originating from an iCloud Shared Album. (#525) * Include assets originating from an iCloud Shared Album. iOS only. * Add a switch to test includeSharedAlbums in GetPhotosPerformanceExample --- .../js/GetPhotosPerformanceExample.tsx | 43 ++++++++++++++----- README.md | 1 + ios/RNCCameraRoll.mm | 6 +++ src/CameraRoll.ts | 5 +++ 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/FabricExample/js/GetPhotosPerformanceExample.tsx b/FabricExample/js/GetPhotosPerformanceExample.tsx index b829990..fb775e4 100644 --- a/FabricExample/js/GetPhotosPerformanceExample.tsx +++ b/FabricExample/js/GetPhotosPerformanceExample.tsx @@ -1,14 +1,14 @@ +import { CameraRoll } from '@react-native-camera-roll/camera-roll'; import * as React from 'react'; import { - StyleSheet, - View, Button, - Text, - Switch, - TextInput, Keyboard, + StyleSheet, + Switch, + Text, + TextInput, + View, } from 'react-native'; -import {CameraRoll} from '@react-native-camera-roll/camera-roll'; import type { GetPhotosParams, Include, @@ -25,6 +25,7 @@ interface State { * with `this.first()` before using. */ firstStr: string; + includeSharedAlbums: boolean; } const includeValues: Include[] = [ @@ -49,6 +50,7 @@ export default class GetPhotosPerformanceExample extends React.PureComponent< output: null, include: [], firstStr: '1000', + includeSharedAlbums: false, }; first = () => { @@ -60,14 +62,18 @@ export default class GetPhotosPerformanceExample extends React.PureComponent< }; startFetchingPhotos = async () => { - const {include} = this.state; + const {include, includeSharedAlbums} = this.state; const first = this.first(); if (first === null) { return; } this.setState({fetchingPhotos: true}); Keyboard.dismiss(); - const params: GetPhotosParams = {first, include}; + const params: GetPhotosParams = { + first, + include, + includeSharedAlbums, + }; const startTime = Date.now(); const output: PhotoIdentifiersPage = await CameraRoll.getPhotos(params); const endTime = Date.now(); @@ -91,8 +97,14 @@ export default class GetPhotosPerformanceExample extends React.PureComponent< }; render() { - const {fetchingPhotos, timeTakenMillis, output, include, firstStr} = - this.state; + const { + fetchingPhotos, + timeTakenMillis, + output, + include, + firstStr, + includeSharedAlbums, + } = this.state; const first = this.first(); return ( @@ -108,6 +120,15 @@ export default class GetPhotosPerformanceExample extends React.PureComponent< /> ))} + + includeSharedAlbums + + this.setState({includeSharedAlbums: changedTo}) + } + /> + first @@ -130,7 +151,7 @@ export default class GetPhotosPerformanceExample extends React.PureComponent< Time taken: {timeTakenMillis} ms )} - Output + Output : {output?.edges?.length || '0'} elements *const mimeTypes = [RCTConvert NSStringArray:params[@"mimeTypes"]]; NSArray *const include = [RCTConvert NSStringArray:params[@"include"]]; + BOOL __block includeSharedAlbums = [params[@"includeSharedAlbums"] boolValue]; + BOOL __block includeFilename = [include indexOfObject:@"filename"] != NSNotFound; BOOL __block includeFileSize = [include indexOfObject:@"fileSize"] != NSNotFound; BOOL __block includeFileExtension = [include indexOfObject:@"fileExtension"] != NSNotFound; @@ -345,6 +347,10 @@ RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params } assetFetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]]; + if (includeSharedAlbums) { + assetFetchOptions.includeAssetSourceTypes = PHAssetSourceTypeUserLibrary | PHAssetSourceTypeCloudShared; + } + BOOL __block foundAfter = NO; BOOL __block hasNextPage = NO; BOOL __block resolvedPromise = NO; diff --git a/src/CameraRoll.ts b/src/CameraRoll.ts index 5589694..50a773e 100644 --- a/src/CameraRoll.ts +++ b/src/CameraRoll.ts @@ -80,6 +80,11 @@ export type GetPhotosParams = { */ groupName?: string; + /** + * Include assets originating from an iCloud Shared Album. iOS only. + */ + includeSharedAlbums?: boolean; + /** * Specifies filter on asset type */