Skip to content

Commit

Permalink
fix: fix tabBarOnPress with MaterialTopTabs and fix isFocused (facebo…
Browse files Browse the repository at this point in the history
…ok#21)

* Hook up tabBarOnPress

* Move onTabPress logic to createTabNavigator

* Use old logic for determining focus state

* Use navigation.isFocused()

* Reorder jumpTo/onTabPress

* react-native-tab-view@0.0.78
  • Loading branch information
Ashoat authored and satya164 committed Aug 18, 2019
1 parent 42e35f5 commit 491ee81
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ class TabView extends React.PureComponent<Props> {
return route.routeName;
};

_getOnPress = (previousScene, { route }) => {
const { descriptors } = this.props;
const descriptor = descriptors[route.key];
const options = descriptor.options;

return options.tabBarOnPress;
};

_getTestIDProps = ({ route, focused }) => {
const { descriptors } = this.props;
const descriptor = descriptors[route.key];
Expand Down Expand Up @@ -107,6 +99,7 @@ class TabView extends React.PureComponent<Props> {
getLabelText={this.props.getLabelText}
getTestIDProps={this._getTestIDProps}
renderIcon={this._renderIcon}
onTabPress={this.props.onTabPress}
/>
);
};
Expand Down
21 changes: 6 additions & 15 deletions packages/bottom-tabs/src/utils/createTabNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,14 @@ export default function createTabNavigator(TabView: React.ComponentType<*>) {
const { descriptors } = this.props;
const descriptor = descriptors[route.key];
const { navigation, options } = descriptor;
const focused = navigation.isFocused();

if (options.tabBarOnPress) {
options.tabBarOnPress({
navigation,
});
} else {
const isFocused =
this.props.navigation.state.index ===
this.props.navigation.state.routes.indexOf(route);

if (isFocused) {
if (route.hasOwnProperty('index') && route.index > 0) {
navigation.dispatch(StackActions.popToTop({ key: route.key }));
} else {
// TODO: do something to scroll to top
}
}
options.tabBarOnPress({ navigation });
} else if (focused && route.hasOwnProperty('index') && route.index > 0) {
navigation.dispatch(StackActions.popToTop({ key: route.key }));
} else if (focused) {
// TODO: do something to scroll to top
}
};

Expand Down
2 changes: 1 addition & 1 deletion packages/bottom-tabs/src/views/BottomTabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ class TabBarBottom extends React.Component<Props> {
<TouchableWithoutFeedback
key={route.key}
onPress={() => {
jumpTo(route.key);
onTabPress({ route });
jumpTo(route.key);
}}
>
<View
Expand Down

0 comments on commit 491ee81

Please sign in to comment.