forked from zzetao/react-native-extract-color
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (26 loc) · 815 Bytes
/
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
import { NativeModules, Platform } from 'react-native';
const { RNExtractColor } = NativeModules;
export default {
extract (imagePath) {
if (Platform.OS === 'android') {
return Promise.reject('[react-native-extract-color] Does not support android!');
}
if (!imagePath || typeof imagePath !== 'string') {
return Promise.reject('[react-native-extract-color] imagePath is not a valid url!');
}
if (imagePath.indexOf('http') !== -1) {
return Promise.reject('[react-native-extract-color] imagePath is not a valid local image path!')
}
return new Promise((resolve, reject) => {
RNExtractColor.extract(
imagePath,
result => {
resolve(result);
},
error => {
reject(error);
}
)
})
}
}