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.

TabHomeIcon.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 {Image, Platform, View} from 'react-native';
  22. import {FAB, TouchableRipple, withTheme} from 'react-native-paper';
  23. import * as Animatable from 'react-native-animatable';
  24. import FOCUSED_ICON from '../../../assets/tab-icon.png';
  25. import UNFOCUSED_ICON from '../../../assets/tab-icon-outline.png';
  26. import type {CustomThemeType} from '../../managers/ThemeManager';
  27. type PropsType = {
  28. focused: boolean,
  29. onPress: () => void,
  30. onLongPress: () => void,
  31. tabBarHeight: number,
  32. };
  33. const AnimatedFAB = Animatable.createAnimatableComponent(FAB);
  34. /**
  35. * Abstraction layer for Agenda component, using custom configuration
  36. */
  37. class TabHomeIcon extends React.Component<PropsType> {
  38. constructor(props: PropsType) {
  39. super(props);
  40. Animatable.initializeRegistryWithDefinitions({
  41. fabFocusIn: {
  42. '0': {
  43. scale: 1,
  44. translateY: 0,
  45. },
  46. '0.9': {
  47. scale: 1.2,
  48. translateY: -9,
  49. },
  50. '1': {
  51. scale: 1.1,
  52. translateY: -7,
  53. },
  54. },
  55. fabFocusOut: {
  56. '0': {
  57. scale: 1.1,
  58. translateY: -6,
  59. },
  60. '1': {
  61. scale: 1,
  62. translateY: 0,
  63. },
  64. },
  65. });
  66. }
  67. shouldComponentUpdate(nextProps: PropsType): boolean {
  68. const {focused} = this.props;
  69. return nextProps.focused !== focused;
  70. }
  71. getIconRender = ({
  72. size,
  73. color,
  74. }: {
  75. size: number,
  76. color: string,
  77. }): React.Node => {
  78. const {focused} = this.props;
  79. return (
  80. <Image
  81. source={focused ? FOCUSED_ICON : UNFOCUSED_ICON}
  82. style={{
  83. width: size,
  84. height: size,
  85. tintColor: color,
  86. }}
  87. />
  88. );
  89. };
  90. render(): React.Node {
  91. const {props} = this;
  92. return (
  93. <View
  94. style={{
  95. flex: 1,
  96. justifyContent: 'center',
  97. }}>
  98. <View
  99. style={{
  100. position: 'absolute',
  101. bottom: 0,
  102. left: 0,
  103. width: '100%',
  104. height: props.tabBarHeight + 30,
  105. marginBottom: -15,
  106. }}>
  107. <AnimatedFAB
  108. duration={200}
  109. easing="ease-out"
  110. animation={props.focused ? 'fabFocusIn' : 'fabFocusOut'}
  111. icon={this.getIconRender}
  112. onPress={props.onPress}
  113. onLongPress={props.onLongPress}
  114. style={{
  115. marginTop: 15,
  116. marginLeft: 'auto',
  117. marginRight: 'auto',
  118. }}
  119. />
  120. </View>
  121. </View>
  122. );
  123. }
  124. }
  125. export default TabHomeIcon;