import React from 'react' import { Image, ImageStyle, LayoutChangeEvent, StyleProp, StyleSheet, TouchableWithoutFeedback, View, ViewStyle, } from 'react-native' interface Dim { width: number height: number } export type ImageLayoutGridType = 'two' | 'three' | 'four' export function ImageLayoutGrid({ type, uris, onPress, style, }: { type: ImageLayoutGridType uris: string[] onPress?: (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, containerInfo, }: { type: ImageLayoutGridType uris: string[] onPress?: (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)}> onPress?.(1)}> ) } if (type === 'three') { return ( onPress?.(0)}> onPress?.(1)}> onPress?.(2)}> ) } if (type === 'four') { return ( onPress?.(0)}> onPress?.(1)}> onPress?.(2)}> onPress?.(3)}> ) } return } const styles = StyleSheet.create({ flexRow: {flexDirection: 'row'}, wSpace: {width: 5}, hSpace: {height: 5}, })