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:
Ashoat Tevosyan
2018-05-16 09:38:39 -04:00
parent 078e7b802a
commit 325c65aa5f
4 changed files with 9 additions and 25 deletions

View File

@@ -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",

View File

@@ -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}
/>
);
};

View File

@@ -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
}
};

View File

@@ -201,8 +201,8 @@ class TabBarBottom extends React.Component<Props> {
<TouchableWithoutFeedback
key={route.key}
onPress={() => {
jumpTo(route.key);
onTabPress({ route });
jumpTo(route.key);
}}
>
<View