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.tsx 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2019 - 2020 Arnaud Vergnet.
  3. *
  4. * This file is part of Campus INSAT.
  5. *
  6. * Campus INSAT is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Campus INSAT is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. import React from 'react';
  20. import type { BottomTabBarProps } from '@react-navigation/bottom-tabs';
  21. import { Animated, StyleSheet } from 'react-native';
  22. import TabIcon from './TabIcon';
  23. import { useTheme } from 'react-native-paper';
  24. import { useCollapsible } from '../../context/CollapsibleContext';
  25. export const TAB_BAR_HEIGHT = 50;
  26. function CustomTabBar(
  27. props: BottomTabBarProps<any> & {
  28. icons: {
  29. [key: string]: {
  30. normal: string;
  31. focused: string;
  32. };
  33. };
  34. labels: {
  35. [key: string]: string;
  36. };
  37. }
  38. ) {
  39. const state = props.state;
  40. const theme = useTheme();
  41. const { collapsible } = useCollapsible();
  42. let translateY: number | Animated.AnimatedInterpolation = 0;
  43. if (collapsible) {
  44. translateY = Animated.multiply(-1.5, collapsible.translateY);
  45. }
  46. return (
  47. <Animated.View
  48. style={{
  49. ...styles.bar,
  50. backgroundColor: theme.colors.surface,
  51. transform: [{ translateY: translateY }],
  52. }}
  53. >
  54. {state.routes.map(
  55. (
  56. route: {
  57. key: string;
  58. name: string;
  59. params?: object | undefined;
  60. },
  61. index: number
  62. ) => {
  63. const iconData = props.icons[route.name];
  64. return (
  65. <TabIcon
  66. isMiddle={index === 2}
  67. onPress={() => props.navigation.navigate(route.name)}
  68. icon={iconData.normal}
  69. focusedIcon={iconData.focused}
  70. label={props.labels[route.name]}
  71. focused={state.index === index}
  72. key={route.key}
  73. />
  74. );
  75. }
  76. )}
  77. </Animated.View>
  78. );
  79. }
  80. const styles = StyleSheet.create({
  81. bar: {
  82. flexDirection: 'row',
  83. width: '100%',
  84. height: 50,
  85. position: 'absolute',
  86. bottom: 0,
  87. left: 0,
  88. },
  89. });
  90. function areEqual(
  91. prevProps: BottomTabBarProps<any>,
  92. nextProps: BottomTabBarProps<any>
  93. ) {
  94. return prevProps.state.index === nextProps.state.index;
  95. }
  96. export default React.memo(CustomTabBar, areEqual);