-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.android.js
41 lines (38 loc) · 1.16 KB
/
index.android.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
import React from 'react-native';
const CameraRollAndroid = React.NativeModules.CameraRollAndroid;
const ANDROID_FILE_PREFIX = 'file:';
function formatToIosCameraRollFormat(imageDataList) {
return {
edges: imageDataList.map((imageData) => {
return {
node: {
image: {
uri: ANDROID_FILE_PREFIX + imageData.uri,
width: imageData.width,
height: imageData.height,
orientation: imageData.orientation,
},
timestamp: parseInt(imageData.timestamp)
},
};
}),
};
}
export default {
getPhotos: (fetchParams, onSuccess) => {
if(fetchParams.after) {
fetchParams.after = fetchParams.after.replace(ANDROID_FILE_PREFIX, '');
}
if(onSuccess && typeof onSuccess === 'function') {
CameraRollAndroid.getCameraImages(fetchParams, (imageDataList) => {
onSuccess(formatToIosCameraRollFormat(imageDataList));
});
} else {
return new Promise((resolve, reject) => {
CameraRollAndroid.getCameraImages(fetchParams, (imageDataList) => {
resolve(formatToIosCameraRollFormat(imageDataList));
});
});
}
},
};