TabView (react-native-pager-view) does not update inside RNN screen on iOS (index updates but UI does not change)
What happened?
When using react-native-tab-view (which relies on react-native-pager-view) inside a react-native-navigation (RNN) screen on iOS, tab switching does not work correctly.
The index state updates correctly (onIndexChange fires), but the visible tab does not change or snaps back to the previous tab.
https://github.com/user-attachments/assets/93bbb959-11be-46c1-918d-c3f61da0f1f5
What was the expected behaviour?
Tabs should switch correctly when index changes.
Was it tested on latest react-native-navigation?
- [x] I have tested this issue on the latest react-native-navigation release and it still reproduces.
Help us reproduce this issue!
Create a clean React Native 0.77 project Add react-native-tab-view and react-native-pager-view TabView works correctly Add react-native-navigation Render the same TabView inside an RNN screen Try switching tabs
In what environment did this happen?
react-native: 0.77.3 react-native-navigation: 8.7.4 and latest react-native-tab-view: 4.0.5 react-native-pager-view: 6.9.1 Platform: iOS New Architecture: enabled
Same issue, but for me it seems to be linked to the commit : https://github.com/wix/react-native-navigation/commit/5a29a75b188a488817a888efabc8bfcabb56148b
Reverting this commit resolves the issue.
Thanks @manuhook
I'm currently using [email protected], and from what I can tell this version was released before the 5a29a75 commit. So it looks like that specific change isn't included on my side.
Given that, I’m probably hitting a similar issue with a different root cause. Still investigating, but sharing in case it helps narrow things down.
Issue8271TabViewRepro.zip @hcrnln I could not reproduce this issue on the versions you mentioned. My test project is attached. Try it out or maybe post your project so I can keep trying to reproduce it.
Same problem with https://github.com/wix/react-native-navigation/commit/5a29a75b188a488817a888efabc8bfcabb56148b, RNN 8.8.3 with preloadWindow.clipsToBounds = YES; doesn't help.
On my side the code tried to grab reactView synchronously right after [viewController render], but since Fabric renders asynchronously, it was nil on cold starts — so the render callback never fired and componentDidAppear was never emitted for the tabs.
Here's something working that removes the preload window (unnecessary with Fabric) and moves the reactView capture inside dispatch_notify, where the view is guaranteed to exist.
#import "UITabBarController+RNNUtils.h"
@implementation BottomTabsAfterInitialTabAttacher
- (void)attach:(UITabBarController *)bottomTabsController {
[bottomTabsController.selectedViewController setReactViewReadyCallback:^{
[bottomTabsController readyForPresentation];
for (UIViewController *viewController in bottomTabsController.deselectedViewControllers) {
dispatch_async(dispatch_get_main_queue(), ^{
dispatch_group_t ready = dispatch_group_create();
dispatch_group_enter(ready);
viewController.waitForRender = YES;
[viewController setReactViewReadyCallback:^{
dispatch_group_leave(ready);
}];
[viewController render];
// reactView is captured here, after Fabric has committed the first frame,
// not synchronously after render() where it is always nil.
dispatch_notify(ready, dispatch_get_main_queue(), ^{
if ([viewController isKindOfClass:[UINavigationController class]]) {
UIView *containerView =
[(UINavigationController *)viewController topViewController].view;
UIView *reactView = containerView.subviews.firstObject;
if (reactView) {
reactView.frame = containerView.bounds;
[containerView addSubview:reactView];
}
}
});
});
}
}];
[bottomTabsController.selectedViewController render];
}
@end