11/* eslint-disable react-native/no-inline-styles */
22import React , { useState } from 'react' ;
3- import { Image , Text } from 'react-native' ;
3+ import {
4+ Image ,
5+ LayoutAnimation ,
6+ Platform ,
7+ Text ,
8+ UIManager ,
9+ } from 'react-native' ;
410import { TouchableOpacity } from 'react-native' ;
511import { ScrollView } from 'react-native' ;
612import { View } from 'react-native' ;
@@ -12,6 +18,22 @@ import { StyleSheet } from 'react-native';
1218import ImageGrid from '@baronha/react-native-image-grid' ;
1319import { openPicker } from '@baronha/react-native-multiple-image-picker' ;
1420
21+ UIManager . setLayoutAnimationEnabledExperimental &&
22+ UIManager . setLayoutAnimationEnabledExperimental ( true ) ;
23+
24+ const layoutEffect = ( ) => {
25+ LayoutAnimation . configureNext ( {
26+ duration : 300 ,
27+ create : {
28+ type : LayoutAnimation . Types . easeInEaseOut ,
29+ property : LayoutAnimation . Properties . opacity ,
30+ } ,
31+ update : {
32+ type : LayoutAnimation . Types . easeInEaseOut ,
33+ } ,
34+ } ) ;
35+ } ;
36+
1537const { width } = Dimensions . get ( 'window' ) ;
1638
1739export default function App ( ) {
@@ -23,7 +45,7 @@ export default function App() {
2345
2446 const onPicker = async ( ) => {
2547 try {
26- const singleSelectedMode = true ;
48+ const singleSelectedMode = false ;
2749
2850 const response = await openPicker ( {
2951 selectedAssets : images ,
@@ -42,25 +64,34 @@ export default function App() {
4264 response . height = crop . height ;
4365 }
4466
45- setImages ( response ) ;
67+ setImages ( Array . isArray ( response ) ? response : [ response ] ) ;
68+ layoutEffect ( ) ;
4669 } catch ( e ) { }
4770 } ;
4871
72+ const onRemovePhoto = ( _ , index ) => {
73+ const data = [ ...images ] . filter ( ( _ , idx ) => idx !== index ) ;
74+ setImages ( data ) ;
75+ layoutEffect ( ) ;
76+ } ;
77+
4978 return (
5079 < View style = { style . container } >
5180 < ScrollView contentContainerStyle = { { paddingTop : 132 } } >
5281 < View style = { { alignItems : 'center' } } >
5382 < ImageGrid
54- dataImage = { Array . isArray ( images ) ? images : [ images ] }
83+ dataImage = { images }
5584 onPressImage = { onPressImage }
5685 // spaceSize={10}
5786 containerStyle = { { marginTop : 3 } }
5887 width = { Dimensions . get ( 'window' ) . width - 6 }
5988 sourceKey = { 'path' }
6089 videoKey = { 'type' }
61- prefixPath = { ' file://'}
90+ prefixPath = { Platform . OS === 'ios' ? ' file://' : null }
6291 conditionCheckVideo = { 'video' }
6392 videoURLKey = { 'thumbnail' }
93+ showDelete
94+ onDeleteImage = { onRemovePhoto }
6495 />
6596 < TouchableOpacity style = { style . buttonOpen } onPress = { onPicker } >
6697 < Text style = { style . textOpen } > Open Picker</ Text >
0 commit comments