From bd63eef7a0beb389b552814cc32fe9d93d3f029c Mon Sep 17 00:00:00 2001 From: QuanPV Date: Wed, 3 May 2017 09:14:58 +0700 Subject: [PATCH 1/2] Prevent navigating twice when tapping too fast --- src/addNavigationHelpers.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/addNavigationHelpers.js b/src/addNavigationHelpers.js index d7c468bc52..8c293596f7 100644 --- a/src/addNavigationHelpers.js +++ b/src/addNavigationHelpers.js @@ -13,6 +13,7 @@ import type { import NavigationActions from './NavigationActions'; export default function(navigation: NavigationProp) { + let debounce = true; return { ...navigation, goBack: (key?: ?string): boolean => @@ -25,14 +26,28 @@ export default function(navigation: NavigationProp) { 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. From cc8edcf957a220a10022991934e70ea2666a8032 Mon Sep 17 00:00:00 2001 From: QuanPV Date: Wed, 3 May 2017 09:30:33 +0700 Subject: [PATCH 2/2] Removed unnecessary empty line --- src/addNavigationHelpers.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/addNavigationHelpers.js b/src/addNavigationHelpers.js index 8c293596f7..f1042edcdb 100644 --- a/src/addNavigationHelpers.js +++ b/src/addNavigationHelpers.js @@ -42,7 +42,6 @@ export default function(navigation: NavigationProp) { }, 500, ); - return true; } return false;