Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

React Navigationのタブバーのバッジが見えないので背景色を変える

Posted at

React Navigationのタブバーのアイコンにバッジを表示したくて調べてみたところ、tabBarBadgeというオプションがあるのを発見しました。

Tab navigation | React Navigation
https://reactnavigation.org/docs/tab-based-navigation/

このオプション、@react-navigation/bottom-tabsが5.6.1では存在しなかったような気がするのですが、5.8.0にバージョンを上げたところ使えるようになっていました。

早速tabBarBadgeを試してみたところ、文字色が白で背景色が透明?なのか思うように表示されません。以下のアイコンの右上に"4"てバッジが表示されているはずなんですけどわかるでしょうか?

スクリーンショット 2020-09-14 21.15.18.png

色の変更については公式ドキュメントにも特に記載が見当たりません。ググってみたところ、以下のチケットで解決方法についてコメントを書いている人を発見しました。

The color for the "tabBarBadge" can't be changed #8812
https://github.com/react-navigation/react-navigation/issues/8812

NavigationContainerにthemeを設定すると、文字色が白で背景色が赤となり綺麗に表示されました。

const MyTheme = {
  ...DefaultTheme,
  colors: {
    ...DefaultTheme.colors,
    notification: 'red',
  },
}
<NavigationContainer theme={MyTheme}>
...
</NavigationContainer>

スクリーンショット 2020-09-14 21.13.49.png

なお、tabBarBadgeにゼロ"0"を指定するとゼロがそのまま表示されてしまいます。バッジを表示したくない場合はundefinedを指定しましょう。

        options={{
          title: 'AAA',
          tabBarIcon: tabBarIconAAA,
          tabBarBadge: someCondition ? undefined : 1,
        }}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?