Application Android et IOS pour l'amicale des élèves
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 2.9KB

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