diff --git a/apps/src/tests/single-feature-tests/stack-v5/index.ts b/apps/src/tests/single-feature-tests/stack-v5/index.ts index 6321f45e2b..c0ae244de4 100644 --- a/apps/src/tests/single-feature-tests/stack-v5/index.ts +++ b/apps/src/tests/single-feature-tests/stack-v5/index.ts @@ -5,6 +5,7 @@ import AnimationAndroid from './test-animation-android'; import TestStackSimpleNav from './test-stack-simple-nav'; import TestStackSubviewsAndroid from './test-stack-subviews-android'; import TestStackSubviewsIOS from './test-stack-subviews-ios'; +import TestStackHeaderMenuIOS from './test-stack-header-menu-ios'; import TestStackBackButton from './test-stack-back-button-android'; import TestStackToolbarMenuCommands from './test-stack-toolbar-menu-commands-android'; import TestStackToolbarMenuShowAsAction from './test-stack-toolbar-menu-show-as-action-android'; @@ -16,6 +17,7 @@ const scenarios = { TestStackSimpleNav, TestStackSubviewsAndroid, TestStackSubviewsIOS, + TestStackHeaderMenuIOS, TestStackBackButton, TestStackToolbarMenuCommands, TestStackToolbarMenuShowAsAction, diff --git a/apps/src/tests/single-feature-tests/stack-v5/test-stack-header-menu-ios/index.tsx b/apps/src/tests/single-feature-tests/stack-v5/test-stack-header-menu-ios/index.tsx new file mode 100644 index 0000000000..e0f53f1abb --- /dev/null +++ b/apps/src/tests/single-feature-tests/stack-v5/test-stack-header-menu-ios/index.tsx @@ -0,0 +1,98 @@ +import React, { useEffect, useMemo, useState } from 'react'; +import { createScenario } from '@apps/tests/shared/helpers'; +import { + StackContainer, + useStackNavigationContext, +} from '@apps/shared/gamma/containers/stack'; +import { StackHeaderConfigProps } from 'react-native-screens/components/gamma/stack/header'; +import { Button, ScrollView } from 'react-native'; +import LongText from '@apps/shared/LongText'; +import { scenarioDescription } from './scenario-description'; +import PressableWithFeedback from '@apps/shared/PressableWithFeedback'; + +const DEFAULT_TRAILING_ITEMS_COUNT = 2; + +export function App() { + return ( + + ); +} + +function buildHeaderConfig(trailingItemsCount: number): StackHeaderConfigProps { + const trailingItems: NonNullable< + StackHeaderConfigProps['ios'] + >['trailingItems'] = Array.from({ length: trailingItemsCount }).map( + (_, i) => ({ + type: 'item', + key: `trailing-${i}`, + label: `Menu ${i}`, + // every second item is custom + ...(i % 2 === 0 && { + render: () => ( + + ), + }), + menu: { + type: 'menu', + children: [ + { type: 'menuItem', title: `Item ${i}.1` }, + { type: 'menuItem', title: `Item ${i}.2` }, + { + type: 'menu', + title: `Submenu ${i}`, + children: [ + { type: 'menuItem', title: `Nested ${i}.1` }, + { type: 'menuItem', title: `Nested ${i}.2` }, + ], + }, + ], + }, + }), + ); + + return { + title: 'Header Menu', + ios: { + trailingItems, + }, + }; +} + +function ConfigScreen() { + const navigation = useStackNavigationContext(); + const [trailingItemsCount, setTrailingItemsCount] = useState( + DEFAULT_TRAILING_ITEMS_COUNT, + ); + + const { setRouteOptions, routeKey } = navigation; + const headerConfig = useMemo( + () => buildHeaderConfig(trailingItemsCount), + [trailingItemsCount], + ); + + useEffect(() => { + setRouteOptions(routeKey, { + headerConfig, + }); + }, [headerConfig, setRouteOptions, routeKey]); + + return ( + +