Files
notesnook/apps/mobile/src/components/ImagePreview/index.js

87 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-01-22 12:57:05 +05:00
import React, { useEffect, useState } from 'react';
import { View } from 'react-native';
2021-04-24 12:46:38 +05:00
import ImageViewer from 'react-native-image-zoom-viewer';
import RNFetchBlob from 'rn-fetch-blob';
import Storage from '../../utils/storage';
2022-01-22 12:57:05 +05:00
import { ActionIcon } from '../ActionIcon';
2021-04-24 12:46:38 +05:00
import BaseDialog from '../Dialog/base-dialog';
2022-01-22 12:57:05 +05:00
const { eSubscribeEvent, eUnSubscribeEvent } = require('../../services/EventManager');
2021-04-24 12:46:38 +05:00
const ImagePreview = () => {
const [visible, setVisible] = useState(false);
const [image, setImage] = useState('');
useEffect(() => {
eSubscribeEvent('ImagePreview', open);
return () => {
eUnSubscribeEvent('ImagePreview', open);
};
}, []);
const open = image => {
setImage(image);
setVisible(true);
};
const close = () => {
setImage(null);
setVisible(false);
};
return (
visible && (
<BaseDialog animation="slide" visible={true} onRequestClose={close}>
<View
style={{
width: '100%',
height: '100%',
backgroundColor: 'black'
2022-01-22 12:57:05 +05:00
}}
>
2021-04-24 12:46:38 +05:00
<ImageViewer
enableImageZoom={true}
2021-04-24 12:46:38 +05:00
renderIndicator={() => <></>}
enableSwipeDown
useNativeDriver
onSwipeDown={close}
saveToLocalByLongPress={false}
2021-04-24 12:46:38 +05:00
renderHeader={() => (
<View
style={{
flexDirection: 'row',
width: '100%',
justifyContent: 'flex-end',
alignItems: 'center',
height: 80,
marginTop: 0,
2021-04-24 12:46:38 +05:00
paddingHorizontal: 12,
position: 'absolute',
zIndex: 999,
backgroundColor: 'rgba(0,0,0,0.3)',
paddingTop: 30
2022-01-22 12:57:05 +05:00
}}
>
2021-04-24 12:46:38 +05:00
<ActionIcon
name="close"
color="white"
onPress={() => {
close();
}}
/>
</View>
)}
imageUrls={[
{
url: image
}
2021-04-24 12:46:38 +05:00
]}
/>
</View>
</BaseDialog>
)
);
};
export default ImagePreview;