Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

Commit

Permalink
fix: use react-lifecycles-compat for async mode compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Aug 18, 2019
1 parent 491ee81 commit 93b45f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
28 changes: 14 additions & 14 deletions packages/bottom-tabs/src/navigators/createBottomTabNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as React from 'react';
import { View, StyleSheet } from 'react-native';
import { polyfill } from 'react-lifecycles-compat';
import createTabNavigator, {
type InjectedProps,
} from '../utils/createTabNavigator';
Expand All @@ -18,24 +19,21 @@ type State = {
};

class TabNavigationView extends React.PureComponent<Props, State> {
static getDerivedStateFromProps(nextProps, prevState) {
const { index } = nextProps.navigation.state;

return {
// Set the current tab to be loaded if it was not loaded before
loaded: prevState.loaded.includes(index)
? prevState.loaded
: [...prevState.loaded, index],
};
}

state = {
loaded: [this.props.navigation.state.index],
};

componentWillReceiveProps(nextProps) {
if (
nextProps.navigation.state.index !== this.props.navigation.state.index
) {
const { index } = nextProps.navigation.state;

this.setState(state => ({
loaded: state.loaded.includes(index)
? state.loaded
: [...state.loaded, index],
}));
}
}

_getLabel = ({ route, focused, tintColor }) => {
const label = this.props.getLabelText({ route });

Expand Down Expand Up @@ -124,6 +122,8 @@ class TabNavigationView extends React.PureComponent<Props, State> {
}
}

polyfill(TabNavigationView);

const styles = StyleSheet.create({
container: {
flex: 1,
Expand Down
8 changes: 5 additions & 3 deletions packages/bottom-tabs/src/utils/createTabNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ export default function createTabNavigator(TabView: React.ComponentType<*>) {

_handleIndexChange = index => {
const { navigation } = this.props;
navigation.dispatch(NavigationActions.navigate({
routeName: navigation.state.routes[index].routeName,
}));
navigation.dispatch(
NavigationActions.navigate({
routeName: navigation.state.routes[index].routeName,
})
);
};

render() {
Expand Down

0 comments on commit 93b45f2

Please sign in to comment.