This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathCameraRoll.js
More file actions
105 lines (92 loc) · 2.66 KB
/
CameraRoll.js
File metadata and controls
105 lines (92 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import invariant from 'invariant';
import PropTypes from 'prop-types';
import CameraRollManager from '../NativeModules/CameraRollManager';
const GROUP_TYPES_OPTIONS = [
'Album',
'All',
'Event',
'Faces',
'Library',
'PhotoStream',
'SavedPhotos', // default
];
const ASSET_TYPE_OPTIONS = [
'All',
'Videos',
'Photos', // default
];
/**
* Shape of the param arg for the `getPhotos` function.
*/
const getPhotosParamChecker = PropTypes.shape({
/**
* The number of photos wanted in reverse order of the photo application
* (i.e. most recent first for SavedPhotos).
*/
first: PropTypes.number.isRequired,
/**
* A cursor that matches `page_info { end_cursor }` returned from a previous
* call to `getPhotos`
*/
after: PropTypes.string,
/**
* Specifies which group types to filter the results to.
*/
groupTypes: PropTypes.oneOf(GROUP_TYPES_OPTIONS),
/**
* Specifies filter on group names, like 'Recent Photos' or custom album
* titles.
*/
groupName: PropTypes.string,
/**
* Specifies filter on asset type
*/
assetType: PropTypes.oneOf(ASSET_TYPE_OPTIONS),
/**
* Filter by mimetype (e.g. image/jpeg).
*/
mimeTypes: PropTypes.arrayOf(PropTypes.string),
});
class CameraRoll {
/**
* Saves the image to the camera roll / gallery.
*
* On Android, the tag is a local URI, such as `"file:///sdcard/img.png"`.
*
* On iOS, the tag can be one of the following:
*
* - local URI
* - assets-library tag
* - a tag not matching any of the above, which means the image data will
* be stored in memory (and consume memory as long as the process is alive)
*
* Returns a Promise which when resolved will be passed the new URI.
*/
static saveImageWithTag(tag) {
invariant(
typeof tag === 'string',
'CameraRoll.saveImageWithTag tag must be a valid string.'
);
// TODO(lmr):
return CameraRollManager.saveImageWithTag(tag);
}
/**
* Returns a Promise with photo identifier objects from the local camera
* roll of the device matching shape defined by `getPhotosReturnChecker`.
*
* @param {object} params See `getPhotosParamChecker`.
*
* Returns a Promise which when resolved will be of shape `getPhotosReturnChecker`.
*/
static getPhotos(params) {
if (process.env.NODE_ENV === 'development') {
getPhotosParamChecker({ params }, 'params', 'CameraRoll.getPhotos');
}
// TODO(lmr):
// TODO: Add the __DEV__ check back in to verify the Promise result
return CameraRollManager.getPhotos(params);
}
}
CameraRoll.GroupTypesOptions = GROUP_TYPES_OPTIONS;
CameraRoll.AssetTypeOptions = ASSET_TYPE_OPTIONS;
module.exports = CameraRoll;