Files
react-native-camera-roll/typings/CameraRoll.d.ts
T
Bartol KaruzaandHarry Yu 4da8310892 feat: Added include parameter to getPhotos to let users tradeoff performance by omitting metadata (#178) (#200)
BREAKING CHANGE: meta data is no longer added as default. This applies to `fileName`, `fileSize` and `location`. If you need this metadata use the new `include` parameter. Adding this metadata will slow down the `getPhotos` function, so consider only retrieving this meta data for smaller sets of images as needed, instead of for all images.

* Created getPhotosFast function, fixed inconsistent getPhotos toDate logic

* Fixed wrong param name, added better typechecking

* Added example, renamed allowEmptyFilenames to skipGettingFilenames

* Removed `after` from getPhotosFast docs

* Redid implementation based on a new `include` param

* Updated API to use include parameter

* Fixed flow checking by converting index.ts to Typescript

* Unformatted README.md

* Unformatted README.md

* Unformatted README.md

* Added .prettierignore and ignored README.md for now

* Made example/index.js not checked by Flow

* Updated README.md to include notes in the outputs too

* Made inclusion of fields consistent, addressed other feedback

* Renamed GetPhotosFastParams back to GetPhotosParams

* Updated documentation to reflect nullable types

* Updated typings and documentation for fromTime, toTime

* Updated to fix `hasNextPage` being incorrectly false in some cases

Co-authored-by: Harry Yu <hy.harry.yu@gmail.com>
2020-06-16 13:20:51 +03:00

174 lines
4.4 KiB
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
declare namespace CameraRoll {
type GroupType =
| 'Album'
| 'All'
| 'Event'
| 'Faces'
| 'Library'
| 'PhotoStream'
| 'SavedPhotos';
type AssetType = 'All' | 'Videos' | 'Photos';
type Include =
/** Ensures the filename is included. Has a large performance hit on iOS */
| 'filename'
/** Ensures the fileSize is included. Has a large performance hit on iOS */
| 'fileSize'
/** Ensures the location is included. Has a medium performance hit on Android */
| 'location';
/**
* Shape of the param arg for the `getPhotosFast` function.
*/
interface GetPhotosParams {
/**
* The number of photos wanted in reverse order of the photo application
* (i.e. most recent first).
*/
first: number;
/**
* A cursor that matches `page_info { end_cursor }` returned from a previous
* call to `getPhotos`. Note that using this will reduce performance
* slightly on iOS. An alternative is just using the `fromTime` and `toTime`
* filters, which have no such impact.
*/
after?: string;
/**
* Specifies which group types to filter the results to.
*/
groupTypes?: GroupType;
/**
* Specifies filter on group names, like 'Recent Photos' or custom album
* titles.
*/
groupName?: string;
/**
* Specifies filter on asset type
*/
assetType?: AssetType;
/**
* Filter by creation time with a timestamp in milliseconds. This time is
* exclusive, so we'll select all photos with `timestamp > fromTime`.
*/
fromTime?: number;
/**
* Filter by creation time with a timestamp in milliseconds. This time is
* inclusive, so we'll select all photos with `timestamp <= toTime`.
*/
toTime?: number;
/**
* Filter by mimetype (e.g. image/jpeg). Note that using this will reduce
* performance slightly on iOS.
*/
mimeTypes?: Array<string>;
/**
* Specific fields in the output that we want to include, even though they
* might have some performance impact.
*/
include?: Include[];
}
interface PhotoIdentifier {
node: {
type: string;
group_name: string;
image: {
/** Only set if the `include` parameter contains `filename`. */
filename: string | null;
uri: string;
height: number;
width: number;
/** Only set if the `include` parameter contains `fileSize`. */
fileSize: number | null;
isStored?: boolean;
playableDuration: number;
};
/** Timestamp in seconds. */
timestamp: number;
/** Only set if the `include` parameter contains `location`. */
location: {
latitude?: number;
longitude?: number;
altitude?: number;
heading?: number;
speed?: number;
} | null;
};
}
interface PhotoIdentifiersPage {
edges: Array<PhotoIdentifier>;
page_info: {
has_next_page: boolean;
start_cursor?: string;
end_cursor?: string;
};
}
interface GetAlbumsParams {
assetType?: AssetType;
}
interface Album {
title: string;
count: number;
}
type SaveToCameraRollOptions = {
type?: 'photo' | 'video' | 'auto';
album?: string;
};
/**
* `CameraRoll.saveImageWithTag()` is deprecated. Use `CameraRoll.saveToCameraRoll()` instead.
*/
function saveImageWithTag(tag: string): Promise<string>;
/**
* Delete a photo from the camera roll or media library. photoUris is an array of photo uri's.
*/
function deletePhotos(photoUris: Array<string>): Promise<boolean>;
/**
* Saves the photo or video to the camera roll or photo library.
*/
function saveToCameraRoll(
tag: string,
type?: 'photo' | 'video',
): Promise<string>;
/**
* Saves the photo or video to the camera roll or photo library.
*/
function save(
tag: string,
options?: SaveToCameraRollOptions,
): Promise<string>;
/**
* Returns a Promise with photo identifier objects from the local camera
* roll of the device matching shape defined by `getPhotosReturnChecker`.
*/
function getPhotos(params: GetPhotosParams): Promise<PhotoIdentifiersPage>;
function getAlbums(params: GetAlbumsParams): Promise<Album[]>;
}
export = CameraRoll;