Skip to content

Commit aaf14b9

Browse files
committed
WA for newier RN version. aksonov#3845
1 parent b6e8e71 commit aaf14b9

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/Router.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,23 @@ class App extends React.Component {
2525
BackHandler.addEventListener('hardwareBackPress', this.props.backAndroidHandler || this.onBackPress);
2626

2727
// If the app was "woken up" by an external route.
28-
Linking.getInitialURL().then(url => this.parseDeepURL(url));
28+
Linking.getInitialURL().then((url) => this.parseDeepURL(url));
2929
// Add an event listener for further deep linking.
30-
Linking.addEventListener('url', this.handleDeepURL);
30+
this.subscription = Linking.addEventListener('url', this.handleDeepURL);
3131
}
3232

3333
componentWillUnmount() {
3434
BackHandler.removeEventListener('hardwareBackPress', this.props.backAndroidHandler || this.onBackPress);
35-
Linking.removeEventListener('url', this.handleDeepURL);
35+
if (typeof Linking.removeEventListener === 'function') {
36+
Linking.removeEventListener('url', this.handleDeepURL);
37+
} else if (this.subscription !== null) {
38+
this.subscription.remove();
39+
}
3640
}
3741

3842
onBackPress = () => this.props.navigationStore.pop();
3943

40-
handleDeepURL = e => this.parseDeepURL(e.url);
44+
handleDeepURL = (e) => this.parseDeepURL(e.url);
4145

4246
parseDeepURL = (url) => {
4347
// If there is no url, then return.
@@ -53,8 +57,8 @@ class App extends React.Component {
5357
}
5458
// Build an array of paths for every scene.
5559
const allPaths = Object.values(this.props.navigationStore.states)
56-
.map(obj => obj.path)
57-
.filter(path => path);
60+
.map((obj) => obj.path)
61+
.filter((path) => path);
5862
// Try to match the url against the set of paths and parse the url parameters.
5963
const parsedPath = pathParser(cleanUrl, allPaths);
6064

@@ -70,7 +74,7 @@ class App extends React.Component {
7074
const actionKey = Object.entries(this.props.navigationStore.states)
7175
.filter(([, value]) => value.path === path)
7276
.map(([key]) => key)
73-
.find(key => key);
77+
.find((key) => key);
7478

7579
if (this.props.onDeepLink) {
7680
this.props.onDeepLink({ url, action: actionKey, params });
@@ -81,9 +85,7 @@ class App extends React.Component {
8185
};
8286

8387
render() {
84-
const {
85-
dispatch, state, navigator: AppNavigator, navigationStore,
86-
} = this.props;
88+
const { dispatch, state, navigator: AppNavigator, navigationStore } = this.props;
8789
if (dispatch && state) {
8890
navigationStore.externalDispatch = dispatch;
8991
navigationStore.externalState = state;
@@ -108,9 +110,7 @@ class App extends React.Component {
108110
}
109111
}
110112

111-
const Router = ({
112-
createReducer, sceneStyle, onStateChange, scenes, uriPrefix, navigator, getSceneStyle, children, onDeepLink, wrapBy, navigationStore: store, ...props
113-
}) => {
113+
const Router = ({ createReducer, sceneStyle, onStateChange, scenes, uriPrefix, navigator, getSceneStyle, children, onDeepLink, wrapBy, navigationStore: store, ...props }) => {
114114
const data = { ...props };
115115
if (getSceneStyle) {
116116
data.cardStyle = getSceneStyle(props);
@@ -143,7 +143,7 @@ Router.defaultProps = {
143143
onStateChange: null,
144144
scenes: null,
145145
navigator: null,
146-
wrapBy: props => props,
146+
wrapBy: (props) => props,
147147
getSceneStyle: null,
148148
sceneStyle: null,
149149
children: null,

0 commit comments

Comments
 (0)