import React from "react"; import { StyleSheet, Dimensions, ScrollView, TouchableHighlight, TouchableWithoutFeedback, Image, Animated, Platform } from "react-native"; import { Block, Text, Button, theme } from "galio-framework"; import { Icon } from "../components"; import argonTheme from "../constants/Theme"; import Images from "../constants/Images"; import { iPhoneX, HeaderHeight } from "../constants/utils"; const { height, width } = Dimensions.get("window"); export default class Product extends React.Component { state = { selectedSize: null }; scrollX = new Animated.Value(0); renderGallery = () => { const { navigation, route } = this.props; // const { params } = navigation && navigation.state; // const product = params.product; const product = route.params?.product; const productImages = [ product.image, product.image, product.image, product.image ]; return ( {productImages.map((image, index) => ( navigation.navigate("Gallery", { images: productImages, index }) } > ))} ); }; renderProgress = () => { const { navigation, route } = this.props; // const { params } = navigation && navigation.state; // const product = params.product; const product = route.params?.product; const productImages = [ product.image, product.image, product.image, product.image ]; const position = Animated.divide(this.scrollX, width); return ( {productImages.map((_, i) => { const opacity = position.interpolate({ inputRange: [i - 1, i, i + 1], outputRange: [0.5, 1, 0.5], extrapolate: "clamp" }); const width = position.interpolate({ inputRange: [i - 1, i, i + 1], outputRange: [8, 18, 8], extrapolate: "clamp" }); return ( ); })} ); }; renderSize = label => { const active = this.state.selectedSize === label; return ( this.setState({ selectedSize: label })} > {label} ); }; renderChatButton = () => { const { navigation } = this.props; return ( ); }; render() { const { selectedSize } = this.state; const { navigation, route } = this.props; // const { params } = navigation && navigation.state; // const product = params.product; const product = route.params?.product; return ( {this.renderGallery()} {this.renderProgress()} {this.renderChatButton()} {product.title} Jessica Jones Pro Seller $899 Size {this.renderSize("XS")} {this.renderSize("S")} {this.renderSize("M")} {this.renderSize("L")} {this.renderSize("XL")} {this.renderSize("2XL")} ); } } const styles = StyleSheet.create({ product: { marginTop: Platform.OS === "android" ? -HeaderHeight : 0 }, options: { position: "relative", marginHorizontal: theme.SIZES.BASE, marginTop: -theme.SIZES.BASE * 2, marginBottom: 0, borderTopLeftRadius: 13, borderTopRightRadius: 13, backgroundColor: theme.COLORS.WHITE, shadowColor: "black", shadowOffset: { width: 0, height: 0 }, shadowRadius: 8, shadowOpacity: 0.2 }, galleryImage: { width: width, height: "auto" }, dots: { height: theme.SIZES.BASE / 2, margin: theme.SIZES.BASE / 2, borderRadius: 4, backgroundColor: "white" }, dotsContainer: { position: "absolute", bottom: theme.SIZES.BASE, left: 0, right: 0, bottom: height / 10 }, addToCart: { width: width - theme.SIZES.BASE * 4, marginTop: theme.SIZES.BASE * 2, shadowColor: "rgba(0, 0, 0, 0.2)", shadowOffset: { width: 0, height: 4 }, shadowRadius: 8, shadowOpacity: 1 }, avatar: { height: 40, width: 40, borderRadius: 20, marginBottom: theme.SIZES.BASE, marginRight: 8 }, chat: { width: 56, height: 56, padding: 20, borderRadius: 28, shadowColor: "rgba(0, 0, 0, 0.2)", shadowOffset: { width: 0, height: 4 }, shadowRadius: 8, shadowOpacity: 1 }, chatContainer: { top: -32, right: theme.SIZES.BASE, zIndex: 2, position: "absolute" }, size: { height: theme.SIZES.BASE * 3, width: (width - theme.SIZES.BASE * 2) / 3, borderBottomWidth: 0.5, borderBottomColor: argonTheme.COLORS.BORDER_COLOR, overflow: "hidden" }, sizeButton: { height: theme.SIZES.BASE * 3, width: "100%", justifyContent: "center", alignItems: "center" }, active: { backgroundColor: argonTheme.COLORS.PRICE_COLOR }, roundTopLeft: { borderTopLeftRadius: 4, borderRightColor: argonTheme.COLORS.BORDER_COLOR, borderRightWidth: 0.5 }, roundBottomLeft: { borderBottomLeftRadius: 4, borderRightColor: argonTheme.COLORS.BORDER_COLOR, borderRightWidth: 0.5, borderBottomWidth: 0 }, roundTopRight: { borderTopRightRadius: 4, borderLeftColor: argonTheme.COLORS.BORDER_COLOR, borderLeftWidth: 0.5 }, roundBottomRight: { borderBottomRightRadius: 4, borderLeftColor: argonTheme.COLORS.BORDER_COLOR, borderLeftWidth: 0.5, borderBottomWidth: 0 } });