2020-06-26 20:22:56 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { ScrollView, StyleSheet } from 'react-native';
|
|
|
|
|
|
|
|
import { ImageComponent } from './ImageComponent';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2020-06-26 20:22:56 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
scrollContent: {
|
|
|
|
width: '100%',
|
|
|
|
height: '100%'
|
|
|
|
},
|
|
|
|
image: {
|
|
|
|
flex: 1
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IImageViewer {
|
|
|
|
uri: string;
|
2021-11-17 19:59:53 +00:00
|
|
|
imageComponentType?: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
width: number;
|
|
|
|
height: number;
|
|
|
|
theme: string;
|
2021-11-17 19:59:53 +00:00
|
|
|
onLoadEnd?: () => void;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
2021-11-17 19:59:53 +00:00
|
|
|
export const ImageViewer = ({ uri, imageComponentType, theme, width, height, ...props }: IImageViewer): JSX.Element => {
|
2020-06-26 20:22:56 +00:00
|
|
|
const backgroundColor = themes[theme].previewBackground;
|
|
|
|
const Component = ImageComponent(imageComponentType);
|
|
|
|
return (
|
2021-09-13 20:41:05 +00:00
|
|
|
// @ts-ignore
|
2020-06-26 20:22:56 +00:00
|
|
|
<ScrollView
|
|
|
|
style={{ backgroundColor }}
|
2021-09-13 20:41:05 +00:00
|
|
|
contentContainerStyle={[styles.scrollContent, width && { width }, height && { height }]}
|
2020-06-26 20:22:56 +00:00
|
|
|
showsHorizontalScrollIndicator={false}
|
|
|
|
showsVerticalScrollIndicator={false}
|
2021-09-13 20:41:05 +00:00
|
|
|
maximumZoomScale={2}>
|
|
|
|
<Component style={styles.image} resizeMode='contain' source={{ uri }} {...props} />
|
2020-06-26 20:22:56 +00:00
|
|
|
</ScrollView>
|
|
|
|
);
|
|
|
|
};
|