2024-02-12 08:58:57 +08:00
|
|
|
import React, { useEffect, useState } from "react";
|
2023-09-26 14:33:01 +08:00
|
|
|
import {
|
|
|
|
FlatList,
|
|
|
|
Image,
|
|
|
|
ScrollView,
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
TouchableOpacity,
|
|
|
|
View,
|
|
|
|
} from "react-native";
|
|
|
|
|
2024-02-12 08:58:57 +08:00
|
|
|
const Variation = ({ vars, prod, setactiveVar }) => {
|
2023-09-26 14:33:01 +08:00
|
|
|
const cat = [
|
|
|
|
"https://obanana.com/wp-content/uploads/2022/03/viber_image_2022-03-30_15-08-57-885-150x150.png",
|
|
|
|
"https://obanana.com/wp-content/uploads/2022/03/viber_image_2022-03-30_15-09-00-222-150x150.png",
|
|
|
|
"https://obanana.com/wp-content/uploads/2022/03/viber_image_2022-03-30_15-09-03-056-150x150.png",
|
|
|
|
];
|
2024-02-12 08:58:57 +08:00
|
|
|
const [varss, setvarss] = useState([]);
|
|
|
|
useEffect(() => {
|
|
|
|
const variation = [prod];
|
|
|
|
|
|
|
|
setvarss([...vars]);
|
|
|
|
// console.log(vars+"----");
|
|
|
|
// console.log(vars)
|
|
|
|
}, [vars, prod]);
|
|
|
|
|
|
|
|
const [active, setactive] = useState(null);
|
2023-09-26 14:33:01 +08:00
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
2024-02-12 08:58:57 +08:00
|
|
|
<Text style={styles.header}>Select Variation</Text>
|
2023-09-26 14:33:01 +08:00
|
|
|
<View style={{ flexDirection: "row" }}>
|
|
|
|
<FlatList
|
|
|
|
// inverted
|
|
|
|
// style={styles.wrapper}
|
|
|
|
horizontal
|
2024-02-12 08:58:57 +08:00
|
|
|
data={varss ? varss : []}
|
2023-09-26 14:33:01 +08:00
|
|
|
showsHorizontalScrollIndicator={false}
|
2024-02-12 08:58:57 +08:00
|
|
|
renderItem={({ item, index }) => {
|
2023-09-26 14:33:01 +08:00
|
|
|
return (
|
2024-02-12 08:58:57 +08:00
|
|
|
<TouchableOpacity
|
|
|
|
onPress={() => {
|
|
|
|
setactive(index);
|
|
|
|
setactiveVar(index);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<View
|
|
|
|
style={
|
|
|
|
index === active ? styles.AddUserActive : styles.AddUser
|
|
|
|
}
|
|
|
|
>
|
2023-09-26 14:33:01 +08:00
|
|
|
<Image
|
|
|
|
style={styles.img}
|
|
|
|
source={{
|
2024-02-12 08:58:57 +08:00
|
|
|
uri: item.product_image,
|
2023-09-26 14:33:01 +08:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Text
|
|
|
|
style={{
|
|
|
|
color: "#000",
|
|
|
|
fontSize: 10,
|
|
|
|
flexWrap: "wrap",
|
|
|
|
}}
|
|
|
|
></Text>
|
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
// flex: 1,
|
|
|
|
backgroundColor: "#fff",
|
|
|
|
// alignItems: "center",
|
|
|
|
// justifyContent: "center",
|
|
|
|
width: "100%",
|
|
|
|
// marginHorizontal: 10,
|
|
|
|
padding: 10,
|
2024-02-12 08:58:57 +08:00
|
|
|
paddingBottom: 0,
|
2023-09-26 14:33:01 +08:00
|
|
|
// height: "87%",
|
|
|
|
},
|
|
|
|
wrapper: {
|
|
|
|
width: "100%",
|
|
|
|
height: 200,
|
|
|
|
// backgroundColor: "#ffaa00",
|
2024-02-12 08:58:57 +08:00
|
|
|
// padding: 10,
|
2023-09-26 14:33:01 +08:00
|
|
|
},
|
|
|
|
header: {
|
|
|
|
fontSize: 14,
|
|
|
|
fontWeight: "700",
|
|
|
|
// textTransform: "uppercase",
|
2024-02-12 08:58:57 +08:00
|
|
|
paddingHorizontal: 5,
|
|
|
|
marginBottom: 15,
|
2023-09-26 14:33:01 +08:00
|
|
|
},
|
|
|
|
img: {
|
|
|
|
width: 80,
|
|
|
|
height: 80,
|
|
|
|
resizeMode: "cover",
|
|
|
|
borderRadius: 10,
|
2024-02-12 08:58:57 +08:00
|
|
|
backgroundColor: "#f1f1f1",
|
|
|
|
// padding: 10,
|
2023-09-26 14:33:01 +08:00
|
|
|
},
|
|
|
|
AddUser: {
|
|
|
|
padding: 10,
|
2024-02-12 08:58:57 +08:00
|
|
|
paddingBottom: 0,
|
|
|
|
|
|
|
|
borderWidth: 2,
|
|
|
|
borderColor: "#eee",
|
|
|
|
},
|
|
|
|
AddUserActive: {
|
|
|
|
padding: 10,
|
|
|
|
paddingBottom: 0,
|
|
|
|
|
|
|
|
borderWidth: 2,
|
|
|
|
borderColor: "#ffaa00",
|
2023-09-26 14:33:01 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
export default Variation;
|