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.

TabIcon.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. // @flow
  20. import * as React from 'react';
  21. import {View} from 'react-native';
  22. import {TouchableRipple, withTheme} from 'react-native-paper';
  23. import type {MaterialCommunityIconsGlyphs} from 'react-native-vector-icons/MaterialCommunityIcons';
  24. import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
  25. import * as Animatable from 'react-native-animatable';
  26. import type {CustomThemeType} from '../../managers/ThemeManager';
  27. type PropsType = {
  28. focused: boolean,
  29. color: string,
  30. label: string,
  31. icon: MaterialCommunityIconsGlyphs,
  32. onPress: () => void,
  33. onLongPress: () => void,
  34. theme: CustomThemeType,
  35. extraData: null | boolean | number | string,
  36. };
  37. /**
  38. * Abstraction layer for Agenda component, using custom configuration
  39. */
  40. class TabIcon extends React.Component<PropsType> {
  41. firstRender: boolean;
  42. constructor(props: PropsType) {
  43. super(props);
  44. Animatable.initializeRegistryWithDefinitions({
  45. focusIn: {
  46. '0': {
  47. scale: 1,
  48. translateY: 0,
  49. },
  50. '0.9': {
  51. scale: 1.3,
  52. translateY: 7,
  53. },
  54. '1': {
  55. scale: 1.2,
  56. translateY: 6,
  57. },
  58. },
  59. focusOut: {
  60. '0': {
  61. scale: 1.2,
  62. translateY: 6,
  63. },
  64. '1': {
  65. scale: 1,
  66. translateY: 0,
  67. },
  68. },
  69. });
  70. this.firstRender = true;
  71. }
  72. componentDidMount() {
  73. this.firstRender = false;
  74. }
  75. shouldComponentUpdate(nextProps: PropsType): boolean {
  76. const {props} = this;
  77. return (
  78. nextProps.focused !== props.focused ||
  79. nextProps.theme.dark !== props.theme.dark ||
  80. nextProps.extraData !== props.extraData
  81. );
  82. }
  83. render(): React.Node {
  84. const {props} = this;
  85. return (
  86. <TouchableRipple
  87. onPress={props.onPress}
  88. onLongPress={props.onLongPress}
  89. borderless
  90. rippleColor={props.theme.colors.primary}
  91. style={{
  92. flex: 1,
  93. justifyContent: 'center',
  94. }}>
  95. <View>
  96. <Animatable.View
  97. duration={200}
  98. easing="ease-out"
  99. animation={props.focused ? 'focusIn' : 'focusOut'}
  100. useNativeDriver>
  101. <MaterialCommunityIcons
  102. name={props.icon}
  103. color={props.color}
  104. size={26}
  105. style={{
  106. marginLeft: 'auto',
  107. marginRight: 'auto',
  108. }}
  109. />
  110. </Animatable.View>
  111. <Animatable.Text
  112. animation={props.focused ? 'fadeOutDown' : 'fadeIn'}
  113. useNativeDriver
  114. style={{
  115. color: props.color,
  116. marginLeft: 'auto',
  117. marginRight: 'auto',
  118. fontSize: 10,
  119. }}>
  120. {props.label}
  121. </Animatable.Text>
  122. </View>
  123. </TouchableRipple>
  124. );
  125. }
  126. }
  127. export default withTheme(TabIcon);