mirror of
https://github.com/status-im/react-native-cameraroll.git
synced 2025-01-12 19:04:13 +00:00
Export an object instead of array for asset type
Summary: Exporting an object instead of an array so it can be used as an enum by other files. Reviewed By: sahrens Differential Revision: D5007488 fbshipit-source-id: 8253a424f0dbb51511b889b1da637f366c0f290a
This commit is contained in:
parent
e6adb78de6
commit
331d248f81
134
CameraRoll.js
134
CameraRoll.js
@ -8,41 +8,36 @@
|
||||
*
|
||||
* @providesModule CameraRoll
|
||||
* @flow
|
||||
* @format
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var {PropTypes, checkPropTypes} = require('React');
|
||||
var RCTCameraRollManager = require('NativeModules').CameraRollManager;
|
||||
const {PropTypes, checkPropTypes} = require('React');
|
||||
const RCTCameraRollManager = require('NativeModules').CameraRollManager;
|
||||
|
||||
var createStrictShapeTypeChecker = require('createStrictShapeTypeChecker');
|
||||
var deepFreezeAndThrowOnMutationInDev =
|
||||
require('deepFreezeAndThrowOnMutationInDev');
|
||||
var invariant = require('fbjs/lib/invariant');
|
||||
const createStrictShapeTypeChecker = require('createStrictShapeTypeChecker');
|
||||
const invariant = require('fbjs/lib/invariant');
|
||||
|
||||
var GROUP_TYPES_OPTIONS = [
|
||||
'Album',
|
||||
'All',
|
||||
'Event',
|
||||
'Faces',
|
||||
'Library',
|
||||
'PhotoStream',
|
||||
'SavedPhotos', // default
|
||||
];
|
||||
const GROUP_TYPES_OPTIONS = {
|
||||
Album: 'Album',
|
||||
All: 'All',
|
||||
Event: 'Event',
|
||||
Faces: 'Faces',
|
||||
Library: 'Library',
|
||||
PhotoStream: 'PhotoStream',
|
||||
SavedPhotos: 'SavedPhotos', // default
|
||||
};
|
||||
|
||||
var ASSET_TYPE_OPTIONS = [
|
||||
'All',
|
||||
'Videos',
|
||||
'Photos', // default
|
||||
];
|
||||
|
||||
// Flow treats Object and Array as disjoint types, currently.
|
||||
deepFreezeAndThrowOnMutationInDev((GROUP_TYPES_OPTIONS: any));
|
||||
deepFreezeAndThrowOnMutationInDev((ASSET_TYPE_OPTIONS: any));
|
||||
const ASSET_TYPE_OPTIONS = {
|
||||
All: 'All',
|
||||
Videos: 'Videos',
|
||||
Photos: 'Photos',
|
||||
};
|
||||
|
||||
/**
|
||||
* Shape of the param arg for the `getPhotos` function.
|
||||
*/
|
||||
var getPhotosParamChecker = createStrictShapeTypeChecker({
|
||||
const getPhotosParamChecker = createStrictShapeTypeChecker({
|
||||
/**
|
||||
* The number of photos wanted in reverse order of the photo application
|
||||
* (i.e. most recent first for SavedPhotos).
|
||||
@ -58,7 +53,7 @@ var getPhotosParamChecker = createStrictShapeTypeChecker({
|
||||
/**
|
||||
* Specifies which group types to filter the results to.
|
||||
*/
|
||||
groupTypes: PropTypes.oneOf(GROUP_TYPES_OPTIONS),
|
||||
groupTypes: PropTypes.oneOf(Object.keys(GROUP_TYPES_OPTIONS)),
|
||||
|
||||
/**
|
||||
* Specifies filter on group names, like 'Recent Photos' or custom album
|
||||
@ -69,7 +64,7 @@ var getPhotosParamChecker = createStrictShapeTypeChecker({
|
||||
/**
|
||||
* Specifies filter on asset type
|
||||
*/
|
||||
assetType: PropTypes.oneOf(ASSET_TYPE_OPTIONS),
|
||||
assetType: PropTypes.oneOf(Object.keys(ASSET_TYPE_OPTIONS)),
|
||||
|
||||
/**
|
||||
* Filter by mimetype (e.g. image/jpeg).
|
||||
@ -80,28 +75,30 @@ var getPhotosParamChecker = createStrictShapeTypeChecker({
|
||||
/**
|
||||
* Shape of the return value of the `getPhotos` function.
|
||||
*/
|
||||
var getPhotosReturnChecker = createStrictShapeTypeChecker({
|
||||
const getPhotosReturnChecker = createStrictShapeTypeChecker({
|
||||
// $FlowFixMe(>=0.41.0)
|
||||
edges: PropTypes.arrayOf(createStrictShapeTypeChecker({
|
||||
node: createStrictShapeTypeChecker({
|
||||
type: PropTypes.string.isRequired,
|
||||
group_name: PropTypes.string.isRequired,
|
||||
image: createStrictShapeTypeChecker({
|
||||
uri: PropTypes.string.isRequired,
|
||||
height: PropTypes.number.isRequired,
|
||||
width: PropTypes.number.isRequired,
|
||||
isStored: PropTypes.bool,
|
||||
edges: PropTypes.arrayOf(
|
||||
createStrictShapeTypeChecker({
|
||||
node: createStrictShapeTypeChecker({
|
||||
type: PropTypes.string.isRequired,
|
||||
group_name: PropTypes.string.isRequired,
|
||||
image: createStrictShapeTypeChecker({
|
||||
uri: PropTypes.string.isRequired,
|
||||
height: PropTypes.number.isRequired,
|
||||
width: PropTypes.number.isRequired,
|
||||
isStored: PropTypes.bool,
|
||||
}).isRequired,
|
||||
timestamp: PropTypes.number.isRequired,
|
||||
location: createStrictShapeTypeChecker({
|
||||
latitude: PropTypes.number,
|
||||
longitude: PropTypes.number,
|
||||
altitude: PropTypes.number,
|
||||
heading: PropTypes.number,
|
||||
speed: PropTypes.number,
|
||||
}),
|
||||
}).isRequired,
|
||||
timestamp: PropTypes.number.isRequired,
|
||||
location: createStrictShapeTypeChecker({
|
||||
latitude: PropTypes.number,
|
||||
longitude: PropTypes.number,
|
||||
altitude: PropTypes.number,
|
||||
heading: PropTypes.number,
|
||||
speed: PropTypes.number,
|
||||
}),
|
||||
}).isRequired,
|
||||
})).isRequired,
|
||||
}),
|
||||
).isRequired,
|
||||
page_info: createStrictShapeTypeChecker({
|
||||
has_next_page: PropTypes.bool.isRequired,
|
||||
start_cursor: PropTypes.string,
|
||||
@ -121,12 +118,13 @@ var getPhotosReturnChecker = createStrictShapeTypeChecker({
|
||||
*
|
||||
*/
|
||||
class CameraRoll {
|
||||
|
||||
static GroupTypesOptions: Array<string>;
|
||||
static AssetTypeOptions: Array<string>;
|
||||
static GroupTypesOptions: Object = GROUP_TYPES_OPTIONS;
|
||||
static AssetTypeOptions: Object = ASSET_TYPE_OPTIONS;
|
||||
|
||||
static saveImageWithTag(tag: string): Promise<Object> {
|
||||
console.warn('CameraRoll.saveImageWithTag is deprecated. Use CameraRoll.saveToCameraRoll instead');
|
||||
console.warn(
|
||||
'CameraRoll.saveImageWithTag is deprecated. Use CameraRoll.saveToCameraRoll instead',
|
||||
);
|
||||
return this.saveToCameraRoll(tag, 'photo');
|
||||
}
|
||||
|
||||
@ -144,16 +142,19 @@ class CameraRoll {
|
||||
*
|
||||
* Returns a Promise which will resolve with the new URI.
|
||||
*/
|
||||
static saveToCameraRoll(tag: string, type?: 'photo' | 'video'): Promise<Object> {
|
||||
static saveToCameraRoll(
|
||||
tag: string,
|
||||
type?: 'photo' | 'video',
|
||||
): Promise<Object> {
|
||||
invariant(
|
||||
typeof tag === 'string',
|
||||
'CameraRoll.saveToCameraRoll must be a valid string.'
|
||||
'CameraRoll.saveToCameraRoll must be a valid string.',
|
||||
);
|
||||
|
||||
invariant(
|
||||
type === 'photo' || type === 'video' || type === undefined,
|
||||
// $FlowFixMe(>=0.28.0)
|
||||
`The second argument to saveToCameraRoll must be 'photo' or 'video'. You passed ${type}`
|
||||
`The second argument to saveToCameraRoll must be 'photo' or 'video'. You passed ${type}`,
|
||||
);
|
||||
|
||||
let mediaType = 'photo';
|
||||
@ -214,32 +215,39 @@ class CameraRoll {
|
||||
*/
|
||||
static getPhotos(params) {
|
||||
if (__DEV__) {
|
||||
checkPropTypes({params: getPhotosParamChecker}, {params}, 'params', 'CameraRoll.getPhotos');
|
||||
checkPropTypes(
|
||||
{params: getPhotosParamChecker},
|
||||
{params},
|
||||
'params',
|
||||
'CameraRoll.getPhotos',
|
||||
);
|
||||
}
|
||||
if (arguments.length > 1) {
|
||||
console.warn('CameraRoll.getPhotos(tag, success, error) is deprecated. Use the returned Promise instead');
|
||||
console.warn(
|
||||
'CameraRoll.getPhotos(tag, success, error) is deprecated. Use the returned Promise instead',
|
||||
);
|
||||
let successCallback = arguments[1];
|
||||
if (__DEV__) {
|
||||
const callback = arguments[1];
|
||||
successCallback = (response) => {
|
||||
successCallback = response => {
|
||||
checkPropTypes(
|
||||
{response: getPhotosReturnChecker},
|
||||
{response},
|
||||
'response',
|
||||
'CameraRoll.getPhotos callback'
|
||||
'CameraRoll.getPhotos callback',
|
||||
);
|
||||
callback(response);
|
||||
};
|
||||
}
|
||||
const errorCallback = arguments[2] || ( () => {} );
|
||||
RCTCameraRollManager.getPhotos(params).then(successCallback, errorCallback);
|
||||
const errorCallback = arguments[2] || (() => {});
|
||||
RCTCameraRollManager.getPhotos(params).then(
|
||||
successCallback,
|
||||
errorCallback,
|
||||
);
|
||||
}
|
||||
// TODO: Add the __DEV__ check back in to verify the Promise result
|
||||
return RCTCameraRollManager.getPhotos(params);
|
||||
}
|
||||
}
|
||||
|
||||
CameraRoll.GroupTypesOptions = GROUP_TYPES_OPTIONS;
|
||||
CameraRoll.AssetTypeOptions = ASSET_TYPE_OPTIONS;
|
||||
|
||||
module.exports = CameraRoll;
|
||||
|
Loading…
x
Reference in New Issue
Block a user