myContribution.js 5.18 KB
/**
 * Created by xiniu on 2018/4/25.
 */
import React, { Component } from 'react';
import {
    StyleSheet,
    View,
    Text,
    Dimensions,
    TouchableOpacity,
    Image,
    TextInput,
    FlatList,
    ActivityIndicator,
    Keyboard,
    ScrollView,
} from 'react-native';
import Carousel, { Pagination } from 'react-native-snap-carousel';
import { width, height, zoomW, zoomH } from '../../utils/getSize';
import { xnToast } from '../../utils/utils';
import AppService from '../../service/AppService';

export default class myContribution extends Component {
  static navigationOptions = ({ navigation, screenProps }) => ({
    title: '我的贡献',
    headerLeft: (
      <TouchableOpacity style={styles.backWrap} onPress={() => navigation.goBack()}>
        <Image source={require('../../img/back_gray.png')} resizeMode="contain" />
      </TouchableOpacity>
        ),
    headerRight: (
      <View />
      ),
  });

  constructor(props) {
    super(props);
    this.state = {
      entries: [1, 1, 1, 1],
      activeSlide: 0,
    };
  }

  componentWillMount() {
    // AppService.findMyContribution({ userId: global.user.id }).then((data) => {
    //   if (data.message) {
    //     xnToast(data.message);
    //     return;
    //   }
    //   if (!!data.errors === true && !!data.errors.length > 0) {
    //     xnToast(data.errors[0].message);
    //   } else {
    //     console.log(global.user, data, '-------------------------');
    //   }
    // });
  }

  _renderItem({ item, index }) {
    return (
      <View style={styles.carouselWrap}>
        <Image style={styles.carouselImg} source={require('../../img/carouselBg.png')} resizeMode="contain" />
        <Text style={{ fontSize: 18, color: '#FFDA14', marginBottom: 33 / zoomH }}>志愿服务</Text>
        <Text style={{ fontSize: 14, color: '#F9F9F9', marginBottom: 13 / zoomH }}>志愿服务共 <Text style={{ fontSize: 18, color: '#FFDA14' }}>28</Text> 次</Text>
        <Text style={{ fontSize: 14, color: '#F9F9F9' }}>时间总计 <Text style={{ fontSize: 18, color: '#FFDA14' }}>28</Text> 小时</Text>
      </View>
    );
  }

  get pagination() {
    const { entries, activeSlide } = this.state;
    return (
      <Pagination
        dotsLength={entries.length}
        activeDotIndex={activeSlide}
        containerStyle={{
          paddingVertical: 0,
        }}
        dotContainerStyle={{
          marginHorizontal: 10 / zoomW,
        }}
        dotStyle={{
          width: 29 / zoomW,
          height: 2 / zoomH,
          backgroundColor: '#FFFFFF',
          borderRadius: 0,
        }}
        inactiveDotStyle={{
          backgroundColor: '#C4C4C4',
        }}
        inactiveDotScale={1}
        inactiveDotOpacity={1}
      />
    );
  }

  render() {
    return (
      <View style={styles.background}>
        <View style={styles.bgImgWrap}>
          <Image style={{ width: '100%', height: '100%' }} source={require('../../img/contributionBg.png')} resizeMode="cover" />
        </View>
        <ScrollView style={{ flex: 1 }}>
          <View style={{ paddingTop: 42 / zoomH, alignItems: 'center' }}>
            <View style={styles.avatarWrap}>
              <Image style={{ width: 74 / zoomW, height: 74 / zoomW }} source={require('../../img/contributionAvatar.png')} resizeMode="contain" />
            </View>
            <View style={styles.baseInfoWrap}>
              <Text style={{ fontSize: 13, color: '#FCFCFC' }}>等级:12</Text>
              <View style={styles.gap} />
              <Text style={{ fontSize: 13, color: '#FCFCFC' }}>头衔:头衔名</Text>
            </View>
          </View>
          <Carousel
            ref={(c) => { this._carousel = c; }}
            data={this.state.entries}
            renderItem={this._renderItem}
            sliderWidth={width}
            itemWidth={176 / zoomW}
            inactiveSlideScale={0.85}
            containerCustomStyle={{ height: 272 / zoomH, marginBottom: 30 / zoomH }}
            onSnapToItem={index => this.setState({ activeSlide: index })}
          />
          { this.pagination }
        </ScrollView>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  backWrap: {
    justifyContent: 'center',
    paddingLeft: 18.5 / zoomW,
    paddingRight: 18.5 / zoomW,
    height: 44 / zoomH,
  },
  background: {
    flex: 1,
    backgroundColor: 'rgba(0,0,0,0.3)',
    display: 'flex',
    alignItems: 'center',
    position: 'relative',
  },
  bgImgWrap: {
    width: '100%',
    height: '100%',
    position: 'absolute',
    left: 0,
    top: 0,
  },
  baseInfoWrap: {
    flexDirection: 'row',
    alignItems: 'center',
    marginBottom: 27 / zoomH,
  },
  avatarWrap: {
    width: 80 / zoomW,
    height: 80 / zoomW,
    backgroundColor: '#EFEFEF',
    borderRadius: 4 / zoomW,
    justifyContent: 'center',
    alignItems: 'center',
    marginBottom: 27 / zoomH,
  },
  gap: {
    width: 1 / zoomW,
    height: 14 / zoomH,
    backgroundColor: '#F6F6F6',
    marginLeft: 25 / zoomW,
    marginRight: 25 / zoomW,
  },
  carouselWrap: {
    width: '100%',
    height: '100%',
    paddingTop: 31 / zoomH,
    alignItems: 'center',
    position: 'relative',
  },
  carouselImg: {
    width: '100%',
    height: '100%',
    position: 'absolute',
    left: 0,
    top: 0,
  },
});