Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CustomTabBar.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import * as React from 'react';
  2. import {withTheme} from 'react-native-paper';
  3. import TabIcon from "./TabIcon";
  4. import TabHomeIcon from "./TabHomeIcon";
  5. import {Animated} from 'react-native';
  6. type Props = {
  7. state: Object,
  8. descriptors: Object,
  9. navigation: Object,
  10. theme: Object,
  11. collapsibleStack: Object,
  12. }
  13. type State = {
  14. translateY: AnimatedValue,
  15. barSynced: boolean,
  16. }
  17. const TAB_ICONS = {
  18. planning: 'calendar-range',
  19. proxiwash: 'tshirt-crew',
  20. proximo: 'cart',
  21. planex: 'clock',
  22. };
  23. /**
  24. * Abstraction layer for Agenda component, using custom configuration
  25. */
  26. class CustomTabBar extends React.Component<Props, State> {
  27. static TAB_BAR_HEIGHT = 48;
  28. activeColor: string;
  29. inactiveColor: string;
  30. state = {
  31. translateY: new Animated.Value(0),
  32. barSynced: false,// Is the bar synced with the header for animations?
  33. }
  34. // shouldComponentUpdate(nextProps: Props): boolean {
  35. // return (nextProps.theme.dark !== this.props.theme.dark)
  36. // || (nextProps.state.index !== this.props.state.index);
  37. // }
  38. tabRef: Object;
  39. constructor(props) {
  40. super(props);
  41. this.tabRef = React.createRef();
  42. this.activeColor = props.theme.colors.primary;
  43. this.inactiveColor = props.theme.colors.tabIcon;
  44. }
  45. onItemPress(route: Object, currentIndex: number, destIndex: number) {
  46. const event = this.props.navigation.emit({
  47. type: 'tabPress',
  48. target: route.key,
  49. canPreventDefault: true,
  50. });
  51. if (currentIndex !== destIndex && !event.defaultPrevented) {
  52. this.state.translateY = new Animated.Value(0);
  53. this.props.navigation.navigate(route.name);
  54. }
  55. }
  56. tabBarIcon = (route, focused) => {
  57. let icon = TAB_ICONS[route.name];
  58. icon = focused ? icon : icon + ('-outline');
  59. if (route.name !== "home")
  60. return icon;
  61. else
  62. return null;
  63. };
  64. onRouteChange = () => {
  65. this.setState({barSynced: false});
  66. }
  67. renderIcon = (route, index) => {
  68. const state = this.props.state;
  69. const {options} = this.props.descriptors[route.key];
  70. const label =
  71. options.tabBarLabel !== undefined
  72. ? options.tabBarLabel
  73. : options.title !== undefined
  74. ? options.title
  75. : route.name;
  76. const isFocused = state.index === index;
  77. const onPress = () => this.onItemPress(route, state.index, index);
  78. const onLongPress = () => {
  79. this.props.navigation.emit({
  80. type: 'tabLongPress',
  81. target: route.key,
  82. });
  83. };
  84. if (isFocused) {
  85. const stackState = route.state;
  86. const stackRoute = route.state ? stackState.routes[stackState.index] : undefined;
  87. const params = stackRoute ? stackRoute.params : undefined;
  88. const collapsible = params ? params.collapsible : undefined;
  89. if (collapsible && !this.state.barSynced) {
  90. this.setState({
  91. translateY: Animated.multiply(-1.5, collapsible.translateY),
  92. barSynced: true,
  93. });
  94. }
  95. }
  96. const color = isFocused ? this.activeColor : this.inactiveColor;
  97. if (route.name !== "home") {
  98. return <TabIcon
  99. onPress={onPress}
  100. onLongPress={onLongPress}
  101. icon={this.tabBarIcon(route, isFocused)}
  102. color={color}
  103. label={label}
  104. focused={isFocused}
  105. extraData={state.index > index}
  106. key={route.key}
  107. />
  108. } else
  109. return <TabHomeIcon
  110. onPress={onPress}
  111. onLongPress={onLongPress}
  112. focused={isFocused}
  113. key={route.key}
  114. />
  115. };
  116. render() {
  117. this.props.navigation.addListener('state', this.onRouteChange);
  118. return (
  119. <Animated.View
  120. ref={this.tabRef}
  121. // animation={"fadeInUp"}
  122. // duration={500}
  123. // useNativeDriver
  124. style={{
  125. flexDirection: 'row',
  126. height: CustomTabBar.TAB_BAR_HEIGHT,
  127. width: '100%',
  128. position: 'absolute',
  129. bottom: 0,
  130. left: 0,
  131. backgroundColor: this.props.theme.colors.surface,
  132. transform: [{translateY: this.state.translateY}]
  133. }}
  134. >
  135. {this.props.state.routes.map(this.renderIcon)}
  136. </Animated.View>
  137. );
  138. }
  139. }
  140. export default withTheme(CustomTabBar);