Nenhuma descrição

BaseNavigationBar.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * Created by zack on 2018/4/20.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. FlatList,
  9. Platform,
  10. TouchableOpacity,
  11. Image
  12. } from 'react-native'
  13. import React, {Component} from 'react'
  14. import BaseNavigationBarListItem from './BaseNavigationBarListItem'
  15. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../utils/DimensionsTools'
  16. export default class BaseNavigationBar extends Component {
  17. constructor(props) {
  18. super(props)
  19. this.state = {
  20. dataSources: props.dataSources,
  21. selectedIndex: props.selectedIndex,
  22. refreshing:props.refreshing||true
  23. }
  24. }
  25. componentWillReceiveProps(props) {
  26. this.setState({
  27. dataSources: props.dataSources,
  28. selectedIndex: props.selectedIndex,
  29. refreshing:true,
  30. })
  31. }
  32. renderItem(item) {
  33. // console.log('renderItem')
  34. return(
  35. <BaseNavigationBarListItem
  36. title = {item.title}
  37. isSelected = {this.state.selectedIndex === item.index}
  38. didSelectedItem = {() => {
  39. let datas = []
  40. for (let i = 0; i < this.state.dataSources.length; i ++) {
  41. datas.push(this.state.dataSources[i])
  42. }
  43. this.props.didSelectedItem(item.index)
  44. this.setState({dataSources: datas,selectedIndex: item.index})
  45. }}
  46. />
  47. )
  48. }
  49. render() {
  50. return (
  51. <View style={styles.View}>
  52. <View style={styles.ListView}>
  53. <FlatList
  54. data={this.state.dataSources}
  55. keyExtractor={(item, index) => { return 'key' + item.key + index }}
  56. renderItem={({item}) => this.renderItem(item)}
  57. horizontal={true}
  58. showsHorizontalScrollIndicator={false}
  59. refreshing={this.state.refreshing}
  60. refreshHandler={()=>{}}
  61. />
  62. </View>
  63. <Image style={styles.MineLeftLineImageView} source={require('../../resources/images/BaseNavigationBar/阴影分割.png')}/>
  64. <TouchableOpacity onPress={() => {
  65. this.props.didClickedMineItem()
  66. }} style={styles.MineBgView}>
  67. <Image style={styles.MineImageView} source={require('../../resources/images/BaseNavigationBar/icon-mine.png')}/>
  68. </TouchableOpacity>
  69. <View style={styles.BottomLineView} />
  70. </View>
  71. );
  72. }
  73. }
  74. const styles = StyleSheet.create({
  75. View: {
  76. position: 'absolute',
  77. left: 0,
  78. top: 0,
  79. height: NavigationBarHeight.height,
  80. width: ScreenDimensions.width,
  81. backgroundColor: "#ffffff",
  82. shadowColor: "#eeeeee",
  83. shadowOffset: {
  84. width: 0,
  85. height: -1
  86. },
  87. shadowRadius: 0,
  88. shadowOpacity: 1,
  89. flexDirection: 'row',
  90. alignItems: 'center',
  91. justifyContent: 'space-between',
  92. elevation: 5, //only for android
  93. zIndex:999,
  94. },
  95. ListView: {
  96. marginTop: Platform.OS === 'ios' ? 20 : 0,
  97. marginLeft: 15,
  98. width: ScreenDimensions.width - 15 - (Platform.OS === 'ios' ? 44 : 56),
  99. height: Platform.OS === 'ios' ? (NavigationBarHeight.height - 20) : NavigationBarHeight.height,
  100. },
  101. MineBgView: {
  102. marginTop: Platform.OS === 'ios' ? 20 : 0,
  103. width: (Platform.OS === 'ios' ? 44 : 56),
  104. height: Platform.OS === 'ios' ? (NavigationBarHeight.height - 20) : NavigationBarHeight.height,
  105. flexDirection: 'row',
  106. alignItems: 'center',
  107. },
  108. MineImageView: {
  109. width: 21,
  110. height: 22,
  111. marginLeft: Platform.OS === 'ios' ? 10 : 15
  112. },
  113. MineLeftLineImageView: {
  114. height: 30,
  115. width: 11,
  116. position: 'absolute',
  117. top: Platform.OS === 'ios' ? 27 : 13,
  118. right: Platform.OS === 'ios' ? 44 : 56
  119. },
  120. BottomLineView: {
  121. width: ScreenDimensions.width,
  122. height: 0.5,
  123. backgroundColor: '#cacaca',
  124. position: 'absolute',
  125. left: 0,
  126. bottom: 0,
  127. }
  128. })