1+ import { ActionEmitEvent } from '@mezon/mobile-components' ;
12import { Colors , size , Text } from '@mezon/mobile-ui' ;
23import { AttachmentEntity , selectAllListAttachmentByChannel } from '@mezon/store-mobile' ;
34import { Snowflake } from '@theinternetfolks/snowflake' ;
45import { ApiMessageAttachment } from 'mezon-js/api.gen' ;
56import React , { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
67import { useTranslation } from 'react-i18next' ;
7- import { Modal , View } from 'react-native' ;
8+ import { DeviceEventEmitter , View } from 'react-native' ;
89import Gallery , { GalleryRef , RenderItemInfo } from 'react-native-awesome-gallery' ;
910import { useSelector } from 'react-redux' ;
1011import { useThrottledCallback } from 'use-debounce' ;
@@ -14,8 +15,6 @@ import { RenderFooterModal } from './RenderFooterModal';
1415import { RenderHeaderModal } from './RenderHeaderModal' ;
1516
1617interface IImageListModalProps {
17- visible ?: boolean ;
18- onClose ?: ( ) => void ;
1918 imageSelected ?: AttachmentEntity ;
2019 channelId : string ;
2120}
@@ -29,14 +28,14 @@ const TIME_TO_HIDE_THUMBNAIL = 5000;
2928const TIME_TO_SHOW_SAVE_IMAGE_SUCCESS = 3000 ;
3029
3130export const ImageListModal = React . memo ( ( props : IImageListModalProps ) => {
32- const { visible , onClose , imageSelected } = props ;
31+ const { imageSelected , channelId } = props ;
3332 const { t } = useTranslation ( 'common' ) ;
3433 const [ currentImage , setCurrentImage ] = useState < AttachmentEntity | null > ( null ) ;
3534 const [ visibleToolbarConfig , setVisibleToolbarConfig ] = useState < IVisibleToolbarConfig > ( { showHeader : true , showFooter : false } ) ;
3635 const [ currentScale , setCurrentScale ] = useState ( 1 ) ;
3736 const [ showSavedImage , setShowSavedImage ] = useState ( false ) ;
3837 const [ isLoadingSaveImage , setIsLoadingSaveImage ] = useState ( false ) ;
39- const attachments = useSelector ( ( state ) => selectAllListAttachmentByChannel ( state , props . channelId ) ) ;
38+ const attachments = useSelector ( ( state ) => selectAllListAttachmentByChannel ( state , channelId ) ) ;
4039 const ref = useRef < GalleryRef > ( null ) ;
4140 const footerTimeoutRef = useRef < NodeJS . Timeout > ( null ) ;
4241 const imageSavedTimeoutRef = useRef < NodeJS . Timeout > ( null ) ;
@@ -63,6 +62,10 @@ export const ImageListModal = React.memo((props: IImageListModalProps) => {
6362 : [ ] ;
6463 } , [ attachments , imageSelected ] ) ;
6564
65+ const onClose = ( ) => {
66+ DeviceEventEmitter . emit ( ActionEmitEvent . ON_TRIGGER_MODAL , { isDismiss : true } ) ;
67+ } ;
68+
6669 const updateToolbarConfig = useCallback (
6770 ( newValue : Partial < IVisibleToolbarConfig > ) => {
6871 setVisibleToolbarConfig ( { ...visibleToolbarConfig , ...newValue } ) ;
@@ -168,39 +171,37 @@ export const ImageListModal = React.memo((props: IImageListModalProps) => {
168171 const setScaleDebounced = useThrottledCallback ( setCurrentScale , 300 ) ;
169172
170173 return (
171- < Modal visible = { visible } >
172- < View style = { { flex : 1 } } >
173- { visibleToolbarConfig . showHeader && (
174- < RenderHeaderModal onClose = { onClose } imageSelected = { currentImage } onImageSaved = { onImageSaved } onLoading = { onLoading } />
175- ) }
176- < Gallery
177- ref = { ref }
178- initialIndex = { initialIndex === - 1 ? 0 : initialIndex }
179- data = { formattedImageList }
180- keyExtractor = { ( item , index ) => `${ item ?. filename } _${ index } ` }
181- onSwipeToClose = { onClose }
182- onIndexChange = { onIndexChange }
183- renderItem = { renderItem }
184- onDoubleTap = { onDoubleTap }
185- onTap = { onTap }
186- onPanStart = { onPanStart }
187- onScaleChange = { setScaleDebounced }
188- />
189- < RenderFooterModal
190- allImageList = { formattedImageList }
191- visible = { visibleToolbarConfig . showFooter }
192- imageSelected = { currentImage }
193- onImageThumbnailChange = { onImageThumbnailChange }
194- />
195- { showSavedImage && (
196- < View style = { { position : 'absolute' , top : '50%' , width : '100%' , alignItems : 'center' } } >
197- < View style = { { backgroundColor : Colors . bgDarkSlate , padding : size . s_10 , borderRadius : size . s_10 } } >
198- < Text style = { { color : Colors . white } } > { t ( 'savedSuccessfully' ) } </ Text >
199- </ View >
174+ < View style = { { flex : 1 } } >
175+ { visibleToolbarConfig . showHeader && (
176+ < RenderHeaderModal onClose = { onClose } imageSelected = { currentImage } onImageSaved = { onImageSaved } onLoading = { onLoading } />
177+ ) }
178+ < Gallery
179+ ref = { ref }
180+ initialIndex = { initialIndex === - 1 ? 0 : initialIndex }
181+ data = { formattedImageList }
182+ keyExtractor = { ( item , index ) => `${ item ?. filename } _${ index } ` }
183+ onSwipeToClose = { onClose }
184+ onIndexChange = { onIndexChange }
185+ renderItem = { renderItem }
186+ onDoubleTap = { onDoubleTap }
187+ onTap = { onTap }
188+ onPanStart = { onPanStart }
189+ onScaleChange = { setScaleDebounced }
190+ />
191+ < RenderFooterModal
192+ allImageList = { formattedImageList }
193+ visible = { visibleToolbarConfig . showFooter }
194+ imageSelected = { currentImage }
195+ onImageThumbnailChange = { onImageThumbnailChange }
196+ />
197+ { showSavedImage && (
198+ < View style = { { position : 'absolute' , top : '50%' , width : '100%' , alignItems : 'center' } } >
199+ < View style = { { backgroundColor : Colors . bgDarkSlate , padding : size . s_10 , borderRadius : size . s_10 } } >
200+ < Text style = { { color : Colors . white } } > { t ( 'savedSuccessfully' ) } </ Text >
200201 </ View >
201- ) }
202- </ View >
202+ </ View >
203+ ) }
203204 < LoadingModal isVisible = { isLoadingSaveImage } />
204- </ Modal >
205+ </ View >
205206 ) ;
206207} ) ;
0 commit comments