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 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // @flow
  2. import * as React from 'react';
  3. import {StyleSheet} from "react-native";
  4. import {FAB} from "react-native-paper";
  5. import AutoHideHandler from "../../utils/AutoHideHandler";
  6. import * as Animatable from 'react-native-animatable';
  7. import CustomTabBar from "../Tabbar/CustomTabBar";
  8. type Props = {
  9. navigation: Object,
  10. icon: string,
  11. onPress: Function,
  12. }
  13. const AnimatedFab = Animatable.createAnimatableComponent(FAB);
  14. export default class AnimatedFAB extends React.Component<Props> {
  15. ref: Object;
  16. hideHandler: AutoHideHandler;
  17. constructor() {
  18. super();
  19. this.ref = React.createRef();
  20. this.hideHandler = new AutoHideHandler(false);
  21. this.hideHandler.addListener(this.onHideChange);
  22. }
  23. onScroll = (event: Object) => {
  24. this.hideHandler.onScroll(event);
  25. };
  26. onHideChange = (shouldHide: boolean) => {
  27. if (this.ref.current) {
  28. if (shouldHide)
  29. this.ref.current.bounceOutDown(1000);
  30. else
  31. this.ref.current.bounceInUp(1000);
  32. }
  33. }
  34. render() {
  35. return (
  36. <AnimatedFab
  37. ref={this.ref}
  38. useNativeDriver
  39. icon={this.props.icon}
  40. onPress={this.props.onPress}
  41. style={{
  42. ...styles.fab,
  43. bottom: CustomTabBar.TAB_BAR_HEIGHT
  44. }}
  45. />
  46. );
  47. }
  48. }
  49. const styles = StyleSheet.create({
  50. fab: {
  51. position: 'absolute',
  52. margin: 16,
  53. right: 0,
  54. },
  55. });