-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageCard.js
71 lines (66 loc) · 1.88 KB
/
ImageCard.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
68
69
70
71
import React from 'react';
import {useEffect, useState} from 'react';
import {Image, View} from 'react-native';
import ImageColors from 'react-native-image-colors';
import LinearGradient from 'react-native-linear-gradient';
const ImageCard = props => {
const {url} = props.item;
useEffect(() => {
getColorsofImage();
}, []);
const [primaryColor, SetPrimaryColor] = useState('#228B22');
const [secondaryColor, SetSecondaryColor] = useState('#228B22');
const [backgroundColor, SetBackgroundColor] = useState('#228B22');
const getColorsofImage = async () => {
const result = await ImageColors.getColors(url, {
fallback: '#A196DE',
// cache: true,
key: 'unique_key',
});
switch (result.platform) {
case 'android':
// android result properties
SetBackgroundColor(result?.average);
SetPrimaryColor(result?.vibrant);
SetSecondaryColor(result?.lightVibrant);
console.log('result', result);
break;
case 'web':
// web result properties
const lightVibrantColor = result.lightVibrant;
console.log('lightVibrantColor', lightVibrantColor);
break;
case 'ios':
// iOS result properties
SetBackgroundColor(result?.background);
SetPrimaryColor(result?.primary);
SetSecondaryColor(result?.secondary);
break;
default:
throw new Error('Unexpected platform key');
}
};
return (
<LinearGradient
colors={[primaryColor, backgroundColor, secondaryColor]}
useAngle={true}
start={{x: 1, y: 0}}
end={{x: 0, y: 1}}
style={{
margin: 15,
height: 100,
width: 100,
justifyContent: 'center',
alignItems: 'center',
}}>
<Image
resizeMode="contain"
style={{height: '50%', width: '50%'}}
source={{
uri: url,
}}
/>
</LinearGradient>
);
};
export default ImageCard;