diff --git a/FabricExample/e2e/component-integration-tests/tabs-stack-v4/test-tabs-search-tab-activation-ios.e2e.ts b/FabricExample/e2e/component-integration-tests/tabs-stack-v4/test-tabs-search-tab-activation-ios.e2e.ts new file mode 100644 index 0000000000..217cf7755c --- /dev/null +++ b/FabricExample/e2e/component-integration-tests/tabs-stack-v4/test-tabs-search-tab-activation-ios.e2e.ts @@ -0,0 +1,66 @@ +import { device, expect, element, by } from 'detox'; +import type { IosElementAttributes } from 'detox/detox'; +import { selectComponentIntegrationTestsScreen } from '@e2e/app/test-screen-navigation'; +import { toggleSettingsSwitch } from '@e2e/app/settings-controls'; +import { tapWithinFrame } from '@e2e/framework/gestures'; +import { getMatches } from '@e2e/framework/matchers'; +import { CLASS_NAME_UI_TAB_BAR_BUTTON_IOS26 } from '@e2e/framework/native-classes-ios'; +import { isIOSVersionAtLeast } from '@e2e/framework/platform'; + +// `UISearchTab` (and with it search activation and the collapsed tab bar) is +// used only on the `UITab` API path, enabled from iOS 26.1. +const describeIfUISearchTab = isIOSVersionAtLeast('26.1') + ? describe + : describe.skip; + +// Once the search tab has been activated, UIKit lets a mount transaction run +// between `shouldSelectTab:` and `didSelectTab:` on every later selection of +// it (observed on iOS 27), so a single round trip is not enough. +const SELECTION_ROUNDS = 5; + +/** + * With the search active, UIKit shows the other tabs as a single collapsed + * button. It has no `testID` (the regular, hidden button keeps it) and is + * told apart by its accessibility value. + */ +async function tapCollapsedTabButton(label: string) { + const buttons = (await getMatches( + by.label(label).and(by.type(CLASS_NAME_UI_TAB_BAR_BUTTON_IOS26)), + )) as IosElementAttributes[]; + const collapsedButton = buttons.find(button => button.value === 'Collapsed'); + if (collapsedButton === undefined) { + throw new Error(`No collapsed tab button labeled "${label}"`); + } + await tapWithinFrame(collapsedButton.frame); +} + +describeIfUISearchTab('Stack v4 & Tabs: search tab activation', () => { + beforeAll(async () => { + await device.reloadReactNative(); + await selectComponentIntegrationTestsScreen( + 'Stack V4 & Native Tabs Integration Tests', + 'test-tabs-search-tab-activation-ios', + ); + }); + + it('should keep the JS selection in sync when returning through the collapsed tab bar', async () => { + await toggleSettingsSwitch({ + switchId: 'automatically-activates-search-switch', + label: 'automaticallyActivatesSearch', + to: true, + }); + + for (let round = 0; round < SELECTION_ROUNDS; round++) { + await element(by.id('search-tab-item')).tap(); + await expect( + element(by.id('search-list-selected-in-js-label')), + ).toHaveLabel('Selected in JS: yes'); + + // The activated search field brings up the keyboard, which covers the + // collapsed tab bar. + await element(by.id('search-list-scrollview')).swipe('down', 'slow', 0.3); + await tapCollapsedTabButton('Config'); + await expect(element(by.text('Search Tab Activation'))).toBeVisible(); + } + }); +}); diff --git a/FabricExample/e2e/single-feature-tests/tabs/test-tabs-navigation-state-search-tab.e2e.ts b/FabricExample/e2e/single-feature-tests/tabs/test-tabs-navigation-state-search-tab.e2e.ts new file mode 100644 index 0000000000..4b987aada3 --- /dev/null +++ b/FabricExample/e2e/single-feature-tests/tabs/test-tabs-navigation-state-search-tab.e2e.ts @@ -0,0 +1,70 @@ +import { device, expect, element, by } from 'detox'; +import { selectSingleFeatureTestsScreen } from '@e2e/app/test-screen-navigation'; +import { describeIfIOS } from '@e2e/framework/platform'; + +type Route = 'Home' | 'Search'; +type ActionOrigin = 'user' | 'programmatic-js'; + +// Several round trips - a selection dropped or reported twice on any of them +// shows up as a provenance mismatch. +const SELECTION_ROUNDS = 5; + +async function expectSelection( + route: Route, + actionOrigin: ActionOrigin, + provenance: number, +) { + await expect(element(by.id(`${route}-selected-in-js-label`))).toHaveLabel( + 'Selected in JS: yes', + ); + await expect(element(by.id(`${route}-last-selection-label`))).toHaveLabel( + `Last selection: ${route} (${actionOrigin}), provenance: ${provenance}`, + ); +} + +describeIfIOS('Tabs: navigation state on search tab interactions', () => { + // Every selection advances the provenance by exactly one - a dropped + // selection leaves it behind, a duplicated one skips a value. + let provenance = 0; + + beforeAll(async () => { + await device.reloadReactNative(); + await selectSingleFeatureTestsScreen( + 'Tabs', + 'test-tabs-navigation-state-search-tab', + ); + }); + + it('should start with the Home tab selected', async () => { + await expectSelection('Home', 'programmatic-js', provenance); + }); + + it('should progress the state on every user selection of the search tab', async () => { + for (let round = 0; round < SELECTION_ROUNDS; round++) { + await element(by.id('search-tab-item')).tap(); + await expectSelection('Search', 'user', ++provenance); + + await element(by.id('home-tab-item')).tap(); + await expectSelection('Home', 'user', ++provenance); + } + }); + + it('should progress the state once on programmatic selection of the search tab', async () => { + await element(by.id('Home-select-search')).tap(); + await expectSelection('Search', 'programmatic-js', ++provenance); + + await element(by.id('Search-select-home')).tap(); + await expectSelection('Home', 'programmatic-js', ++provenance); + }); + + it('should progress the state on user selection after programmatic one', async () => { + await element(by.id('Home-select-search')).tap(); + await expectSelection('Search', 'programmatic-js', ++provenance); + + await element(by.id('home-tab-item')).tap(); + await expectSelection('Home', 'user', ++provenance); + + await element(by.id('search-tab-item')).tap(); + await expectSelection('Search', 'user', ++provenance); + }); +}); diff --git a/android/src/main/java/com/swmansion/rnscreens/legacy/ScreenViewManager.kt b/android/src/main/java/com/swmansion/rnscreens/legacy/ScreenViewManager.kt index edbe695f23..fd47f1fb78 100644 --- a/android/src/main/java/com/swmansion/rnscreens/legacy/ScreenViewManager.kt +++ b/android/src/main/java/com/swmansion/rnscreens/legacy/ScreenViewManager.kt @@ -328,6 +328,11 @@ open class ScreenViewManager : value: Boolean, ) = Unit + override fun setSheetPrefersHorizontalBars( + view: Screen?, + value: Boolean, + ) = Unit + // END mark: iOS-only override fun setAndroidResetScreenShadowStateOnOrientationChangeEnabled( diff --git a/android/src/main/java/com/swmansion/rnscreens/react/modals/formsheet/host/FormSheetHostViewManager.kt b/android/src/main/java/com/swmansion/rnscreens/react/modals/formsheet/host/FormSheetHostViewManager.kt index 3f7c253c91..14cc616258 100644 --- a/android/src/main/java/com/swmansion/rnscreens/react/modals/formsheet/host/FormSheetHostViewManager.kt +++ b/android/src/main/java/com/swmansion/rnscreens/react/modals/formsheet/host/FormSheetHostViewManager.kt @@ -91,6 +91,11 @@ class FormSheetHostViewManager : view.prefersGrabberVisible = value } + override fun setPrefersHorizontalBars( + view: FormSheetHost, + value: Boolean, + ) = Unit // iOS-only bar placement preference. + override fun setPreferredCornerRadius( view: FormSheetHost, value: Float, diff --git a/apps/src/tests/component-integration-tests/tabs-stack-v4/test-tabs-search-tab-activation-ios/index.tsx b/apps/src/tests/component-integration-tests/tabs-stack-v4/test-tabs-search-tab-activation-ios/index.tsx index 405ac46b20..fbab50dbde 100644 --- a/apps/src/tests/component-integration-tests/tabs-stack-v4/test-tabs-search-tab-activation-ios/index.tsx +++ b/apps/src/tests/component-integration-tests/tabs-stack-v4/test-tabs-search-tab-activation-ios/index.tsx @@ -73,6 +73,8 @@ function SearchListScreen({ }) { const [search, setSearch] = useState(''); const { hideNavigationBar } = useContext(HideNavigationBarContext); + // JS-side selection state - must follow UIKit after every user selection. + const { isSelected } = useTabsNavigationContext(); useLayoutEffect(() => { navigation.setOptions({ @@ -86,8 +88,12 @@ function SearchListScreen({ return ( + + Selected in JS: {isSelected ? 'yes' : 'no'} + {PLACES.filter( item => item.toLowerCase().indexOf(search.toLowerCase()) !== -1, ).map(place => ( @@ -182,6 +188,7 @@ function ConfigTab() { Search Tab Activation was mutated while being enumerated". +// +// `updateHeaderStateInShadowTreeInContextOfNavigationBar:` loops over `reactSubviews`. +// A header item that was just mounted sends its frame to the shadow tree synchronously, +// and that can mount the next pending commit. Here the left and right items toggle at +// different rates, so that commit adds or removes a header subview during the loop. +// Fast enumeration only notices it when it moves on to the next element, so the title +// is placed after the right item. + +function HeaderItem() { + return ; +} + +export default function App() { + const [running, setRunning] = useState(false); + const [tick, setTick] = useState(0); + + useEffect(() => { + if (!running) { + return; + } + let timer: ReturnType; + const loop = () => { + setTick(t => t + 1); + timer = setTimeout(loop, 0); + }; + loop(); + return () => clearTimeout(timer); + }, [running]); + + return ( + + + {tick % 2 === 0 && ( + + + + )} + {tick % 3 !== 0 && ( + + + + )} + + + + + ), + }}> + +