import React from 'react' import { LayoutChangeEvent, StyleProp, StyleSheet, TouchableOpacity, View, ViewStyle, } from 'react-native' import Image, {ImageStyle} from 'view/com/util/images/Image' export const DELAY_PRESS_IN = 500 interface Dim { width: number height: number } export type ImageLayoutGridType = 'two' | 'three' | 'four' export function ImageLayoutGrid({ type, uris, onPress, onLongPress, onPressIn, style, }: { type: ImageLayoutGridType uris: string[] onPress?: (index: number) => void onLongPress?: (index: number) => void onPressIn?: (index: number) => void style?: StyleProp }) { const [containerInfo, setContainerInfo] = React.useState() const onLayout = (evt: LayoutChangeEvent) => { setContainerInfo({ width: evt.nativeEvent.layout.width, height: evt.nativeEvent.layout.height, }) } return ( {containerInfo ? ( ) : undefined} ) } function ImageLayoutGridInner({ type, uris, onPress, onLongPress, onPressIn, containerInfo, }: { type: ImageLayoutGridType uris: string[] onPress?: (index: number) => void onLongPress?: (index: number) => void onPressIn?: (index: number) => void containerInfo: Dim }) { const size1 = React.useMemo>(() => { if (type === 'three') { const size = (containerInfo.width - 10) / 3 return {width: size, height: size, resizeMode: 'cover', borderRadius: 4} } else { const size = (containerInfo.width - 5) / 2 return {width: size, height: size, resizeMode: 'cover', borderRadius: 4} } }, [type, containerInfo]) const size2 = React.useMemo>(() => { if (type === 'three') { const size = ((containerInfo.width - 10) / 3) * 2 + 5 return {width: size, height: size, resizeMode: 'cover', borderRadius: 4} } else { const size = (containerInfo.width - 5) / 2 return {width: size, height: size, resizeMode: 'cover', borderRadius: 4} } }, [type, containerInfo]) if (type === 'two') { return ( onPress?.(0)} onPressIn={() => onPressIn?.(0)} onLongPress={() => onLongPress?.(0)}> onPress?.(1)} onPressIn={() => onPressIn?.(1)} onLongPress={() => onLongPress?.(1)}> ) } if (type === 'three') { return ( onPress?.(0)} onPressIn={() => onPressIn?.(0)} onLongPress={() => onLongPress?.(0)}> onPress?.(1)} onPressIn={() => onPressIn?.(1)} onLongPress={() => onLongPress?.(1)}> onPress?.(2)} onPressIn={() => onPressIn?.(2)} onLongPress={() => onLongPress?.(2)}> ) } if (type === 'four') { return ( onPress?.(0)} onPressIn={() => onPressIn?.(0)} onLongPress={() => onLongPress?.(0)}> onPress?.(2)} onPressIn={() => onPressIn?.(2)} onLongPress={() => onLongPress?.(2)}> onPress?.(1)} onPressIn={() => onPressIn?.(1)} onLongPress={() => onLongPress?.(1)}> onPress?.(3)} onPressIn={() => onPressIn?.(3)} onLongPress={() => onLongPress?.(3)}> ) } return } const styles = StyleSheet.create({ flexRow: {flexDirection: 'row'}, wSpace: {width: 5}, hSpace: {height: 5}, })