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.

CollapsibleUtils.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // @flow
  2. import * as React from 'react';
  3. import {useTheme} from "react-native-paper";
  4. import {createCollapsibleStack} from "react-navigation-collapsible";
  5. import StackNavigator, {StackNavigationOptions} from "@react-navigation/stack";
  6. /**
  7. * Creates a navigation stack with the collapsible library, allowing the header to collapse on scroll.
  8. *
  9. * Please use the getWebsiteStack function if your screen uses a webview as their main component as it needs special parameters.
  10. *
  11. * @param name The screen name in the navigation stack
  12. * @param Stack The stack component
  13. * @param component The screen component
  14. * @param title The screen title shown in the header (needs to be translated)
  15. * @param useNativeDriver Whether to use the native driver for animations.
  16. * Set to false if the screen uses a webview as this component does not support native driver.
  17. * In all other cases, set it to true for increase performance.
  18. * @param options Screen options to use, or null if no options are necessary.
  19. * @returns {JSX.Element}
  20. */
  21. export function createScreenCollapsibleStack(
  22. name: string,
  23. Stack: StackNavigator,
  24. component: React.Node,
  25. title: string,
  26. useNativeDriver?: boolean,
  27. options?: StackNavigationOptions) {
  28. const {colors} = useTheme();
  29. const screenOptions = options != null ? options : {};
  30. return createCollapsibleStack(
  31. <Stack.Screen
  32. name={name}
  33. component={component}
  34. options={{
  35. title: title,
  36. headerStyle: {
  37. backgroundColor: colors.surface,
  38. },
  39. ...screenOptions,
  40. }}
  41. />,
  42. {
  43. collapsedColor: colors.surface,
  44. useNativeDriver: useNativeDriver != null ? useNativeDriver : true, // native driver does not work with webview
  45. }
  46. )
  47. }
  48. /**
  49. * Creates a navigation stack with the collapsible library, allowing the header to collapse on scroll.
  50. *
  51. * This is a preset for screens using a webview as their main component, as it uses special parameters to work.
  52. * (aka a dirty workaround)
  53. *
  54. * @param name
  55. * @param Stack
  56. * @param component
  57. * @param title
  58. * @returns {JSX.Element}
  59. */
  60. export function getWebsiteStack(name: string, Stack: any, component: any, title: string) {
  61. return createScreenCollapsibleStack(name, Stack, component, title, false);
  62. }