diff --git a/docs/api/navigators/TabNavigator.md b/docs/api/navigators/TabNavigator.md index a857e339ea..3c0cb205ec 100644 --- a/docs/api/navigators/TabNavigator.md +++ b/docs/api/navigators/TabNavigator.md @@ -108,6 +108,7 @@ Several options get passed to the underlying router to modify navigation logic: - `showLabel` - whether to show label for tab, default is true - `style` - style object for the tab bar - `labelStyle` - style object for the tab label +- `onTabPress` - optional callback invoked on tab press Example: @@ -135,6 +136,7 @@ tabBarOptions: { - `indicatorStyle` - style object for the tab indicator (line at the bottom of the tab) - `labelStyle` - style object for the tab label - `style` - style object for the tab bar +- `onTabPress` - optional callback invoked on tab press Example: diff --git a/src/views/TabView/TabBarBottom.js b/src/views/TabView/TabBarBottom.js index f395710fc0..d0ffa376cc 100644 --- a/src/views/TabView/TabBarBottom.js +++ b/src/views/TabView/TabBarBottom.js @@ -35,6 +35,7 @@ type Props = { position: Animated.Value; navigationState: NavigationState; jumpToIndex: (index: number) => void; + onTabPress: (route: NavigationRoute) => void; getLabel: (scene: TabScene) => ?(React.Element<*> | string); renderIcon: (scene: TabScene) => React.Element<*>; showLabel: boolean; @@ -57,6 +58,18 @@ export default class TabBarBottom extends PureComponent { + const { + navigationState, + jumpToIndex, + onTabPress, + } = this.props; + jumpToIndex(index); + if (onTabPress) { + onTabPress(navigationState.routes[index]); + } + } + _renderLabel = (scene: TabScene) => { const { position, @@ -144,7 +157,10 @@ export default class TabBarBottom extends PureComponent jumpToIndex(index)}> + this._handleTabPress(index)} + > {this._renderIcon(scene)} {this._renderLabel(scene)}