-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable Double R shortcut to reload JS when redbox is shown on Android
Summary: Make "double tap R" shortcut enabled when redbox is shown in RN Android, consistent with that in iOS. Reviewed By: mkonicek Differential Revision: D3390132 fbshipit-source-id: 48fc40c2ba371a34abcac42a077359d11e907dfc
- Loading branch information
Siqi Liu
authored and
Facebook Github Bot 9
committed
Jun 7, 2016
1 parent
748a507
commit 4959b21
Showing
3 changed files
with
63 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
ReactAndroid/src/main/java/com/facebook/react/devsupport/DoubleTapReloadRecognizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
package com.facebook.react.devsupport; | ||
|
||
import android.os.Handler; | ||
import android.view.KeyEvent; | ||
import android.view.View; | ||
import android.widget.EditText; | ||
|
||
/** | ||
* A class allows recognizing double key tap of "R", used to reload JS in | ||
* {@link AbstractReactActivity}, {@link RedBoxDialog} and {@link ReactActivity}. | ||
*/ | ||
public class DoubleTapReloadRecognizer { | ||
private boolean mDoRefresh = false; | ||
private static final long DOUBLE_TAP_DELAY = 200; | ||
|
||
public boolean didDoubleTapR(int keyCode, View view) { | ||
if (keyCode == KeyEvent.KEYCODE_R && !(view instanceof EditText)) { | ||
if (mDoRefresh) { | ||
mDoRefresh = false; | ||
return true; | ||
} else { | ||
mDoRefresh = true; | ||
new Handler().postDelayed( | ||
new Runnable() { | ||
@Override | ||
public void run() { | ||
mDoRefresh = false; | ||
} | ||
}, | ||
DOUBLE_TAP_DELAY); | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters