Skip to content

Commit 80b7046

Browse files
committed
Revert "fix ios lazy tab first-load flash"
This reverts commit 99b5e34.
1 parent 99b5e34 commit 80b7046

7 files changed

Lines changed: 9 additions & 131 deletions

File tree

.changeset/lazy-placeholders-style.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

apps/example/src/Examples/LazyTabs.tsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ import { useState } from 'react';
33
import { Article } from '../Screens/Article';
44
import { Albums } from '../Screens/Albums';
55
import { Contacts } from '../Screens/Contacts';
6-
import { Chat } from '../Screens/Chat';
7-
import { SolidColor } from '../Screens/SolidColor';
86

97
const renderScene = SceneMap({
108
article: Article,
119
albums: Albums,
1210
contacts: Contacts,
13-
chat: Chat,
14-
solid: SolidColor,
1511
});
1612

1713
export default function LazyTabs() {
@@ -39,18 +35,6 @@ export default function LazyTabs() {
3935
title: 'Contacts',
4036
testID: 'contactsTestID',
4137
},
42-
{
43-
key: 'chat',
44-
focusedIcon: require('../../assets/icons/chat_dark.png'),
45-
title: 'Chat',
46-
testID: 'chatTestID',
47-
},
48-
{
49-
key: 'solid',
50-
focusedIcon: require('../../assets/icons/person_dark.png'),
51-
title: 'Solid',
52-
testID: 'solidTestID',
53-
},
5438
]);
5539

5640
return (

apps/example/src/Examples/NativeBottomTabsLazy.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Albums } from '../Screens/Albums';
33
import { Contacts } from '../Screens/Contacts';
44
import { Chat } from '../Screens/Chat';
55
import { createNativeBottomTabNavigator } from '@bottom-tabs/react-navigation';
6-
import { SolidColor } from '../Screens/SolidColor';
76

87
const Tab = createNativeBottomTabNavigator();
98

@@ -39,13 +38,6 @@ export default function NativeBottomTabsLazy() {
3938
tabBarIcon: () => require('../../assets/icons/chat_dark.png'),
4039
}}
4140
/>
42-
<Tab.Screen
43-
name="Solid"
44-
component={SolidColor}
45-
options={{
46-
tabBarIcon: () => require('../../assets/icons/newspaper.svg'),
47-
}}
48-
/>
4941
</Tab.Navigator>
5042
);
5143
}

apps/example/src/Screens/SolidColor.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.

packages/react-native-bottom-tabs/ios/TabItemEventModifier.swift

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import UIKit
88

99
private final class TabBarDelegate: NSObject, UITabBarControllerDelegate {
1010
var onClick: ((_ index: Int?, _ identifier: String?) -> Bool)?
11-
weak var props: TabViewProps?
1211

1312
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
1413
if #available(iOS 27.0, *) {
@@ -72,36 +71,9 @@ private final class TabBarDelegate: NSObject, UITabBarControllerDelegate {
7271
$0 === tab || $0.identifier == tab.identifier
7372
}
7473
}
75-
76-
func tabBarController(
77-
_ tabBarController: UITabBarController,
78-
animationControllerForTransitionFrom fromVC: UIViewController,
79-
to toVC: UIViewController
80-
) -> UIViewControllerAnimatedTransitioning? {
81-
props?.disablePageAnimations == true ? DisabledTabTransitionAnimator() : nil
82-
}
83-
}
84-
85-
private final class DisabledTabTransitionAnimator: NSObject, UIViewControllerAnimatedTransitioning {
86-
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
87-
0
88-
}
89-
90-
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
91-
guard let toView = transitionContext.view(forKey: .to),
92-
let toViewController = transitionContext.viewController(forKey: .to) else {
93-
transitionContext.completeTransition(false)
94-
return
95-
}
96-
97-
toView.frame = transitionContext.finalFrame(for: toViewController)
98-
transitionContext.containerView.addSubview(toView)
99-
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
100-
}
10174
}
10275

