mirror of
https://github.com/status-im/react-native-camera-roll.git
synced 2026-08-27 19:31:12 +00:00
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
This commit is contained in:
@@ -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<
|
||||
/>
|
||||
</View>
|
||||
))}
|
||||
<View key="includeSharedAlbums" style={styles.inputRow}>
|
||||
<Text>includeSharedAlbums</Text>
|
||||
<Switch
|
||||
value={includeSharedAlbums}
|
||||
onValueChange={(changedTo: boolean) =>
|
||||
this.setState({includeSharedAlbums: changedTo})
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.inputRow}>
|
||||
<Text>
|
||||
first
|
||||
@@ -130,7 +151,7 @@ export default class GetPhotosPerformanceExample extends React.PureComponent<
|
||||
<Text>Time taken: {timeTakenMillis} ms</Text>
|
||||
)}
|
||||
<View>
|
||||
<Text>Output</Text>
|
||||
<Text>Output : {output?.edges?.length || '0'} elements</Text>
|
||||
</View>
|
||||
<TextInput
|
||||
value={JSON.stringify(output, null, 2)}
|
||||
|
||||
@@ -235,6 +235,7 @@ Returns a Promise with photo identifier objects from the local camera roll of th
|
||||
* `PhotoStream`
|
||||
* `SavedPhotos`
|
||||
* `groupName` : {string} : Specifies filter on group names, like 'Recent Photos' or custom album titles.
|
||||
* `includeSharedAlbums` : {boolean} : Include assets originating from an iCloud Shared Album. iOS only.
|
||||
* `assetType` : {string} : Specifies filter on asset type. Valid values are:
|
||||
* `All`
|
||||
* `Videos`
|
||||
|
||||
@@ -315,6 +315,8 @@ RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params
|
||||
NSArray<NSString *> *const mimeTypes = [RCTConvert NSStringArray:params[@"mimeTypes"]];
|
||||
NSArray<NSString *> *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;
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user