react-native-navigation的迁移库

JsDevReloadHandler.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package com.reactnativenavigation.react;
  2. import android.view.KeyEvent;
  3. import android.view.View;
  4. import android.widget.EditText;
  5. import com.facebook.react.ReactInstanceManager;
  6. import com.reactnativenavigation.NavigationApplication;
  7. public class JsDevReloadHandler {
  8. private static boolean shouldRefreshOnRR = false;
  9. //TODO yuck.
  10. public static boolean onKeyUp(View currentFocus, int keyCode) {
  11. ReactInstanceManager reactInstanceManager = NavigationApplication
  12. .instance
  13. .getReactGateway()
  14. .getReactInstanceManager();
  15. if (reactInstanceManager != null &&
  16. reactInstanceManager.getDevSupportManager().getDevSupportEnabled()) {
  17. if (keyCode == KeyEvent.KEYCODE_MENU) {
  18. reactInstanceManager.showDevOptionsDialog();
  19. return true;
  20. }
  21. if (keyCode == KeyEvent.KEYCODE_R && !(currentFocus instanceof EditText)) {
  22. // Enable double-tap-R-to-reload
  23. if (shouldRefreshOnRR) {
  24. reactInstanceManager.getDevSupportManager().handleReloadJS();
  25. shouldRefreshOnRR = false;
  26. return true;
  27. } else {
  28. shouldRefreshOnRR = true;
  29. NavigationApplication.instance.runOnMainThread(
  30. new Runnable() {
  31. @Override
  32. public void run() {
  33. shouldRefreshOnRR = false;
  34. }
  35. },
  36. 500);
  37. }
  38. }
  39. }
  40. return false;
  41. }
  42. }