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.6KB

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