TabBar.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React from 'react'
  2. import { TouchableOpacity, View, Text, StyleSheet } from 'react-native'
  3. import theme from '../theme'
  4. const TabBar = props => (
  5. <View style={styles.container}>
  6. <View style={styles.body}>
  7. {props.tabs.map((tab, i) => (
  8. // change the style to fit your needs
  9. <TouchableOpacity
  10. activeOpacity={0.9}
  11. key={tab.key || i}
  12. style={styles.itemContainer}
  13. onPress={() => {
  14. const {goToTab, onTabClick} = props;
  15. // tslint:disable-next-line:no-unused-expression
  16. onTabClick && onTabClick(props.tabs[i], i);
  17. // tslint:disable-next-line:no-unused-expression
  18. goToTab && goToTab(i);
  19. }}
  20. >
  21. <Text style={styles.title}>
  22. {tab.title}
  23. </Text>
  24. <View style={{
  25. backgroundColor: props.activeTab === i ? theme.brand_primary : undefined,
  26. height: 3,
  27. borderRadius: 2,
  28. width: 25
  29. }}></View>
  30. </TouchableOpacity>
  31. ))}
  32. </View>
  33. {props.rightComponent ? props.rightComponent : null}
  34. </View>
  35. )
  36. const styles = StyleSheet.create({
  37. container: {
  38. flexDirection: 'row',
  39. backgroundColor: '#fff',
  40. borderColor: '#fff'
  41. },
  42. body: {
  43. flex: 1,
  44. paddingHorizontal: 16,
  45. flexDirection: 'row',
  46. justifyContent: 'flex-start',
  47. width: 180,
  48. height: 34,
  49. paddingTop: 6
  50. },
  51. itemContainer:{
  52. width: 70,
  53. alignItems: 'center'
  54. },
  55. title:{
  56. color: '#333',
  57. fontSize: 16,
  58. marginBottom: 5
  59. }
  60. });
  61. export default TabBar