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.

CollapsibleUtils.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. * @param headerColor The color of the header. Uses default color if not specified
  20. * @returns {JSX.Element}
  21. */
  22. export function createScreenCollapsibleStack(
  23. name: string,
  24. Stack: StackNavigator,
  25. component: React.ComponentType<any>,
  26. title: string,
  27. useNativeDriver?: boolean,
  28. options?: StackNavigationOptions,
  29. headerColor?: string) {
  30. const {colors} = useTheme();
  31. const screenOptions = options != null ? options : {};
  32. return createCollapsibleStack(
  33. <Stack.Screen
  34. name={name}
  35. component={component}
  36. options={{
  37. title: title,
  38. headerStyle: {
  39. backgroundColor: headerColor!=null ? headerColor :colors.surface,
  40. },
  41. ...screenOptions,
  42. }}
  43. />,
  44. {
  45. collapsedColor: headerColor!=null ? headerColor :colors.surface,
  46. useNativeDriver: useNativeDriver != null ? useNativeDriver : true, // native driver does not work with webview
  47. }
  48. )
  49. }
  50. /**
  51. * Creates a navigation stack with the collapsible library, allowing the header to collapse on scroll.
  52. *
  53. * This is a preset for screens using a webview as their main component, as it uses special parameters to work.
  54. * (aka a dirty workaround)
  55. *
  56. * @param name
  57. * @param Stack
  58. * @param component
  59. * @param title
  60. * @returns {JSX.Element}
  61. */
  62. export function getWebsiteStack(name: string, Stack: any, component: any, title: string) {
  63. return createScreenCollapsibleStack(name, Stack, component, title, false);
  64. }