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 8f2d6aa commit c436433
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/bottom-tabs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ You can install another package, `react-navigation-material-bottom-tabs`, to use
- `createMaterialBottomTabNavigator`: Material design themed animated bottom tabs, from [react-native-paper](https://callstack.github.io/react-native-paper/bottom-navigation.html).

```js
import createMaterialBottomTabNavigator from 'react-navigation-material-bottom-tabs/createMaterialBottomTabNavigator';
import { createMaterialBottomTabNavigator } from 'react-navigation-material-bottom-tabs';

export default createMaterialBottomTabNavigator({
Album: { screen: Album },
Expand Down
2 changes: 1 addition & 1 deletion packages/bottom-tabs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"dependencies": {
"hoist-non-react-statics": "^2.5.0",
"prop-types": "^15.6.0",
"react-lifecycles-compat": "^1.0.2",
"react-lifecycles-compat": "^3.0.4",
"react-native-safe-area-view": "^0.7.0",
"react-native-tab-view": "~0.0.78"
},
Expand Down
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
10 changes: 10 additions & 0 deletions packages/bottom-tabs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4400,6 +4400,10 @@ react-lifecycles-compat@^3, react-lifecycles-compat@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.2.tgz#7279047275bd727a912e25f734c0559527e84eff"

react-lifecycles-compat@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"

[email protected]:
version "1.0.0"
resolved "https://registry.yarnpkg.com/react-native-dismiss-keyboard/-/react-native-dismiss-keyboard-1.0.0.tgz#32886242b3f2317e121f3aeb9b0a585e2b879b49"
Expand Down Expand Up @@ -4444,6 +4448,12 @@ react-native-tab-view@~0.0.77:
dependencies:
prop-types "^15.6.0"

react-native-tab-view@~0.0.78:
version "0.0.78"
resolved "https://registry.yarnpkg.com/react-native-tab-view/-/react-native-tab-view-0.0.78.tgz#9b90730d89cbd34a03f0e0ab10e74ca7af945560"
dependencies:
prop-types "^15.6.0"

[email protected]:
version "4.4.2"
resolved "https://registry.yarnpkg.com/react-native-vector-icons/-/react-native-vector-icons-4.4.2.tgz#090f42ee0396c4cc4eae0ddaa518028ba8df40c7"
Expand Down

0 comments on commit c436433

Please sign in to comment.