From 35ddc65a4ca308379ace4dd5030aa45ce57f80ba Mon Sep 17 00:00:00 2001 From: Max schwenk Date: Wed, 18 Nov 2026 16:28:50 -0800 Subject: [PATCH 1/2] fix(ios): header symbol buttons no longer fade in on every rebuild Every Fabric header rebuild built new UIBarButtonItems and swapped them in with setLeft/RightBarButtonItems:animated:YES. UIKit blurs a new bar item in when it enters the window, and the animated swap runs its own transition on top. In T3 Code a keyboard show or hide adds or drops a dismiss-keyboard item on every stack header: one tap on search rebuilt 7 headers 16 times in about 320 ms, so the visible buttons were replaced and re-faded several times in a row. On the iPhone Duo the trailing items sit in the vertical bar, and there the transition regularly stops partway: the glass buttons stay blurred with no icon until the screen is rebuilt. - Leading and trailing items are set without animation, including when a header is cleared. The toolbar already did this. - A rebuilt plain symbol button (no custom view, menu or overflow menu) copies its new contents onto the button already shown for the same item id, like the toolbar's retained icon buttons, so UIKit keeps the view it has. Buttons with menus are still rebuilt, since their menus capture the toggle state tracker a rebuild replaces. - applyItems skips setting an item array that hasn't changed. --- ios/header/RNSHeaderCoordinator.mm | 118 ++++++++++++++++++++++++++--- 1 file changed, 108 insertions(+), 10 deletions(-) diff --git a/ios/header/RNSHeaderCoordinator.mm b/ios/header/RNSHeaderCoordinator.mm index 95891cd21a..f475eae88e 100644 --- a/ios/header/RNSHeaderCoordinator.mm +++ b/ios/header/RNSHeaderCoordinator.mm @@ -89,6 +89,12 @@ - (void)rebuild // UIKit requires the search controller before its placement item is created. [self applyConfigPropertiesForController:controller]; + // UIKit fades a bar item in each time a new one enters the window. Items rebuilt here reuse the button already + // shown for the same id when only its contents changed, so the bar does not fade it in again. + NSDictionary *previousItemsByItemId = [_barButtonItemsByItemId copy]; + NSSet *previousBarItems = + [NSSet setWithArray:[_leadingBarButtonItems arrayByAddingObjectsFromArray:_trailingBarButtonItems]]; + [_leadingBarButtonItems removeAllObjects]; [_trailingBarButtonItems removeAllObjects]; [_toolbarBarButtonItems removeAllObjects]; @@ -105,10 +111,14 @@ - (void)rebuild switch (item.placement) { case RNSHeaderItemPlacementLeading: - [_leadingBarButtonItems addObject:[self buildBarButtonItemForItem:item]]; + [_leadingBarButtonItems addObject:[self buildBarItemForItem:item + reusingItem:previousItemsByItemId[item.itemId] + fromItems:previousBarItems]]; break; case RNSHeaderItemPlacementTrailing: - [_trailingBarButtonItems addObject:[self buildBarButtonItemForItem:item]]; + [_trailingBarButtonItems addObject:[self buildBarItemForItem:item + reusingItem:previousItemsByItemId[item.itemId] + fromItems:previousBarItems]]; break; case RNSHeaderItemPlacementToolbar: #if !TARGET_OS_TV @@ -233,7 +243,14 @@ - (void)rebuildItemWithId:(NSString *)itemId switch (targetItem.placement) { case RNSHeaderItemPlacementLeading: { - UIBarButtonItem *newBarButtonItem = [self buildBarButtonItemForItem:targetItem]; + NSSet *shownItems = [NSSet setWithArray:_leadingBarButtonItems]; + UIBarButtonItem *newBarButtonItem = [self buildBarItemForItem:targetItem + reusingItem:oldBarButtonItem + fromItems:shownItems]; + if (newBarButtonItem == oldBarButtonItem) { + // Updated in place: the bar already shows this button. + break; + } if (oldBarButtonItem != nil) { NSUInteger index = [_leadingBarButtonItems indexOfObject:oldBarButtonItem]; @@ -244,11 +261,18 @@ - (void)rebuildItemWithId:(NSString *)itemId } } - [controller.navigationItem setLeftBarButtonItems:[_leadingBarButtonItems copy] animated:YES]; + [controller.navigationItem setLeftBarButtonItems:[_leadingBarButtonItems copy] animated:NO]; break; } case RNSHeaderItemPlacementTrailing: { - UIBarButtonItem *newBarButtonItem = [self buildBarButtonItemForItem:targetItem]; + NSSet *shownItems = [NSSet setWithArray:_trailingBarButtonItems]; + UIBarButtonItem *newBarButtonItem = [self buildBarItemForItem:targetItem + reusingItem:oldBarButtonItem + fromItems:shownItems]; + if (newBarButtonItem == oldBarButtonItem) { + // Updated in place: the bar already shows this button. + break; + } if (oldBarButtonItem != nil) { NSUInteger index = [_trailingBarButtonItems indexOfObject:oldBarButtonItem]; @@ -259,7 +283,7 @@ - (void)rebuildItemWithId:(NSString *)itemId } } - [controller.navigationItem setRightBarButtonItems:[_trailingBarButtonItems copy] animated:YES]; + [controller.navigationItem setRightBarButtonItems:[_trailingBarButtonItems copy] animated:NO]; break; } case RNSHeaderItemPlacementToolbar: { @@ -389,8 +413,8 @@ - (void)clearHeaderConfiguration navItem.titleView = nil; navItem.standardAppearance = nil; navItem.scrollEdgeAppearance = nil; - [navItem setLeftBarButtonItems:@[] animated:YES]; - [navItem setRightBarButtonItems:@[] animated:YES]; + [navItem setLeftBarButtonItems:@[] animated:NO]; + [navItem setRightBarButtonItems:@[] animated:NO]; #if RNS_IPHONE_OS_VERSION_AVAILABLE(16_0) && !TARGET_OS_TV if (@available(iOS 16.0, *)) { @@ -741,8 +765,14 @@ - (void)applyItemsWithTitleView:(nullable UIView *)titleView navItem.leftItemsSupplementBackButton = YES; #endif // !TARGET_OS_TV - [navItem setLeftBarButtonItems:[_leadingBarButtonItems copy] animated:YES]; - [navItem setRightBarButtonItems:[_trailingBarButtonItems copy] animated:YES]; + // Like the toolbar above: a Fabric rebuild is not a transition. An animated swap restarts UIKit's blur + // transition on every rebuild, and on the iPhone Duo's vertical bar it can leave the buttons blurred. + if (![navItem.leftBarButtonItems ?: @[] isEqualToArray:_leadingBarButtonItems]) { + [navItem setLeftBarButtonItems:[_leadingBarButtonItems copy] animated:NO]; + } + if (![navItem.rightBarButtonItems ?: @[] isEqualToArray:_trailingBarButtonItems]) { + [navItem setRightBarButtonItems:[_trailingBarButtonItems copy] animated:NO]; + } navItem.titleView = titleView; @@ -787,6 +817,74 @@ - (void)applyTitleMenuForController:(UIViewController *)controller #endif // !TARGET_OS_TV } +/** + Builds the bar item for a leading or trailing header item. When `previous` is the button shown for the same item + and both are plain icon buttons, the new contents are copied onto `previous` and it is returned instead, so UIKit + keeps the button it already shows rather than fading a new one in. + */ +- (UIBarButtonItem *)buildBarItemForItem:(id)item + reusingItem:(nullable UIBarButtonItem *)previous + fromItems:(NSSet *)shownItems +{ + UIBarButtonItem *source = [self buildBarButtonItemForItem:item]; + if (previous == nil || previous == source || item.searchBarPlacement || ![shownItems containsObject:previous] || + ![RNSHeaderCoordinator isReusablePlainIconItem:source] || + ![RNSHeaderCoordinator isReusablePlainIconItem:previous]) { + return source; + } + + previous.primaryAction = source.primaryAction; + previous.target = source.target; + previous.action = source.action; + previous.title = source.title; + previous.image = source.image; + previous.tintColor = source.tintColor; + previous.enabled = source.enabled; + previous.style = source.style; + previous.accessibilityLabel = source.accessibilityLabel; +#if RNS_IPHONE_OS_VERSION_AVAILABLE(26_0) + if (@available(iOS 26.0, *)) { + previous.identifier = source.identifier; + previous.hidesSharedBackground = source.hidesSharedBackground; + } +#endif // RNS_IPHONE_OS_VERSION_AVAILABLE(26_0) +#if RNS_IPHONE_OS_VERSION_AVAILABLE(27_0) && !TARGET_OS_TV && !TARGET_OS_VISION + if (@available(iOS 27.0, *)) { + previous.visibilityPriority = source.visibilityPriority; + } +#endif // RNS_IPHONE_OS_VERSION_AVAILABLE(27_0) && !TARGET_OS_TV && !TARGET_OS_VISION +#if RNS_IPHONE_OS_VERSION_AVAILABLE(27_1) && !TARGET_OS_TV && !TARGET_OS_VISION + if (@available(iOS 27.1, *)) { + previous.axisBehavior = source.axisBehavior; + } +#endif // RNS_IPHONE_OS_VERSION_AVAILABLE(27_1) && !TARGET_OS_TV && !TARGET_OS_VISION + + if (item.itemId != nil) { + _barButtonItemsByItemId[item.itemId] = previous; + } + return previous; +} + +/** + A button whose whole state is the properties copied above: a symbol image resolves synchronously, so no image + load finishes later on the discarded item, and there is no custom view, menu or overflow menu to carry over. Menus + capture the toggle state tracker they were built with, which a rebuild replaces. + */ ++ (BOOL)isReusablePlainIconItem:(UIBarButtonItem *)item +{ + if (item.customView != nil || item.menu != nil || item.image == nil || !item.image.isSymbolImage) { + return NO; + } +#if RNS_IPHONE_OS_VERSION_AVAILABLE(16_0) && !TARGET_OS_TV + if (@available(iOS 16.0, *)) { + if (item.menuRepresentation != nil) { + return NO; + } + } +#endif // RNS_IPHONE_OS_VERSION_AVAILABLE(16_0) && !TARGET_OS_TV + return YES; +} + - (UIBarButtonItem *)buildBarButtonItemForItem:(id)item { UIBarButtonItem *barButtonItem = nil; From c213f92b5c0f73280b93603f541d5589dc4b9bc4 Mon Sep 17 00:00:00 2001 From: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:29:03 -0800 Subject: [PATCH 2/2] chore: release 5.0.0-t3.61 Co-Authored-By: Claude Opus 5.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 18b2093612..78c760deb0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-screens", - "version": "5.0.0-t3.60", + "version": "5.0.0-t3.61", "description": "Native navigation primitives for your React Native app.", "scripts": { "submodules": "git submodule update --init --recursive && (cd react-navigation && yarn && yarn build && cd ../)",