ScrollView
, FlatList
로 충분히 만들수있다고 한다!FlatList
를 적용해서 만들어보려고 한다우선 사용하기전에 이친구에 대해서 정리를 해보려한다
interface ReviewPropsType {
userName: string;
userImage: string;
reviewImage: string[];
reviewMainText: string;
}
export default function ReviewBox(props: ReviewPropsType) {
const screenWidth = Math.round(Dimensions.get("window").width);
return (
<View style={styles.reviewBoxContainer}>
<View style={styles.userInfoContainer}>
{/* 5월 31일 2시 8분 User Icon 추후 데이터값 인입시 Image로 변경 예정 */}
<UserIcon name="user-circle-o" size={40} />
<CustomText
children="유저이름입니다"
fontWeight="bold"
fontSize="20px"
marginLft="12px"
marginTop="2px"
/>
</View>
<View style={styles.reviewImageContainer}>
<Carousel
images={props.reviewImage}
gap={15}
offset={36}
pageWidth={screenWidth - (15 + 36) * 2}
/>
</View>
<View>
<CustomText children={`${props.reviewMainText}`} />
</View>
</View>
);
}
interface CarouselProps {
images: string[];
gap: number;
offset: number;
pageWidth: number;
}
export default function Carousel(props: CarouselProps) {
const renderItem = (item: string, index: number) => {
return (
<Image
key={item}
source={{ uri: item }}
style={{
width: props.pageWidth,
marginHorizontal: props.gap / 2,
marginLeft: 0,
borderRadius: 5,
marginRight: index === props.images.length - 1 ? 0 : 20,
}}
/>
);
};
return (
<View style={styles.container}>
{props.images.length === 1 ? (
<Image source={{ uri: props.images[0] }} style={styles.image} />
) : (
<FlatList
automaticallyAdjustContentInsets={false}
data={props.images}
decelerationRate="fast"
horizontal
renderItem={(item) => renderItem(item.item, item.index)}
showsHorizontalScrollIndicator={false}
/>
)}
</View>
);
}
const styles = StyleSheet.create({
container: {
height: 210,
width: "100%",
},
imageWrapper: {
width: 230,
height: 210,
},
image: { width: "100%", height: "100%", borderRadius: 5 },
});