-
Notifications
You must be signed in to change notification settings - Fork 41
/
index.js
67 lines (58 loc) · 2.09 KB
/
index.js
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
import {
NativeModules,
Platform,
PermissionsAndroid
} from 'react-native';
const RNGalleryManager = NativeModules.RNGalleryManager;
const GalleryManager = {
/**
* Get Assets from the gallery
* @param {object} params Object with params
* @param {string} params.type Type of the asset. Can be - image, video, all
* @param {number} params.limit Number of assets returned
* @param {number} params.startFrom From which index to start
* @param {string} params.albumName If requesting items from album -> set the album name
*/
getAssets(params) {
return RNGalleryManager.getAssets(params);
},
/**
* To Request authorization for access photos
* returns Promise
*/
requestAuthorization(title, message) {
if (Platform.OS === 'ios') {
return RNGalleryManager.requestAuthorization();
} else {
return new Promise(async (resolve, reject) => {
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, {
title: title,
message: message,
});
// On devices before SDK version 23, the permissions are automatically granted if they appear in the manifest,
// so check and request should always be true.
// https://github.com/facebook/react-native-website/blob/master/docs/permissionsandroid.md
const isAuthorized =
Platform.Version >= 23 ? granted === PermissionsAndroid.RESULTS.GRANTED : granted === true;
if (isAuthorized) {
resolve({ isAuthorized: true });
} else {
resolve({ isAuthorized: false })
}
});
}
},
/**
* Get List with album names
*/
getAlbums() {
return RNGalleryManager.getAlbums();
},
/**
* Convert video
*/
convertVideo(params) {
return RNGalleryManager.convertVideo(params);
}
}
module.exports = GalleryManager;