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
committed by satyajit.happy
parent 42e35f5028
commit 491ee81eda
3 changed files with 8 additions and 24 deletions

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