10376
struct TabItemEventModifier: ViewModifier {
104-
@ObservedObject var props: TabViewProps
10577
let onTabEvent: (_ index: Int?, _ identifier: String?, _ isLongPress: Bool) -> Bool
10678
private let delegate = TabBarDelegate()
10779

@@ -113,7 +85,6 @@ struct TabItemEventModifier: ViewModifier {
11385
}
11486

11587
func handle(tabController: UITabBarController) {
116-
delegate.props = props
11788
delegate.onClick = { index, identifier in
11889
onTabEvent(index, identifier, false)
11990
}
@@ -184,14 +155,8 @@ extension View {
184155
/**
185156
Event for tab items. Returns true if should prevent default (switching tabs).
186157
*/
187-
func onTabItemEvent(
188-
props: TabViewProps,
189-
_ handler: @escaping (Int?, String?, Bool) -> Bool
190-
) -> some View {
191-
modifier(TabItemEventModifier(
192-
props: props,
193-
onTabEvent: handler
194-
))
158+
func onTabItemEvent(_ handler: @escaping (Int?, String?, Bool) -> Bool) -> some View {
159+
modifier(TabItemEventModifier(onTabEvent: handler))
195160
}
196161
}
197162

packages/react-native-bottom-tabs/ios/TabViewImpl.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ struct TabViewImpl: View {
4646
tabContent
4747
.tabBarMinimizeBehavior(props.minimizeBehavior)
4848
#if !os(tvOS) && !os(macOS) && !os(visionOS)
49-
.onTabItemEvent(
50-
props: props
51-
) { index, identifier, isLongPress in
49+
.onTabItemEvent { index, identifier, isLongPress in
5250
let item = identifier.flatMap { props.filteredItems.findByKey($0) }
5351
?? index.flatMap { props.filteredItems[safe: $0] }
5452
guard let key = item?.key else { return false }

packages/react-native-bottom-tabs/src/TabView.tsx

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,12 @@ const TabView = <Route extends BaseRoute>({
299299
}
300300
return navigationState.routes;
301301
}, [navigationState.routes]);
302-
const shouldDeferUnloadedLazySelection =
303-
Platform.OS === 'ios' && parseFloat(String(Platform.Version)) >= 26;
304302

305303
/**
306304
* List of loaded tabs, tabs will be loaded when navigated to.
307305
*/
308306
const [loaded, setLoaded] = React.useState<string[]>([focusedKey]);
307+
309308
if (!loaded.includes(focusedKey)) {
310309
// Set the current tab to be loaded if it was not loaded before
311310
setLoaded((loaded) => [...loaded, focusedKey]);
@@ -348,11 +347,7 @@ const TabView = <Route extends BaseRoute>({
348347
hidden: getHidden?.({ route }),
349348
testID: getTestID?.({ route }),
350349
role: getRole?.({ route }),
351-
preventsDefault:
352-
getPreventsDefault?.({ route }) ||
353-
(shouldDeferUnloadedLazySelection &&
354-
getLazy({ route }) !== false &&
355-
!loaded.includes(route.key)),
350+
preventsDefault: getPreventsDefault?.({ route }),
356351
};
357352
}),
358353
[
@@ -368,9 +363,6 @@ const TabView = <Route extends BaseRoute>({
368363
getTestID,
369364
getRole,
370365
getPreventsDefault,
371-
getLazy,
372-
loaded,
373-
shouldDeferUnloadedLazySelection,
374366
]
375367
);
376368

@@ -392,12 +384,6 @@ const TabView = <Route extends BaseRoute>({
392384
onIndexChange(index);
393385
});
394386

395-
const hasUnloadedLazyRoute =
396-
shouldDeferUnloadedLazySelection &&
397-
trimmedRoutes.some(
398-
(route) => getLazy({ route }) !== false && !loaded.includes(route.key)
399-
);
400-
401387
const handleTabLongPress = React.useCallback(
402388
({ nativeEvent: { key } }: { nativeEvent: OnPageSelectedEventData }) => {
403389
const index = trimmedRoutes.findIndex((route) => route.key === key);
@@ -408,22 +394,9 @@ const TabView = <Route extends BaseRoute>({
408394

409395
const handlePageSelected = React.useCallback(
410396
({ nativeEvent: { key } }: { nativeEvent: OnPageSelectedEventData }) => {
411-
const route = trimmedRoutes.find((route) => route.key === key);
412-
const preventsDefault = route ? getPreventsDefault({ route }) : false;
413-
414-
if (route && !preventsDefault) {
415-
setLoaded((loaded) =>
416-
loaded.includes(key) ? loaded : [...loaded, key]
417-
);
418-
}
419-
420397
jumpTo(key);
421398
},
422-
[
423-
getPreventsDefault,
424-
jumpTo,
425-
trimmedRoutes,
426-
]
399+
[jumpTo]
427400
);
428401

429402
const handleTabBarMeasured = React.useCallback(
@@ -469,34 +442,27 @@ const TabView = <Route extends BaseRoute>({
469442
activeTintColor={activeTintColor}
470443
inactiveTintColor={inactiveTintColor}
471444
experimentalBakedTintColors={experimentalBakedTintColors}
472-
disablePageAnimations={
473-
props.disablePageAnimations || hasUnloadedLazyRoute
474-
}
475445
barTintColor={tabBarStyle?.backgroundColor}
476446
rippleColor={rippleColor}
477447
labeled={labeled}
478448
>
479449
{trimmedRoutes.map((route) => {
480-
const customStyle = getSceneStyle({ route });
481-
482450
if (getLazy({ route }) !== false && !loaded.includes(route.key)) {
483451
// Don't render a screen if we've never navigated to it
484452
return (
485453
<View
486454
key={route.key}
487455
collapsable={false}
488-
style={[
489-
styles.screen,
490-
renderCustomTabBar ? styles.fullWidth : measuredDimensions,
491-
customStyle,
492-
]}
456+
style={styles.fullWidth}
493457
/>
494458
);
495459
}
496460

497461
const focused = route.key === focusedKey;
498462
const freeze = !focused ? getFreezeOnBlur({ route }) : false;
499463

464+
const customStyle = getSceneStyle({ route });
465+
500466
return (
501467
<View
502468
key={route.key}

0 commit comments

Comments
 (0)