ShakeScreen.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import React, {Component} from 'react';
  2. import CommonTitleBar from '../views/CommonTitleBar';
  3. import {Dimensions, Image, StyleSheet, Text, TouchableOpacity, View} from 'react-native';
  4. const {width} = Dimensions.get('window');
  5. const normalSource = [
  6. require('../../images/ic_shake_person_normal.png'),
  7. require('../../images/ic_shake_music_normal.png'),
  8. require('../../images/ic_shake_tv_normal.png')
  9. ];
  10. const checkedSource = [
  11. require('../../images/ic_shake_person_checked.png'),
  12. require('../../images/ic_shake_music_checked.png'),
  13. require('../../images/ic_shake_tv_checked.png')
  14. ];
  15. export default class ShakeScreen extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. icons: [checkedSource[0], normalSource[1], normalSource[2]]
  20. }
  21. }
  22. render() {
  23. return (
  24. <View style={styles.container}>
  25. <CommonTitleBar nav={this.props.navigation} title={"摇一摇"}/>
  26. <View style={styles.content}>
  27. <Image style={styles.shakeImg} source={require('../../images/ic_shake_above.png')}/>
  28. <Image style={styles.shakeImg} source={require('../../images/ic_shake_below.png')}/>
  29. </View>
  30. <View style={styles.bottomContainer}>
  31. <TouchableOpacity style={styles.tabContainer} onPress={() => this.handleTabClick(0)}>
  32. <View style={styles.tabContainer}>
  33. <Image ref="iconPerson" style={styles.tabIcon} source={this.state.icons[0]}/>
  34. <Text style={styles.tabTitle}>人</Text>
  35. </View>
  36. </TouchableOpacity>
  37. <TouchableOpacity style={styles.tabContainer} onPress={() => this.handleTabClick(1)}>
  38. <View style={styles.tabContainer}>
  39. <Image ref="iconMusic" style={styles.tabIcon} source={this.state.icons[1]}/>
  40. <Text style={styles.tabTitle}>歌曲</Text>
  41. </View>
  42. </TouchableOpacity>
  43. <TouchableOpacity style={styles.tabContainer} onPress={() => this.handleTabClick(2)}>
  44. <View style={styles.tabContainer}>
  45. <Image ref="iconTv" style={styles.tabIcon} source={this.state.icons[2]}/>
  46. <Text style={styles.tabTitle}>电视</Text>
  47. </View>
  48. </TouchableOpacity>
  49. </View>
  50. </View>
  51. );
  52. }
  53. handleTabClick(index) {
  54. let arr = this.state.icons;
  55. for (let i = 0; i < arr.length; i++) {
  56. if (index == i) {
  57. arr[i] = checkedSource[i];
  58. } else {
  59. arr[i] = normalSource[i];
  60. }
  61. }
  62. this.setState({icons: arr});
  63. }
  64. }
  65. const styles = StyleSheet.create({
  66. container: {
  67. flex: 1,
  68. flexDirection: 'column',
  69. },
  70. content: {
  71. flex: 1,
  72. backgroundColor: '#282C2D',
  73. justifyContent: 'center',
  74. alignItems: 'center'
  75. },
  76. shakeImg: {
  77. width: 150,
  78. height: 84
  79. },
  80. bottomContainer: {
  81. flexDirection: 'row',
  82. height: 120,
  83. width: width,
  84. backgroundColor: '#282C2D',
  85. justifyContent: 'center',
  86. alignItems: 'center',
  87. },
  88. tabContainer: {
  89. flex: 1,
  90. flexDirection: 'column',
  91. justifyContent: 'center',
  92. alignItems: 'center',
  93. },
  94. tabIcon: {
  95. width: 40,
  96. height: 36,
  97. },
  98. tabTitle: {
  99. fontSize: 16,
  100. marginTop: 10,
  101. color: '#FFFFFF'
  102. }
  103. });