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.

CollapsibleComponent.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 {Collapsible} from 'react-navigation-collapsible';
  22. import withCollapsible from '../../utils/withCollapsible';
  23. import CustomTabBar from '../Tabbar/CustomTabBar';
  24. export type CollapsibleComponentPropsType = {
  25. children?: React.Node,
  26. hasTab?: boolean,
  27. onScroll?: (event: SyntheticEvent<EventTarget>) => void,
  28. };
  29. type PropsType = {
  30. ...CollapsibleComponentPropsType,
  31. collapsibleStack: Collapsible,
  32. // eslint-disable-next-line flowtype/no-weak-types
  33. component: any,
  34. };
  35. class CollapsibleComponent extends React.Component<PropsType> {
  36. static defaultProps = {
  37. children: null,
  38. hasTab: false,
  39. onScroll: null,
  40. };
  41. onScroll = (event: SyntheticEvent<EventTarget>) => {
  42. const {props} = this;
  43. if (props.onScroll) props.onScroll(event);
  44. };
  45. render(): React.Node {
  46. const {props} = this;
  47. const Comp = props.component;
  48. const {
  49. containerPaddingTop,
  50. scrollIndicatorInsetTop,
  51. onScrollWithListener,
  52. } = props.collapsibleStack;
  53. return (
  54. <Comp
  55. // eslint-disable-next-line react/jsx-props-no-spreading
  56. {...props}
  57. onScroll={onScrollWithListener(this.onScroll)}
  58. contentContainerStyle={{
  59. paddingTop: containerPaddingTop,
  60. paddingBottom: props.hasTab ? CustomTabBar.TAB_BAR_HEIGHT : 0,
  61. minHeight: '100%',
  62. }}
  63. scrollIndicatorInsets={{top: scrollIndicatorInsetTop}}>
  64. {props.children}
  65. </Comp>
  66. );
  67. }
  68. }
  69. export default withCollapsible(CollapsibleComponent);