mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Kotlinify DoubleTapReloadRecognizer (#43862)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43862 Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Reviewed By: andrewdacenko Differential Revision: D55747942 fbshipit-source-id: 07376f5ca2790d1656903cd03705f32c2050a589
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0132142446
commit
c84faadd50
@@ -2161,9 +2161,9 @@ public abstract interface class com/facebook/react/devsupport/DevSupportManagerF
|
||||
public abstract fun create (Landroid/content/Context;Lcom/facebook/react/devsupport/ReactInstanceDevHelper;Ljava/lang/String;ZLcom/facebook/react/devsupport/interfaces/RedBoxHandler;Lcom/facebook/react/devsupport/interfaces/DevBundleDownloadListener;ILjava/util/Map;Lcom/facebook/react/common/SurfaceDelegateFactory;Lcom/facebook/react/devsupport/interfaces/DevLoadingViewManager;)Lcom/facebook/react/devsupport/interfaces/DevSupportManager;
|
||||
}
|
||||
|
||||
public class com/facebook/react/devsupport/DoubleTapReloadRecognizer {
|
||||
public final class com/facebook/react/devsupport/DoubleTapReloadRecognizer {
|
||||
public fun <init> ()V
|
||||
public fun didDoubleTapR (ILandroid/view/View;)Z
|
||||
public final fun didDoubleTapR (ILandroid/view/View;)Z
|
||||
}
|
||||
|
||||
public abstract interface class com/facebook/react/devsupport/HMRClient : com/facebook/react/bridge/JavaScriptModule {
|
||||
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.devsupport;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
|
||||
/**
|
||||
* A class allows recognizing double key tap of "R", used to reload JS in {@link
|
||||
* AbstractReactActivity}, {@link RedBoxDialogSurfaceDelegate} and {@link ReactActivity}.
|
||||
*/
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
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;
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.devsupport
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
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 [AbstractReactActivity],
|
||||
* [RedBoxDialogSurfaceDelegate] and [ReactActivity].
|
||||
*/
|
||||
public class DoubleTapReloadRecognizer {
|
||||
private var doRefresh = false
|
||||
|
||||
public fun didDoubleTapR(keyCode: Int, view: View): Boolean {
|
||||
if (keyCode == KeyEvent.KEYCODE_R && view !is EditText) {
|
||||
if (doRefresh) {
|
||||
doRefresh = false
|
||||
return true
|
||||
} else {
|
||||
doRefresh = true
|
||||
Handler(Looper.getMainLooper()).postDelayed({ doRefresh = false }, DOUBLE_TAP_DELAY)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private const val DOUBLE_TAP_DELAY: Long = 200
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user