@@ -41,6 +41,10 @@ type Props<T> = {
41
41
* By default, this is `true` when you have more than 3 tabs.
42
42
*/
43
43
shifting ?: boolean ,
44
+ /**
45
+ * Whether to show labels in tabs. When `false`, only icons will be displayed.
46
+ */
47
+ labeled ?: boolean ,
44
48
/**
45
49
* State for the bottom navigation. The state should contain the following properties:
46
50
*
@@ -289,6 +293,10 @@ class BottomNavigation<T: *> extends React.Component<Props<T>, State> {
289
293
);
290
294
}
291
295
296
+ static defaultProps = {
297
+ labeled : true ,
298
+ } ;
299
+
292
300
static getDerivedStateFromProps(nextProps, prevState) {
293
301
const { index, routes } = nextProps . navigationState ;
294
302
@@ -436,6 +444,7 @@ class BottomNavigation<T: *> extends React.Component<Props<T>, State> {
436
444
activeTintColor,
437
445
inactiveTintColor,
438
446
barStyle,
447
+ labeled,
439
448
style,
440
449
theme,
441
450
} = this . props ;
@@ -574,20 +583,23 @@ class BottomNavigation<T: *> extends React.Component<Props<T>, State> {
574
583
const focused = this . state . tabs [ index ] ;
575
584
576
585
// Scale up in the label
577
- const scale = shifting
578
- ? focused . interpolate ( {
579
- inputRange : [ 0 , 1 ] ,
580
- outputRange : [ 0.5 , 1 ] ,
581
- } )
582
- : 1 ;
586
+ const scale =
587
+ labeled && shifting
588
+ ? focused . interpolate ( {
589
+ inputRange : [ 0 , 1 ] ,
590
+ outputRange : [ 0.5 , 1 ] ,
591
+ } )
592
+ : 1 ;
583
593
584
594
// Move down the icon to account for no-label in shifting and smaller label in non-shifting.
585
- const translateY = shifting
586
- ? focused . interpolate ( {
587
- inputRange : [ 0 , 1 ] ,
588
- outputRange : [ 10 , 0 ] ,
589
- } )
590
- : 0 ;
595
+ const translateY = labeled
596
+ ? shifting
597
+ ? focused . interpolate ( {
598
+ inputRange : [ 0 , 1 ] ,
599
+ outputRange : [ 10 , 0 ] ,
600
+ } )
601
+ : 0
602
+ : 10 ;
591
603
592
604
// We render the active icon and label on top of inactive ones and cross-fade them on change.
593
605
// This trick gives the illusion that we are animating between active and inactive colors.
@@ -651,67 +663,71 @@ class BottomNavigation<T: *> extends React.Component<Props<T>, State> {
651
663
) }
652
664
</ Animated . View >
653
665
</ Animated . View >
654
- < Animated . View
655
- style = { [
656
- styles . labelContainer ,
657
- {
658
- transform : [ { scale } ] ,
659
- } ,
660
- ] }
661
- >
666
+ { labeled ? (
662
667
< Animated . View
663
668
style = { [
664
- styles . labelWrapper ,
665
- { opacity : activeOpacity } ,
669
+ styles . labelContainer ,
670
+ {
671
+ transform : [ { scale } ] ,
672
+ } ,
666
673
] }
667
674
>
668
- { renderLabel ? (
669
- renderLabel ( {
670
- route,
671
- focused : true ,
672
- tintColor : activeColor ,
673
- } )
674
- ) : (
675
- < AnimatedText
676
- style = { [
677
- styles . label ,
678
- {
679
- color : activeColor ,
680
- } ,
681
- ] }
682
- >
683
- { getLabelText ( { route } ) }
684
- </ AnimatedText >
685
- ) }
686
- </ Animated . View >
687
- { shifting ? null : (
688
675
< Animated . View
689
676
style = { [
690
677
styles . labelWrapper ,
691
- { opacity : inactiveOpacity } ,
678
+ { opacity : activeOpacity } ,
692
679
] }
693
680
>
694
681
{ renderLabel ? (
695
682
renderLabel ( {
696
683
route,
697
- focused : false ,
698
- tintColor : inactiveColor ,
684
+ focused : true ,
685
+ tintColor : activeColor ,
699
686
} )
700
687
) : (
701
688
< AnimatedText
702
689
style = { [
703
690
styles . label ,
704
691
{
705
- color : inactiveColor ,
692
+ color : activeColor ,
706
693
} ,
707
694
] }
708
695
>
709
696
{ getLabelText ( { route } ) }
710
697
</ AnimatedText >
711
698
) }
712
699
</ Animated . View >
713
- ) }
714
- </ Animated . View >
700
+ { shifting ? null : (
701
+ < Animated . View
702
+ style = { [
703
+ styles . labelWrapper ,
704
+ { opacity : inactiveOpacity } ,
705
+ ] }
706
+ >
707
+ { renderLabel ? (
708
+ renderLabel ( {
709
+ route,
710
+ focused : false ,
711
+ tintColor : inactiveColor ,
712
+ } )
713
+ ) : (
714
+ < AnimatedText
715
+ style = { [
716
+ styles . label ,
717
+ {
718
+ color : inactiveColor ,
719
+ } ,
720
+ ] }
721
+ >
722
+ { getLabelText ( { route } ) }
723
+ </ AnimatedText >
724
+ ) }
725
+ </ Animated . View >
726
+ ) }
727
+ </ Animated . View >
728
+ ) : (
729
+ < View style = { styles . labelContainer } />
730
+ ) }
715
731
</ View >
716
732
</ Touchable >
717
733
) ;
0 commit comments