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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import React from 'react';
  2. import { View, StyleSheet, Image } from 'react-native';
  3. import { FAB } from 'react-native-paper';
  4. import * as Animatable from 'react-native-animatable';
  5. import { useNavigation } from '@react-navigation/core';
  6. import { MainRoutes } from '../../navigation/MainNavigator';
  7. interface Props {
  8. icon: string;
  9. focusedIcon: string;
  10. focused: boolean;
  11. onPress: () => void;
  12. }
  13. Animatable.initializeRegistryWithDefinitions({
  14. fabFocusIn: {
  15. 0: {
  16. // @ts-ignore
  17. scale: 1,
  18. translateY: 0,
  19. },
  20. 0.4: {
  21. // @ts-ignore
  22. scale: 1.2,
  23. translateY: -9,
  24. },
  25. 0.6: {
  26. // @ts-ignore
  27. scale: 1.05,
  28. translateY: -6,
  29. },
  30. 0.8: {
  31. // @ts-ignore
  32. scale: 1.15,
  33. translateY: -6,
  34. },
  35. 1: {
  36. // @ts-ignore
  37. scale: 1.1,
  38. translateY: -6,
  39. },
  40. },
  41. fabFocusOut: {
  42. 0: {
  43. // @ts-ignore
  44. scale: 1.1,
  45. translateY: -6,
  46. },
  47. 1: {
  48. // @ts-ignore
  49. scale: 1,
  50. translateY: 0,
  51. },
  52. },
  53. });
  54. const styles = StyleSheet.create({
  55. outer: {
  56. flex: 1,
  57. justifyContent: 'center',
  58. },
  59. inner: {
  60. position: 'absolute',
  61. bottom: 0,
  62. left: 0,
  63. width: '100%',
  64. height: 60,
  65. },
  66. fab: {
  67. marginLeft: 'auto',
  68. marginRight: 'auto',
  69. },
  70. });
  71. const FOCUSED_ICON = require('../../../assets/tab-icon.png');
  72. const UNFOCUSED_ICON = require('../../../assets/tab-icon-outline.png');
  73. function TabHomeIcon(props: Props) {
  74. const navigation = useNavigation();
  75. const getImage = (iconProps: { size: number; color: string }) => {
  76. return (
  77. <Animatable.View useNativeDriver={true} animation={'rubberBand'}>
  78. <Image
  79. source={props.focused ? FOCUSED_ICON : UNFOCUSED_ICON}
  80. style={{
  81. width: iconProps.size,
  82. height: iconProps.size,
  83. tintColor: iconProps.color,
  84. }}
  85. />
  86. </Animatable.View>
  87. );
  88. };
  89. return (
  90. <View style={styles.outer}>
  91. <View style={styles.inner}>
  92. <Animatable.View
  93. style={styles.fab}
  94. useNativeDriver={true}
  95. duration={props.focused ? 500 : 200}
  96. animation={props.focused ? 'fabFocusIn' : 'fabFocusOut'}
  97. easing={'ease-out'}
  98. >
  99. <FAB
  100. onPress={props.onPress}
  101. onLongPress={() => navigation.navigate(MainRoutes.GameStart)}
  102. animated={false}
  103. icon={getImage}
  104. color={'#fff'}
  105. />
  106. </Animatable.View>
  107. </View>
  108. </View>
  109. );
  110. }
  111. export default TabHomeIcon;