Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent navigating twice when tapping too fast #1348

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/addNavigationHelpers.js
Expand Up @@ -13,6 +13,7 @@ import type {
import NavigationActions from './NavigationActions';

export default function<S: *>(navigation: NavigationProp<S, NavigationAction>) {
let debounce = true;
return {
...navigation,
goBack: (key?: ?string): boolean =>
Expand All @@ -25,14 +26,27 @@ export default function<S: *>(navigation: NavigationProp<S, NavigationAction>) {
routeName: string,
params?: NavigationParams,
action?: NavigationAction,
): boolean =>
navigation.dispatch(
NavigationActions.navigate({
routeName,
params,
action,
}),
),
): boolean => {
if (debounce) {
debounce = false;
navigation.dispatch(
NavigationActions.navigate({
routeName,
params,
action,
}),
);
setTimeout(
() => {
debounce = true;
},
500,
);
return true;
}
return false;
},

/**
* For updating current route params. For example the nav bar title and
* buttons are based on the route params.
Expand Down