ShareDetail.js 4.34 KB
import React, { Component, PureComponent } from 'react';
import { Dimensions, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native';

const { width } = Dimensions.get('window');

export default class ShareDetail extends Component {
  state = { opacity: 0 }
  render() {
    return (
      <View style={styles.container}>
        <View style={{backgroundColor: 'black', height: 42, width, opacity: this.state.opacity, position: 'absolute', top: 0, zIndex: 10}}>
        </View>
        <View style={{backgroundColor: 'black', height: 24, width: 24, opacity: 0.5 - this.state.opacity, borderWidth: 1, borderColor: 'transparent', borderRadius: 12, position: 'absolute', top: 9, left: 20}} />
        <ScrollView
          style={styles.container}
          contentContainerStyle={styles.contentContainerStyle}
          showsVerticalScrollIndicator={false}
          onScroll={(e) => this.changeOpacity(e)}>
          <View style={[styles.imgContainer]}>
          </View>
          <View style={styles.nameContainer}>
            <Text style={styles.name}>HUMAN MADE 字母印花圆领T</Text>
          </View>
          <View style={[styles.priceContainer, styles.border]}>
            <Text style={styles.price}> 99.9</Text>
            <Text style={styles.origPrice}> 239</Text>
          </View>
          <View style={[styles.promContainer, styles.border]}>
            <Text style={styles.proDesc}>新客订单返现10%,老客订单返现3%(预计最高返现¥9.9</Text>
          </View>
          <View style={[styles.recommendContainer, styles.border]}>
            <TouchableOpacity onPress={() => null}>
              <Text style={styles.recommendText}>查看其它推荐商品</Text>
            </TouchableOpacity>
          </View>
        </ScrollView>
        <View style={[styles.bottomBar, styles.border]}>
          <View style={[styles.favContainer, styles.center]}>
            <TouchableOpacity onPress={() => null} style={styles.favorite} />
          </View>
          <View style={styles.buttonContainer}>
            <TouchableOpacity onPress={() => null}>
              <View style={[styles.button, styles.center]}>
                <Text style={styles.btnText}>查看商品详情</Text>
              </View>
            </TouchableOpacity>
            <TouchableOpacity onPress={() => null}>
              <View style={[styles.button, styles.center, styles.red]}>
                <Text style={styles.btnText}>分享可赚¥9.9</Text>
              </View>
            </TouchableOpacity>
          </View>
        </View>
      </View>
    );
  }

  changeOpacity(e) {
    let opacity = 1 - (600 - e.nativeEvent.contentOffset.y) / 600;
    this.setState({opacity: opacity < 0.5 ? opacity : 0.5});
    console.log(e.nativeEvent.contentOffset.y);
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  contentContainerStyle: {
    height: 1000,
  },
  center: {
    justifyContent: 'center',
    alignItems: 'center',
  },
  imgContainer: {
    flex: 1,
  },
  nameContainer: {
    height: 46,
    paddingLeft: 20,
    backgroundColor: '#393939',
    justifyContent: 'center',
  },
  name: {
    color: '#fff',
  },
  border: {
    borderTopWidth: 1,
    borderColor: '#5d5d5d'
  },
  priceContainer: {
    height: 46,
    paddingLeft: 20,
    flexDirection: 'row',
    alignItems: 'center',
  },
  price: {
    fontSize: 16,
    fontWeight: '500',
    color: '#D0021B'
  },
  origPrice: {
    color: '#909090',
    marginLeft: 12
  },
  promContainer: {
    height: 46,
    paddingLeft: 20,
    flexDirection: 'row',
    alignItems: 'center',
  },
  proDesc: {
    color: '#909090',
    fontSize: 10,
  },
  recommendContainer: {
    height: 80,
    justifyContent: 'center',
    alignItems: 'center',
  },
  recommendText: {
    fontWeight: '500',
    fontSize: 12,
  },
  bottomBar: {
    flexDirection: 'row',
    height: 64,
    alignItems: 'center',
  },
  favContainer: {
    width: width / 5,
  },
  favorite: {
    height: 24,
    width: 24,
    borderWidth: 1,
    borderRadius: 12,
    marginHorizontal: 25
  },
  buttonContainer: {
    flex: 1,
    marginRight: 20,
    flexDirection: 'row',
    justifyContent: 'space-between',
  },
  button: {
    backgroundColor: 'black',
    borderRadius: 3,
    height: 50,
    width: width / 3,
  },
  red: {
    backgroundColor: '#D0021B'
  },
  btnText: {
    color: '#fff',
    fontSize: 13,
  }
})