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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 { useCollapsibleStack } from 'react-navigation-collapsible';
  21. import CustomTabBar from '../Tabbar/CustomTabBar';
  22. import {
  23. NativeScrollEvent,
  24. NativeSyntheticEvent,
  25. StyleSheet,
  26. } from 'react-native';
  27. export type CollapsibleComponentPropsType = {
  28. children?: React.ReactNode;
  29. hasTab?: boolean;
  30. onScroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
  31. };
  32. type PropsType = CollapsibleComponentPropsType & {
  33. component: React.ComponentType<any>;
  34. };
  35. const styles = StyleSheet.create({
  36. main: {
  37. minHeight: '100%',
  38. },
  39. });
  40. function CollapsibleComponent(props: PropsType) {
  41. const onScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
  42. if (props.onScroll) {
  43. props.onScroll(event);
  44. }
  45. };
  46. const Comp = props.component;
  47. const {
  48. containerPaddingTop,
  49. scrollIndicatorInsetTop,
  50. onScrollWithListener,
  51. } = useCollapsibleStack();
  52. const paddingBottom = props.hasTab ? CustomTabBar.TAB_BAR_HEIGHT : 0;
  53. return (
  54. <Comp
  55. {...props}
  56. onScroll={onScrollWithListener(onScroll)}
  57. contentContainerStyle={{
  58. paddingTop: containerPaddingTop,
  59. paddingBottom: paddingBottom,
  60. ...styles.main,
  61. }}
  62. scrollIndicatorInsets={{ top: scrollIndicatorInsetTop }}
  63. >
  64. {props.children}
  65. </Comp>
  66. );
  67. }
  68. export default CollapsibleComponent;