// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import {type ImageContentFit, type ImageStyle} from 'expo-image'; import React, {type ReactNode, useEffect, useState} from 'react'; import {type StyleProp, StyleSheet, View, type ViewStyle} from 'react-native'; import Animated from 'react-native-reanimated'; import ExpoImage, {ExpoImageAnimated, ExpoImageBackground} from '@components/expo_image'; import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme'; type Props = ProgressiveImageProps & { children?: ReactNode | ReactNode[]; forwardRef?: React.RefObject; id: string; imageStyle?: StyleProp; isBackgroundImage?: boolean; onError: () => void; contentFit?: ImageContentFit; style?: StyleProp; tintDefaultSource?: boolean; theme: Theme; }; const getStyleSheet = makeStyleSheetFromTheme((theme) => { return { defaultImageContainer: { alignItems: 'center', justifyContent: 'center', backgroundColor: changeOpacity(theme.centerChannelColor, 0.08), }, defaultImageTint: { flex: 1, tintColor: changeOpacity(theme.centerChannelColor, 0.2), }, }; }); const ProgressiveImage = ({ children, defaultSource, forwardRef, id, imageStyle, imageUri, inViewPort, isBackgroundImage, onError, contentFit = 'contain', style = {}, thumbnailUri, tintDefaultSource, theme, }: Props) => { const [showHighResImage, setShowHighResImage] = useState(false); const styles = getStyleSheet(theme); useEffect(() => { if (inViewPort) { setShowHighResImage(inViewPort); } }, [inViewPort]); if (isBackgroundImage && imageUri) { return ( ]} > {children} ); } if (defaultSource) { return ( ); } const showImage = showHighResImage || !thumbnailUri; return ( ); }; export default ProgressiveImage;