TopTabBar.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import React from 'react'
  2. import {
  3. StyleSheet,
  4. Text,
  5. View,
  6. TouchableOpacity,
  7. Dimensions,
  8. PixelRatio,
  9. } from 'react-native'
  10. import Bubble from '../Bubble'
  11. const { width, height } = Dimensions.get('window')
  12. class TopTabBar extends React.Component {
  13. constructor(props) {
  14. super(props)
  15. }
  16. render() {
  17. return (
  18. <View
  19. style={{
  20. flexDirection: 'row',
  21. borderBottomColor: '#DDD',
  22. backgroundColor: '#fff',
  23. borderBottomWidth: 1 / PixelRatio.get(),
  24. }}
  25. >
  26. <View style={[styles.tabs, this.props.style, { width: width }]}>
  27. {this.props.tabs.map((tab, i) => {
  28. let right = 10
  29. if (
  30. (tab.split('/') && tab.split('/')[0].length > 2) ||
  31. tab.split('/')[1] > 9
  32. ) {
  33. right = 10
  34. } else {
  35. right = 16
  36. }
  37. return (
  38. <View key={tab} style={styles.tab}>
  39. <TouchableOpacity onPress={() => this.props.goToPage(i)}>
  40. <View
  41. style={{
  42. height: 35,
  43. justifyContent: 'center',
  44. paddingTop: 5,
  45. // borderBottomColor:
  46. // this.props.activeTab === i ? "#E14C46" : "transparent",
  47. // borderBottomWidth: 2,
  48. }}
  49. >
  50. <Text
  51. style={{
  52. fontSize: 14,
  53. lineHeight: 20,
  54. letterSpacing: 0.17,
  55. color: this.props.activeTab === i ? '#E14C46' : '#333',
  56. }}
  57. >
  58. {tab.split('/')[0]}
  59. </Text>
  60. </View>
  61. </TouchableOpacity>
  62. <Bubble
  63. bubbleColor={'#E14C46'}
  64. size={12}
  65. fontSize={8}
  66. style={{ position: 'absolute', right: right, top: 5 }}
  67. value={tab.split('/')[1] ? parseFloat(tab.split('/')[1]) : 0}
  68. />
  69. </View>
  70. )
  71. })}
  72. </View>
  73. </View>
  74. )
  75. }
  76. }
  77. const styles = StyleSheet.create({
  78. tab: {
  79. flex: 1,
  80. alignItems: 'center',
  81. justifyContent: 'center',
  82. paddingBottom: 10,
  83. },
  84. tabs: {
  85. height: 35,
  86. flexDirection: 'row',
  87. // paddingTop: 10
  88. },
  89. })
  90. export default TopTabBar