mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-17 04:07:51 +01:00
83 lines
2.0 KiB
JavaScript
83 lines
2.0 KiB
JavaScript
|
|
import React, { useEffect, useState } from 'react';
|
||
|
|
import { View } from 'react-native';
|
||
|
|
import ImageViewer from 'react-native-image-zoom-viewer';
|
||
|
|
import { ActionIcon } from '../ActionIcon';
|
||
|
|
import BaseDialog from '../Dialog/base-dialog';
|
||
|
|
const {
|
||
|
|
eSubscribeEvent,
|
||
|
|
eUnSubscribeEvent,
|
||
|
|
} = require('../../services/EventManager');
|
||
|
|
|
||
|
|
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',
|
||
|
|
}}>
|
||
|
|
<ImageViewer
|
||
|
|
enableImageZoom={false}
|
||
|
|
renderIndicator={() => <></>}
|
||
|
|
enableSwipeDown
|
||
|
|
useNativeDriver
|
||
|
|
onSwipeDown={close}
|
||
|
|
renderHeader={() => (
|
||
|
|
<View
|
||
|
|
style={{
|
||
|
|
flexDirection: 'row',
|
||
|
|
width: '100%',
|
||
|
|
justifyContent: 'flex-end',
|
||
|
|
alignItems: 'center',
|
||
|
|
height: 50,
|
||
|
|
marginTop: 30,
|
||
|
|
paddingHorizontal: 12,
|
||
|
|
position: 'absolute',
|
||
|
|
zIndex: 999,
|
||
|
|
}}>
|
||
|
|
<ActionIcon
|
||
|
|
name="close"
|
||
|
|
color="white"
|
||
|
|
onPress={() => {
|
||
|
|
close();
|
||
|
|
}}
|
||
|
|
/>
|
||
|
|
</View>
|
||
|
|
)}
|
||
|
|
imageUrls={[
|
||
|
|
{
|
||
|
|
url: image,
|
||
|
|
},
|
||
|
|
]}
|
||
|
|
/>
|
||
|
|
</View>
|
||
|
|
</BaseDialog>
|
||
|
|
)
|
||
|
|
);
|
||
|
|
};
|
||
|
|
|
||
|
|
export default ImagePreview;
|