-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove-image
More file actions
147 lines (112 loc) · 4.24 KB
/
move-image
File metadata and controls
147 lines (112 loc) · 4.24 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import React, { useCallback, useEffect, useState } from 'react';
import { View, FlatList, StyleSheet, TouchableOpacity, Text } from 'react-native';
import { moderateScale } from 'react-native-size-matters';
import { MD3LightTheme, TouchableRipple } from '@jmstechnologiesinc/react-native-paper';
import DraggableFlatList, { ScaleDecorator, NestableScrollContainer } from 'react-native-draggable-flatlist';
import ScreenWrapperSection from '../ScreenWrapper/ScreenWrapperSection';
import FastImage from 'react-native-fast-image';
import { IconButton } from '@jmstechnologiesinc/react-native-paper';
import { imagekitUrl } from '@jmstechnologiesinc/react-native-components/lib/utils';
import { Photos} from './data'
const PhotoGallery = ({ photos, showNav = true, onLongPress, inputDispatchPayloadRef }) => {
const [data, setData] = useState(photos);
const [selectedIndex, setSelectedIndex] = useState(0);
useEffect(() => {
setData(photos)
}, [photos]);
const renderItem =({ item, drag, isActive, getIndex }) => {
const isSelected = getIndex() === selectedIndex;
// console.log(JSON.stringify(item, null, 2))
const photo = item.uri ? item.uri : imagekitUrl(item)
return (
<ScaleDecorator>
<TouchableOpacity
activeOpacity={1}
onPress={() => setSelectedIndex(getIndex())}
onLongPress={drag}
disabled={isActive}
style={[
styles.rowItem,
{ opacity: isActive ? 0.5 : 1 },
isActive ? styles.activeItem : null
]}
>
<FastImage source={{ uri: photo }} style={styles.photo} resizeMode={FastImage.resizeMode.stretch} />
{isSelected && (
<IconButton
icon="delete"
mode="contained"
size={moderateScale(24)}
onPress={() => { /* Acciones para el ícono seleccionado */ }}
style={{
position: 'absolute',
right: 0,
top: 0,
}}
/>
)}
</TouchableOpacity>
</ScaleDecorator>
);
}
const photo = data?.map((photo) => {
if (photo.uri) {
return photo.uri;
} else {
return imagekitUrl(photo);
}
})
const onDragEnd = ({ data: newData }) => {
console.log(newData)
setData(newData);
inputDispatchPayloadRef('photos', newData)
};
return (
<>
{
data?.length > 0 && (<FastImage source={{ uri: photo[selectedIndex] }} style={styles.mainImage} />)
}
{showNav && data?.length > 0 && (<ScreenWrapperSection>
<NestableScrollContainer>
<DraggableFlatList
horizontal
data={data}
onDragEnd={onDragEnd}
keyExtractor={(item) => item.fileName ? item.fileName : item
}
// onDragEnd={({ data }) => setData(data)}
renderItem={renderItem}
/>
</NestableScrollContainer>
</ScreenWrapperSection>)}
</>
);
};
const styles = StyleSheet.create({
mainImage: {
height: moderateScale(195),
},
photo: {
height: moderateScale(90),
width: moderateScale(90),
},
rowItem: {
height: moderateScale(100),
width:moderateScale(100),
alignItems: 'center',
justifyContent: 'center',
},
text: {
fontSize: 24,
fontWeight: 'bold',
textAlign: 'center',
},
activeItem: {
backgroundColor: '#f0f0f0',
elevation: 5,
shadowOpacity: 0.3,
shadowRadius: 4,
shadowOffset: { height: 2, width: 2 },
},
});
export default PhotoGallery;