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

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