mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-02-09 09:13:32 +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:
@@ -42,7 +42,7 @@
|
||||
"prop-types": "^15.6.0",
|
||||
"react-lifecycles-compat": "^1.0.2",
|
||||
"react-native-safe-area-view": "^0.7.0",
|
||||
"react-native-tab-view": "~0.0.77"
|
||||
"react-native-tab-view": "~0.0.78"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@expo/vector-icons": "^6.2.0",
|
||||
|
||||
@@ -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