mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-28 12:25:21 +08:00
fix: fix tabBarOnPress with MaterialTopTabs and fix isFocused (#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
This commit is contained in:
committed by
satyajit.happy
parent
42e35f5028
commit
491ee81eda
@@ -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];
|
||||
@@ -107,6 +99,7 @@ class TabView extends React.PureComponent<Props> {
|
||||
getLabelText={this.props.getLabelText}
|
||||
getTestIDProps={this._getTestIDProps}
|
||||
renderIcon={this._renderIcon}
|
||||
onTabPress={this.props.onTabPress}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -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
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -201,8 +201,8 @@ class TabBarBottom extends React.Component<Props> {
|
||||
<TouchableWithoutFeedback
|
||||
key={route.key}
|
||||
onPress={() => {
|
||||
jumpTo(route.key);
|
||||
onTabPress({ route });
|
||||
jumpTo(route.key);
|
||||
}}
|
||||
>
|
||||
<View
|
||||
|
||||
Reference in New Issue
Block a user