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.

AnimatedFAB.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 {StyleSheet} from 'react-native';
  22. import {FAB} from 'react-native-paper';
  23. import * as Animatable from 'react-native-animatable';
  24. import AutoHideHandler from '../../utils/AutoHideHandler';
  25. import CustomTabBar from '../Tabbar/CustomTabBar';
  26. type PropsType = {
  27. icon: string,
  28. onPress: () => void,
  29. };
  30. const AnimatedFab = Animatable.createAnimatableComponent(FAB);
  31. const styles = StyleSheet.create({
  32. fab: {
  33. position: 'absolute',
  34. margin: 16,
  35. right: 0,
  36. },
  37. });
  38. export default class AnimatedFAB extends React.Component<PropsType> {
  39. ref: {current: null | Animatable.View};
  40. hideHandler: AutoHideHandler;
  41. constructor() {
  42. super();
  43. this.ref = React.createRef();
  44. this.hideHandler = new AutoHideHandler(false);
  45. this.hideHandler.addListener(this.onHideChange);
  46. }
  47. onScroll = (event: SyntheticEvent<EventTarget>) => {
  48. this.hideHandler.onScroll(event);
  49. };
  50. onHideChange = (shouldHide: boolean) => {
  51. if (this.ref.current != null) {
  52. if (shouldHide) this.ref.current.bounceOutDown(1000);
  53. else this.ref.current.bounceInUp(1000);
  54. }
  55. };
  56. render(): React.Node {
  57. const {props} = this;
  58. return (
  59. <AnimatedFab
  60. ref={this.ref}
  61. useNativeDriver
  62. icon={props.icon}
  63. onPress={props.onPress}
  64. style={{
  65. ...styles.fab,
  66. bottom: CustomTabBar.TAB_BAR_HEIGHT,
  67. }}
  68. />
  69. );
  70. }
  71. }