index.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React from 'react';
  2. import { Text, TouchableOpacity, View } from 'react-native';
  3. import { Route, TabBar, TabView } from 'react-native-tab-view';
  4. import { styles } from './styles';
  5. import { Colors } from 'src/theme';
  6. import MarkToUpIcon from '../../../assets/icons/mark-to-up.svg';
  7. export const HorizontalTabView = ({
  8. index,
  9. setIndex,
  10. routes,
  11. renderScene,
  12. withMark,
  13. onDoubleClick,
  14. lazy = false
  15. }: {
  16. index: number;
  17. setIndex: React.Dispatch<React.SetStateAction<number>>;
  18. routes: Route[];
  19. renderScene: (props: any) => React.ReactNode;
  20. withMark?: boolean;
  21. onDoubleClick?: () => void;
  22. lazy?: boolean;
  23. }) => {
  24. const renderTabBar = (props: any) => (
  25. <TabBar
  26. {...props}
  27. renderLabel={({ route, focused }) => (
  28. <View style={[styles.tabLabelContainer, focused ? styles.tabLabelFocused : null]}>
  29. <Text style={[styles.label, focused ? styles.labelFocused : null]}>{route.title}</Text>
  30. {withMark ? (
  31. <MarkToUpIcon
  32. height={16}
  33. width={16}
  34. style={styles.icon}
  35. stroke={focused ? Colors.WHITE : Colors.DARK_BLUE}
  36. />
  37. ) : null}
  38. </View>
  39. )}
  40. scrollEnabled={true}
  41. indicatorStyle={styles.indicator}
  42. style={styles.tabBar}
  43. activeColor={Colors.ORANGE}
  44. inactiveColor={Colors.DARK_BLUE}
  45. tabStyle={styles.tabStyle}
  46. pressColor={'transparent'}
  47. />
  48. );
  49. return (
  50. <TabView
  51. navigationState={{ index, routes }}
  52. renderScene={renderScene}
  53. onIndexChange={setIndex}
  54. animationEnabled={true}
  55. swipeEnabled={true}
  56. style={styles.tabView}
  57. renderTabBar={renderTabBar}
  58. lazy={lazy}
  59. />
  60. );
  61. };