Skip to content

Commit f624e84

Browse files
computerjazzchristopherdro
authored andcommitted
[Nav] Prevent duplicate routing on double-tapping links (#58)
Note: Remove if update to React-Navigation fixes issue: react-navigation/react-navigation#723
1 parent 6fd5cf1 commit f624e84

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

Diff for: src/scopes/navigation/reducer.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//@flow
22
import AppNavigator from './navigator'
3+
import _ from 'lodash'
4+
35
import type { Action } from '../types.js'
46

57
// @TODO can we type this better or get type from react-navigation [zack]
@@ -8,10 +10,29 @@ export type State = {
810
index: number,
911
};
1012

11-
export default (state, action) => {
13+
function isDuplicateRoute(originalRoute, newRoute) {
14+
while (originalRoute && originalRoute.index >= 0) {
15+
originalRoute = originalRoute.routes[originalRoute.index]
16+
}
17+
18+
while (newRoute && newRoute.index >= 0) {
19+
newRoute = newRoute.routes[newRoute.index]
20+
}
21+
22+
if (_.isEqual(originalRoute, newRoute)) {
23+
console.log('## Duplicate navigation stack push, skipping')
24+
return true
25+
} else
26+
return false
27+
}
28+
29+
export default (state: ?State, action: Action) => {
1230
const appNavigatorState = AppNavigator.router.getStateForAction(
1331
action,
1432
state
1533
)
34+
35+
if (isDuplicateRoute(state, appNavigatorState)) return state
36+
1637
return appNavigatorState || state
1738
}

0 commit comments

Comments
 (0)