This repository was archived by the owner on Nov 27, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +26
-18
lines changed
Expand file tree Collapse file tree 2 files changed +26
-18
lines changed Original file line number Diff line number Diff line change @@ -13,15 +13,14 @@ export type Props<T> = {|
1313 style ?: ViewStyleProp ,
1414| } ;
1515
16+ const { max, min, multiply } = Animated ;
17+
1618export default function TabBarIndicator < T : Route > (props: Props< T > ) {
1719 const { width , position , navigationState , style } = props;
1820 const { routes } = navigationState;
19- const translateX = Animated.multiply(
20- Animated.interpolate(position, {
21- inputRange : [ 0 , routes . length - 1 ] ,
22- outputRange : [ 0 , routes . length - 1 ] ,
23- extrapolate : 'clamp' ,
24- } ),
21+
22+ const translateX = multiply(
23+ max(min(position, routes.length - 1), 0),
2524 width * (I18nManager.isRTL ? -1 : 1)
2625 );
2726
Original file line number Diff line number Diff line change @@ -69,18 +69,27 @@ export default function TabBarItem<T: Route>({
6969 const tabIndex = navigationState . routes . indexOf ( route ) ;
7070 const isFocused = navigationState . index === tabIndex ;
7171
72- // Prepend '-1', so there are always at least 2 items in inputRange
73- const inputRange = [ - 1 , ...navigationState . routes . map ( ( x , i ) => i ) ] ;
74-
75- const activeOpacity = Animated . interpolate ( position , {
76- inputRange,
77- outputRange : inputRange . map ( i => ( i === tabIndex ? 1 : 0 ) ) ,
78- } ) ;
79-
80- const inactiveOpacity = Animated . interpolate ( position , {
81- inputRange,
82- outputRange : inputRange . map ( i => ( i === tabIndex ? 0 : 1 ) ) ,
83- } ) ;
72+ let activeOpacity ;
73+ let inactiveOpacity ;
74+
75+ if ( navigationState . routes . length > 1 ) {
76+ const inputRange = navigationState . routes . map ( ( x , i ) => i ) ;
77+
78+ activeOpacity = Animated . interpolate ( position , {
79+ inputRange,
80+ outputRange : inputRange . map ( i => ( i === tabIndex ? 1 : 0 ) ) ,
81+ } ) ;
82+
83+ inactiveOpacity = Animated . interpolate ( position , {
84+ inputRange,
85+ outputRange : inputRange . map ( i => ( i === tabIndex ? 0 : 1 ) ) ,
86+ } ) ;
87+ } else {
88+ // When there's only one tab, we can't use interpolate
89+ // Coz inputRange can't have only one item
90+ activeOpacity = 1 ;
91+ inactiveOpacity = 0 ;
92+ }
8493
8594 let icon = null ;
8695 let label = null ;
You can’t perform that action at this time.
0 commit comments