|
1 | 1 | /* eslint-disable react-native/no-inline-styles */ |
2 | 2 | import React, { useState } from 'react'; |
3 | | -import { Dimensions, Image, SafeAreaView, FlatList } from 'react-native'; |
4 | | -import { StyleSheet, View, Text, TouchableOpacity } from 'react-native'; |
5 | | -import MultipleImagePicker from '@baronha/react-native-multiple-image-picker'; |
| 3 | +import { Text } from 'react-native'; |
| 4 | +import { TouchableOpacity } from 'react-native'; |
| 5 | +import { ScrollView } from 'react-native'; |
| 6 | +import { View } from 'react-native'; |
| 7 | +import { Dimensions } from 'react-native'; |
| 8 | +import { StatusBar } from 'react-native'; |
| 9 | +import { SafeAreaView } from 'react-native'; |
| 10 | + |
| 11 | +import { StyleSheet } from 'react-native'; |
| 12 | +import ImageGrid from '@baronha/react-native-image-grid'; |
| 13 | +import ImagePicker from '@baronha/react-native-multiple-image-picker'; |
| 14 | + |
| 15 | +const { width } = Dimensions.get('window'); |
6 | 16 |
|
7 | 17 | export default function App() { |
8 | 18 | const [images, setImages] = useState([]); |
| 19 | + const onPressImage = (item, index) => { |
| 20 | + console.log(item, index); |
| 21 | + }; |
9 | 22 |
|
10 | 23 | const openPicker = async () => { |
11 | 24 | try { |
12 | | - const response = await MultipleImagePicker.openPicker({ |
| 25 | + const response = await ImagePicker.openPicker({ |
13 | 26 | selectedAssets: images, |
14 | 27 | isExportThumbnail: true, |
15 | 28 | maxVideo: 1, |
16 | | - usedCameraButton: false, |
17 | | - isCrop: true, |
18 | | - isCropCircle: true, |
19 | 29 | }); |
20 | | - console.log('response: ', response); |
| 30 | + console.log(response); |
21 | 31 | setImages(response); |
22 | | - } catch (e) { |
23 | | - console.log(e.code, e.message); |
24 | | - } |
25 | | - }; |
26 | | - |
27 | | - const onDelete = (value) => { |
28 | | - const data = images.filter( |
29 | | - (item) => |
30 | | - item?.localIdentifier && |
31 | | - item?.localIdentifier !== value?.localIdentifier |
32 | | - ); |
33 | | - setImages(data); |
34 | | - }; |
35 | | - |
36 | | - const renderItem = ({ item, index }) => { |
37 | | - return ( |
38 | | - <View> |
39 | | - <Image |
40 | | - width={IMAGE_WIDTH} |
41 | | - source={{ |
42 | | - uri: |
43 | | - item?.type === 'video' |
44 | | - ? item?.thumbnail ?? '' |
45 | | - : 'file://' + (item?.crop?.cropPath ?? item.path), |
46 | | - }} |
47 | | - style={style.media} |
48 | | - /> |
49 | | - <TouchableOpacity |
50 | | - onPress={() => onDelete(item)} |
51 | | - activeOpacity={0.9} |
52 | | - style={style.buttonDelete} |
53 | | - > |
54 | | - <Text style={style.titleDelete}>Xoá</Text> |
55 | | - </TouchableOpacity> |
56 | | - </View> |
57 | | - ); |
| 32 | + } catch (e) {} |
58 | 33 | }; |
59 | 34 |
|
60 | 35 | return ( |
61 | | - <SafeAreaView style={style.container}> |
62 | | - <FlatList |
63 | | - style={[ |
64 | | - style.container, |
65 | | - { |
66 | | - paddingTop: 6, |
67 | | - }, |
68 | | - ]} |
69 | | - data={images} |
70 | | - keyExtractor={(item, index) => (item?.filename ?? item?.path) + index} |
71 | | - renderItem={renderItem} |
72 | | - numColumns={3} |
73 | | - /> |
74 | | - <View style={style.bottom}> |
75 | | - <TouchableOpacity style={style.openPicker} onPress={openPicker}> |
76 | | - <Text style={style.openText}>open</Text> |
77 | | - </TouchableOpacity> |
| 36 | + <View style={style.container}> |
| 37 | + <ScrollView contentContainerStyle={{ paddingTop: 132 }}> |
| 38 | + <View style={{ alignItems: 'center' }}> |
| 39 | + <ImageGrid |
| 40 | + dataImage={images} |
| 41 | + onPressImage={onPressImage} |
| 42 | + // spaceSize={10} |
| 43 | + containerStyle={{ marginTop: 3 }} |
| 44 | + width={Dimensions.get('window').width - 6} |
| 45 | + sourceKey={'path'} |
| 46 | + videoKey={'type'} |
| 47 | + conditionCheckVideo={'video'} |
| 48 | + videoURLKey={'thumbnail'} |
| 49 | + /> |
| 50 | + <TouchableOpacity style={style.buttonOpen} onPress={openPicker}> |
| 51 | + <Text style={style.textOpen}>Open Gallery</Text> |
| 52 | + </TouchableOpacity> |
| 53 | + </View> |
| 54 | + </ScrollView> |
| 55 | + <View style={style.header}> |
| 56 | + <StatusBar barStyle={'light-content'} backgroundColor={'#000'} /> |
| 57 | + <SafeAreaView /> |
| 58 | + <Text style={style.title}>PICKER</Text> |
78 | 59 | </View> |
79 | | - </SafeAreaView> |
| 60 | + </View> |
80 | 61 | ); |
81 | 62 | } |
82 | 63 |
|
83 | | -const { width } = Dimensions.get('window'); |
84 | | - |
85 | | -const IMAGE_WIDTH = (width - 24) / 3; |
86 | | - |
87 | 64 | const style = StyleSheet.create({ |
88 | 65 | container: { |
| 66 | + backgroundColor: '#000', |
89 | 67 | flex: 1, |
90 | 68 | }, |
91 | | - imageView: { |
92 | | - flex: 1, |
93 | | - flexDirection: 'row', |
94 | | - flexWrap: 'wrap', |
| 69 | + title: { |
| 70 | + fontWeight: '900', |
| 71 | + fontSize: 24, |
95 | 72 | paddingVertical: 24, |
| 73 | + fontFamily: 'Avenir', |
| 74 | + color: '#cdac81', |
| 75 | + textAlign: 'center', |
96 | 76 | }, |
97 | | - media: { |
98 | | - marginLeft: 6, |
99 | | - width: IMAGE_WIDTH, |
100 | | - height: IMAGE_WIDTH, |
101 | | - marginBottom: 6, |
102 | | - backgroundColor: 'rgba(0,0,0,0.2)', |
103 | | - }, |
104 | | - bottom: { |
105 | | - padding: 24, |
| 77 | + buttonOpen: { |
| 78 | + margin: 24, |
| 79 | + backgroundColor: '#fff', |
| 80 | + padding: 12, |
| 81 | + alignItems: 'center', |
| 82 | + width: width - 48, |
106 | 83 | }, |
107 | | - openText: { |
| 84 | + textOpen: { |
108 | 85 | fontWeight: 'bold', |
109 | | - fontSize: 16, |
110 | | - color: '#fff', |
111 | | - paddingVertical: 12, |
112 | 86 | }, |
113 | | - openPicker: { |
114 | | - justifyContent: 'center', |
115 | | - alignItems: 'center', |
116 | | - backgroundColor: '#000', |
117 | | - }, |
118 | | - buttonDelete: { |
119 | | - paddingHorizontal: 8, |
120 | | - paddingVertical: 4, |
| 87 | + header: { |
121 | 88 | position: 'absolute', |
122 | | - top: 6, |
123 | | - right: 6, |
124 | | - backgroundColor: '#ffffff92', |
125 | | - borderRadius: 4, |
126 | | - }, |
127 | | - titleDelete: { |
128 | | - fontWeight: 'bold', |
129 | | - fontSize: 12, |
130 | | - color: '#000', |
| 89 | + top: 0, |
| 90 | + left: 0, |
| 91 | + right: 0, |
| 92 | + backgroundColor: 'rgba(0,0,0,0.9)', |
131 | 93 | }, |
132 | 94 | }); |
0 commit comments