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.

TabHomeIcon.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. theme: CustomThemeType,
  32. tabBarHeight: number,
  33. };
  34. const AnimatedFAB = Animatable.createAnimatableComponent(FAB);
  35. /**
  36. * Abstraction layer for Agenda component, using custom configuration
  37. */
  38. class TabHomeIcon extends React.Component<PropsType> {
  39. constructor(props: PropsType) {
  40. super(props);
  41. Animatable.initializeRegistryWithDefinitions({
  42. fabFocusIn: {
  43. '0': {
  44. scale: 1,
  45. translateY: 0,
  46. },
  47. '0.9': {
  48. scale: 1.2,
  49. translateY: -9,
  50. },
  51. '1': {
  52. scale: 1.1,
  53. translateY: -7,
  54. },
  55. },
  56. fabFocusOut: {
  57. '0': {
  58. scale: 1.1,
  59. translateY: -6,
  60. },
  61. '1': {
  62. scale: 1,
  63. translateY: 0,
  64. },
  65. },
  66. });
  67. }
  68. shouldComponentUpdate(nextProps: PropsType): boolean {
  69. const {focused} = this.props;
  70. return nextProps.focused !== focused;
  71. }
  72. getIconRender = ({
  73. size,
  74. color,
  75. }: {
  76. size: number,
  77. color: string,
  78. }): React.Node => {
  79. const {focused} = this.props;
  80. if (focused)
  81. return (
  82. <Image
  83. source={FOCUSED_ICON}
  84. style={{
  85. width: size,
  86. height: size,
  87. tintColor: color,
  88. }}
  89. />
  90. );
  91. return (
  92. <Image
  93. source={UNFOCUSED_ICON}
  94. style={{
  95. width: size,
  96. height: size,
  97. tintColor: color,
  98. }}
  99. />
  100. );
  101. };
  102. render(): React.Node {
  103. const {props} = this;
  104. return (
  105. <View
  106. style={{
  107. flex: 1,
  108. justifyContent: 'center',
  109. }}>
  110. <TouchableRipple
  111. onPress={props.onPress}
  112. onLongPress={props.onLongPress}
  113. borderless
  114. rippleColor={
  115. Platform.OS === 'android'
  116. ? props.theme.colors.primary
  117. : 'transparent'
  118. }
  119. style={{
  120. position: 'absolute',
  121. bottom: 0,
  122. left: 0,
  123. width: '100%',
  124. height: props.tabBarHeight + 30,
  125. marginBottom: -15,
  126. }}>
  127. <AnimatedFAB
  128. duration={200}
  129. easing="ease-out"
  130. animation={props.focused ? 'fabFocusIn' : 'fabFocusOut'}
  131. icon={this.getIconRender}
  132. style={{
  133. marginTop: 15,
  134. marginLeft: 'auto',
  135. marginRight: 'auto',
  136. }}
  137. />
  138. </TouchableRipple>
  139. </View>
  140. );
  141. }
  142. }
  143. export default withTheme(TabHomeIcon);