From 3096fe0e2b8e7cfe78d09d3566e5ce8ece367032 Mon Sep 17 00:00:00 2001 From: Pixel Perfect Date: Fri, 16 Oct 2026 17:32:43 -0700 Subject: [PATCH 01/18] fix(ios): use horizontal bars in sheets on iPhone Duo --- ios/legacy/RNSScreen.mm | 15 +++++++++++++++ .../form-sheet/RNSFormSheetContentController.mm | 9 +++++++++ package.json | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ios/legacy/RNSScreen.mm b/ios/legacy/RNSScreen.mm index 67ceb528c8..b96250019e 100644 --- a/ios/legacy/RNSScreen.mm +++ b/ios/legacy/RNSScreen.mm @@ -1450,6 +1450,21 @@ @implementation RNSScreen { #pragma mark - Common +#if RNS_IPHONE_OS_VERSION_AVAILABLE(27_1) && !TARGET_OS_TV && !TARGET_OS_VISION +// Navigation sheets use horizontal bars, matching the standalone FormSheet. +- (UIVerticalBarBehavior)preferredVerticalBarBehavior API_AVAILABLE(ios(27.1)) +{ + switch (self.screenView.stackPresentation) { + case RNSScreenStackPresentationModal: + case RNSScreenStackPresentationPageSheet: + case RNSScreenStackPresentationFormSheet: + return UIVerticalBarBehaviorDisabled; + default: + return [super preferredVerticalBarBehavior]; + } +} +#endif + - (instancetype)initWithView:(UIView *)view { if (self = [super init]) { diff --git a/ios/modals/form-sheet/RNSFormSheetContentController.mm b/ios/modals/form-sheet/RNSFormSheetContentController.mm index a6e34d25b4..8c90a0e368 100644 --- a/ios/modals/form-sheet/RNSFormSheetContentController.mm +++ b/ios/modals/form-sheet/RNSFormSheetContentController.mm @@ -5,6 +5,7 @@ #import "RNSFormSheetUpdateCoordinator.h" #import "RNSFormSheetUpdateFlags.h" #import "RNSPresentationSourceProvider.h" +#import "RNSDefines.h" #import #import @@ -43,6 +44,14 @@ - (RNSFormSheetContentView *)contentView return static_cast(self.view); } +#if RNS_IPHONE_OS_VERSION_AVAILABLE(27_1) && !TARGET_OS_TV && !TARGET_OS_VISION +// Short sheets should not reserve an empty control rail on iPhone Duo. +- (UIVerticalBarBehavior)preferredVerticalBarBehavior API_AVAILABLE(ios(27.1)) +{ + return UIVerticalBarBehaviorDisabled; +} +#endif + #pragma mark - UIKit callbacks - (void)loadView diff --git a/package.json b/package.json index 4783005d26..c5b2b267a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-screens", - "version": "5.0.0-t3.27", + "version": "5.0.0-t3.28", "description": "Native navigation primitives for your React Native app.", "scripts": { "submodules": "git submodule update --init --recursive && (cd react-navigation && yarn && yarn build && cd ../)", From f0d4b311e088f41cd74d7970017769f49f14e6cc Mon Sep 17 00:00:00 2001 From: Pixel Perfect Date: Fri, 16 Oct 2026 18:08:45 -0700 Subject: [PATCH 02/18] fix(ios): make horizontal sheet bars opt-in --- .../swmansion/rnscreens/legacy/ScreenViewManager.kt | 5 +++++ .../formsheet/host/FormSheetHostViewManager.kt | 5 +++++ ios/legacy/RNSScreen.h | 1 + ios/legacy/RNSScreen.mm | 13 ++++++++++++- .../form-sheet/RNSFormSheetContentController.mm | 6 ++++-- .../form-sheet/RNSFormSheetHostComponentView.h | 1 + .../form-sheet/RNSFormSheetHostComponentView.mm | 12 ++++++++++++ ios/modals/form-sheet/RNSFormSheetProviders.h | 1 + package.json | 2 +- src/components/modals/form-sheet/FormSheet.types.ts | 10 ++++++++++ src/fabric/legacy/ModalScreenNativeComponent.ts | 1 + src/fabric/legacy/ScreenNativeComponent.ts | 1 + .../form-sheet/FormSheetHostNativeComponent.ts | 1 + src/legacy/types.ts | 9 +++++++++ 14 files changed, 64 insertions(+), 4 deletions(-) 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/ios/legacy/RNSScreen.h b/ios/legacy/RNSScreen.h index 49ff50b2dd..8398305e92 100644 --- a/ios/legacy/RNSScreen.h +++ b/ios/legacy/RNSScreen.h @@ -117,6 +117,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) NSArray *sheetAllowedDetents; @property (nonatomic) NSNumber *sheetLargestUndimmedDetent; @property (nonatomic) BOOL sheetGrabberVisible; +@property (nonatomic) BOOL sheetPrefersHorizontalBars; @property (nonatomic) CGFloat sheetCornerRadius; @property (nonatomic) NSInteger sheetInitialDetent; @property (nonatomic) BOOL sheetExpandsWhenScrolledToEdge; diff --git a/ios/legacy/RNSScreen.mm b/ios/legacy/RNSScreen.mm index b96250019e..98405fd8ed 100644 --- a/ios/legacy/RNSScreen.mm +++ b/ios/legacy/RNSScreen.mm @@ -100,6 +100,7 @@ - (void)initCommonProps _shouldUpdateScrollEdgeEffects = NO; #if !TARGET_OS_TV _sheetExpandsWhenScrolledToEdge = YES; + _sheetPrefersHorizontalBars = NO; #endif // !TARGET_OS_TV _sheetsScrollView = nil; _sheetsScrollViewTag = 0; @@ -1313,6 +1314,14 @@ - (void)updateProps:(react::Props::Shared const &)props oldProps:(react::Props:: } [self setSheetGrabberVisible:newScreenProps.sheetGrabberVisible]; + if (_sheetPrefersHorizontalBars != newScreenProps.sheetPrefersHorizontalBars) { + _sheetPrefersHorizontalBars = newScreenProps.sheetPrefersHorizontalBars; +#if RNS_IPHONE_OS_VERSION_AVAILABLE(27_1) && !TARGET_OS_VISION + if (@available(iOS 27.1, *)) { + [_controller setNeedsUpdateOfVerticalBarConfiguration]; + } +#endif + } [self setSheetCornerRadius:newScreenProps.sheetCornerRadius]; [self setSheetExpandsWhenScrolledToEdge:newScreenProps.sheetExpandsWhenScrolledToEdge]; @@ -1451,9 +1460,11 @@ @implementation RNSScreen { #pragma mark - Common #if RNS_IPHONE_OS_VERSION_AVAILABLE(27_1) && !TARGET_OS_TV && !TARGET_OS_VISION -// Navigation sheets use horizontal bars, matching the standalone FormSheet. - (UIVerticalBarBehavior)preferredVerticalBarBehavior API_AVAILABLE(ios(27.1)) { + if (!self.screenView.sheetPrefersHorizontalBars) { + return [super preferredVerticalBarBehavior]; + } switch (self.screenView.stackPresentation) { case RNSScreenStackPresentationModal: case RNSScreenStackPresentationPageSheet: diff --git a/ios/modals/form-sheet/RNSFormSheetContentController.mm b/ios/modals/form-sheet/RNSFormSheetContentController.mm index 8c90a0e368..bd78aae7d6 100644 --- a/ios/modals/form-sheet/RNSFormSheetContentController.mm +++ b/ios/modals/form-sheet/RNSFormSheetContentController.mm @@ -45,10 +45,12 @@ - (RNSFormSheetContentView *)contentView } #if RNS_IPHONE_OS_VERSION_AVAILABLE(27_1) && !TARGET_OS_TV && !TARGET_OS_VISION -// Short sheets should not reserve an empty control rail on iPhone Duo. - (UIVerticalBarBehavior)preferredVerticalBarBehavior API_AVAILABLE(ios(27.1)) { - return UIVerticalBarBehaviorDisabled; + if (self.appearanceProvider.prefersHorizontalBars) { + return UIVerticalBarBehaviorDisabled; + } + return [super preferredVerticalBarBehavior]; } #endif diff --git a/ios/modals/form-sheet/RNSFormSheetHostComponentView.h b/ios/modals/form-sheet/RNSFormSheetHostComponentView.h index bc1367191d..9e9beedca5 100644 --- a/ios/modals/form-sheet/RNSFormSheetHostComponentView.h +++ b/ios/modals/form-sheet/RNSFormSheetHostComponentView.h @@ -22,6 +22,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) BOOL isOpen; @property (nonatomic, readonly) BOOL prefersGrabberVisible; +@property (nonatomic, readonly) BOOL prefersHorizontalBars; @property (nonatomic, readonly) CGFloat preferredCornerRadius; @property (nonatomic, readonly) NSInteger largestUndimmedDetentIndex; @property (nonatomic, readonly) NSInteger initialDetentIndex; diff --git a/ios/modals/form-sheet/RNSFormSheetHostComponentView.mm b/ios/modals/form-sheet/RNSFormSheetHostComponentView.mm index e2d0cad04d..bc439a3138 100644 --- a/ios/modals/form-sheet/RNSFormSheetHostComponentView.mm +++ b/ios/modals/form-sheet/RNSFormSheetHostComponentView.mm @@ -1,4 +1,5 @@ #import "RNSFormSheetHostComponentView.h" +#import "RNSDefines.h" #import "RNSFormSheetContentController.h" #import "RNSFormSheetContentView.h" #import "RNSFormSheetContentWrapperComponentView.h" @@ -36,6 +37,7 @@ @implementation RNSFormSheetHostComponentView { BOOL _isOpen; std::vector _detents; BOOL _prefersGrabberVisible; + BOOL _prefersHorizontalBars; CGFloat _preferredCornerRadius; NSInteger _largestUndimmedDetentIndex; NSInteger _initialDetentIndex; @@ -71,6 +73,7 @@ - (void)resetProps _isOpen = NO; _detents = {}; _prefersGrabberVisible = NO; + _prefersHorizontalBars = NO; _preferredCornerRadius = -1.0; _largestUndimmedDetentIndex = kRNSFormSheetAlwaysDimmed; _initialDetentIndex = 0; @@ -274,6 +277,15 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props [_controller setNeedsAppearanceUpdate]; } + if (oldComponentProps.prefersHorizontalBars != newComponentProps.prefersHorizontalBars) { + _prefersHorizontalBars = newComponentProps.prefersHorizontalBars; +#if RNS_IPHONE_OS_VERSION_AVAILABLE(27_1) && !TARGET_OS_TV && !TARGET_OS_VISION + if (@available(iOS 27.1, *)) { + [_controller setNeedsUpdateOfVerticalBarConfiguration]; + } +#endif + } + if (oldComponentProps.preferredCornerRadius != newComponentProps.preferredCornerRadius) { _preferredCornerRadius = newComponentProps.preferredCornerRadius; [_controller setNeedsAppearanceUpdate]; diff --git a/ios/modals/form-sheet/RNSFormSheetProviders.h b/ios/modals/form-sheet/RNSFormSheetProviders.h index 66ff2e2898..588d5878c2 100644 --- a/ios/modals/form-sheet/RNSFormSheetProviders.h +++ b/ios/modals/form-sheet/RNSFormSheetProviders.h @@ -18,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol RNSFormSheetAppearanceProvider - (BOOL)prefersGrabberVisible; +- (BOOL)prefersHorizontalBars; - (CGFloat)preferredCornerRadius; - (NSInteger)largestUndimmedDetentIndex; - (nullable UIColor *)nativeContainerBackgroundColor; diff --git a/package.json b/package.json index c5b2b267a5..599d095126 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-screens", - "version": "5.0.0-t3.28", + "version": "5.0.0-t3.29", "description": "Native navigation primitives for your React Native app.", "scripts": { "submodules": "git submodule update --init --recursive && (cd react-navigation && yarn && yarn build && cd ../)", diff --git a/src/components/modals/form-sheet/FormSheet.types.ts b/src/components/modals/form-sheet/FormSheet.types.ts index 98b45c6e15..fb818e1fa8 100644 --- a/src/components/modals/form-sheet/FormSheet.types.ts +++ b/src/components/modals/form-sheet/FormSheet.types.ts @@ -63,6 +63,16 @@ export interface FormSheetProps { */ prefersGrabberVisible?: boolean | undefined; + /** + * Requests horizontal bars instead of the vertical bar on iPhone Duo. + * Leave unset to let UIKit place native controls in the vertical bar. + * + * @default false + * @platform ios + * @supported iOS 27.1 or higher + */ + prefersHorizontalBars?: boolean | undefined; + /** * @summary The corner radius that the sheet will attempt to present with. * diff --git a/src/fabric/legacy/ModalScreenNativeComponent.ts b/src/fabric/legacy/ModalScreenNativeComponent.ts index 1633ff0f12..b56b0d62a2 100644 --- a/src/fabric/legacy/ModalScreenNativeComponent.ts +++ b/src/fabric/legacy/ModalScreenNativeComponent.ts @@ -92,6 +92,7 @@ export interface NativeProps extends ViewProps { sheetAllowedDetents?: number[] | undefined; sheetLargestUndimmedDetent?: CT.WithDefault; sheetGrabberVisible?: CT.WithDefault; + sheetPrefersHorizontalBars?: CT.WithDefault; sheetCornerRadius?: CT.WithDefault; sheetExpandsWhenScrolledToEdge?: CT.WithDefault; sheetInitialDetent?: CT.WithDefault; diff --git a/src/fabric/legacy/ScreenNativeComponent.ts b/src/fabric/legacy/ScreenNativeComponent.ts index 0d0085c7fa..1fb1cb3c0c 100644 --- a/src/fabric/legacy/ScreenNativeComponent.ts +++ b/src/fabric/legacy/ScreenNativeComponent.ts @@ -92,6 +92,7 @@ export interface NativeProps extends ViewProps { sheetAllowedDetents?: number[] | undefined; sheetLargestUndimmedDetent?: CT.WithDefault; sheetGrabberVisible?: CT.WithDefault; + sheetPrefersHorizontalBars?: CT.WithDefault; sheetCornerRadius?: CT.WithDefault; sheetExpandsWhenScrolledToEdge?: CT.WithDefault; sheetInitialDetent?: CT.WithDefault; diff --git a/src/fabric/modals/form-sheet/FormSheetHostNativeComponent.ts b/src/fabric/modals/form-sheet/FormSheetHostNativeComponent.ts index 29b785373a..5d9edb44ce 100644 --- a/src/fabric/modals/form-sheet/FormSheetHostNativeComponent.ts +++ b/src/fabric/modals/form-sheet/FormSheetHostNativeComponent.ts @@ -20,6 +20,7 @@ interface NativeProps extends ViewProps { isOpen?: CT.WithDefault; detents?: CT.Double[] | undefined; prefersGrabberVisible?: CT.WithDefault; + prefersHorizontalBars?: CT.WithDefault; preferredCornerRadius?: CT.WithDefault; largestUndimmedDetentIndex?: CT.WithDefault; initialDetentIndex?: CT.WithDefault; diff --git a/src/legacy/types.ts b/src/legacy/types.ts index ed29506c10..3f580790e8 100644 --- a/src/legacy/types.ts +++ b/src/legacy/types.ts @@ -454,6 +454,15 @@ export interface ScreenProps extends ViewProps { * @platform ios */ sheetGrabberVisible?: boolean | undefined; + /** + * Requests horizontal bars instead of the vertical bar for modal, page-sheet, + * and form-sheet presentations on iPhone Duo. Defaults to `false`, preserving + * UIKit's automatic bar placement. + * + * @platform ios + * @supported iOS 27.1 or higher + */ + sheetPrefersHorizontalBars?: boolean | undefined; /** * The largest sheet detent for which a view underneath won't be dimmed. * Works only when `stackPresentation` is set to `formSheet`. From d1aa7c82823e27a9b4d86d9fa0dc009694f26112 Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Mon, 12 Oct 2026 12:31:41 +0200 Subject: [PATCH 03/18] fix(iOS, Tabs): don't drop user selection of UISearchTab on mount transactions (#4862) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description On the `UITab` API path (iOS 26.1+), once a tab with `role: 'search'` has been activated (`automaticallyActivatesSearch` with a search bar in the nested stack header), later user selections of that tab can be dropped: UIKit shows the search tab selected, but `onTabSelected` is never sent and JS stays on the previous tab. `tabBarController:didSelectTab:previousTab:` fires for both user and programmatic selections, so user selections were detected with a flag set in `tabBarController:shouldSelectTab:` and consumed in `didSelectTab:`. Every container update (`-performContainerUpdate`, run after each Fabric mount transaction) cleared that flag. On iOS 27, once search has been activated, UIKit lets a mount transaction run between `shouldSelectTab:` and `didSelectTab:` - the flag is cleared and the user selection is treated as programmatic. This PR inverts the filter: the controller marks its own `setTabs:` / `selectedTab` writes - UIKit sends `didSelectTab:` synchronously from inside them (verified at runtime and in the UIKitCore disassembly on iOS 26.1 and 27.0) - and treats every other `didSelectTab:` as a user selection. No flag stays set across the asynchronous should -> did window anymore. Reported in #4855, with the first fix proposed in #4856, by @zhelezkov - thank you! The scenario steps and the "Selected in JS" readout of the v4 test come from #4856. Closes #4855. ## Changes - `RNSTabBarController`: replace `_isHandlingUserTabSelection` (set in `shouldSelectTab:`, cleared on every container update) with `_isApplyingProgrammaticTabSelection`, set around the controller's own `setTabs:` / `selectedTab` writes and checked in `didSelectTab:`. - `test-tabs-search-tab-activation-ios` (Stack v4 & tabs): JS-side selection readout on the List screen, scenario steps for returning through the collapsed tab bar, and an e2e test for that flow. - New `test-tabs-navigation-state-search-tab` (tabs): verifies that each user and programmatic selection of a search-role tab advances the navigation state exactly once with the right action origin, with an e2e test. It hosts no search controller, so it does not reproduce #4855 itself - it guards the programmatic-selection filtering this fix relies on. ## Test plan e2e (Detox, `ios.sim.release`, iPhone 17): - `FabricExample/e2e/component-integration-tests/tabs-stack-v4/test-tabs-search-tab-activation-ios.e2e.ts` - iOS 27.0: fails without the fix ("Selected in JS: no" after reselecting the search tab), passes with it. - iOS 26.5: passes with and without the fix - the race was not observed on iOS 26.x, so CI (iOS 26.x for now) does not guard it until it moves to iOS 27. - `FabricExample/e2e/single-feature-tests/tabs/test-tabs-navigation-state-search-tab.e2e.ts` - passes with the fix on iOS 27.0 and 26.5. - `FabricExample/e2e/single-feature-tests/tabs/test-tabs-simple-nav.e2e.ts` - passes with the fix on iOS 27.0 and 26.5. Manual, `test-tabs-search-tab-activation-ios` (Component Integration Tests -> Stack V4 & Native Tabs), iOS 27.0 simulator, without the fix: 1. Enable `automaticallyActivatesSearch`. 2. Tap the search tab, dismiss the keyboard by dragging the list, tap the collapsed `Config` button. 3. Tap the search tab again and check "Selected in JS" on the List screen. Without the fix 5 of 5 reselections showed "Selected in JS: no"; with the fix the e2e loop above passes. ## Checklist - [x] Included code example that can be used to test this change. - [ ] For visual changes, included screenshots / GIFs / recordings documenting the change. - [ ] For API changes, updated relevant public types. - [ ] Ensured that CI passes 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Nick Zhelezkov <5163918+zhelezkov@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 (cherry picked from commit 6430b6709d6a9ecb453aeecde0063f713b294454) --- ...test-tabs-search-tab-activation-ios.e2e.ts | 66 ++++++++++++ ...st-tabs-navigation-state-search-tab.e2e.ts | 70 ++++++++++++ .../index.tsx | 7 ++ .../scenario-description.ts | 2 +- .../scenario.md | 30 ++++-- .../tests/single-feature-tests/tabs/index.ts | 3 + .../index.tsx | 101 ++++++++++++++++++ .../scenario-description.ts | 11 ++ .../scenario.md | 69 ++++++++++++ ios/tabs/host/RNSTabBarController.mm | 23 ++-- 10 files changed, 365 insertions(+), 17 deletions(-) create mode 100644 FabricExample/e2e/component-integration-tests/tabs-stack-v4/test-tabs-search-tab-activation-ios.e2e.ts create mode 100644 FabricExample/e2e/single-feature-tests/tabs/test-tabs-navigation-state-search-tab.e2e.ts create mode 100644 apps/src/tests/single-feature-tests/tabs/test-tabs-navigation-state-search-tab/index.tsx create mode 100644 apps/src/tests/single-feature-tests/tabs/test-tabs-navigation-state-search-tab/scenario-description.ts create mode 100644 apps/src/tests/single-feature-tests/tabs/test-tabs-navigation-state-search-tab/scenario.md 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/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 (null); + +function formatLastSelection(event: TabSelectedEvent | null) { + if (event === null) { + return 'Last selection: none'; + } + return `Last selection: ${event.selectedScreenKey} (${event.actionOrigin}), provenance: ${event.provenance}`; +} + +function ContentView() { + const { routeKey, isSelected, selectTab } = useTabsNavigationContext(); + const lastSelection = React.useContext(LastSelectionContext); + + return ( + + + {routeKey} + + + Selected in JS: {isSelected ? 'yes' : 'no'} + + + {formatLastSelection(lastSelection)} + +