@ReactMethod public void initialize() { ReactApplication application = (ReactApplication)getReactApplicationContext() .getCurrentActivity() .getApplication(); DevSupportManager devSupportManager = application .getReactNativeHost() .getReactInstanceManager() .getDevSupportManager(); devSupportManager.addCustomDevOption("Log AsyncStorage", new DevOptionHandler() { @Override public void onOptionSelected() { getReactApplicationContext() .getJSModule(RCTNativeAppEventEmitter.class) .emit("LogAsyncStorage", null); } }); }
public Timing(ReactApplicationContext reactContext, DevSupportManager devSupportManager) { super(reactContext); mDevSupportManager = devSupportManager; // We store timers sorted by finish time. mTimers = new PriorityQueue<Timer>( 11, // Default capacity: for some reason they don't expose a (Comparator) constructor new Comparator<Timer>() { @Override public int compare(Timer lhs, Timer rhs) { long diff = lhs.mTargetTime - rhs.mTargetTime; if (diff == 0) { return 0; } else if (diff < 0) { return -1; } else { return 1; } } }); mTimerIdsToTimers = new HashMap<>(); mSendIdleEventsExecutorTokens = new HashSet<>(); mIdleCallbackContextsToCall = new ArrayList<>(); }
/** * Timing module needs to be created on the main thread so that it gets the correct Choreographer. */ protected Timing createTimingModule() { final SimpleSettableFuture<Timing> simpleSettableFuture = new SimpleSettableFuture<Timing>(); UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { Timing timing = new Timing(getContext(), mock(DevSupportManager.class)); simpleSettableFuture.set(timing); } }); try { return simpleSettableFuture.get(5000, TimeUnit.MILLISECONDS); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Demonstrates how to add a custom option to the dev menu. * https://stackoverflow.com/a/44882371/3968276 */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MainApplication application = (MainApplication) getApplication(); ReactNativeHost reactNativeHost = application.getReactNativeHost(); ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager(); DevSupportManager devSupportManager = reactInstanceManager.getDevSupportManager(); devSupportManager.addCustomDevOption("Custom dev option", new DevOptionHandler() { @Override public void onOptionSelected() { Toast.makeText(MainActivity.this, "Hello from custom dev option", Toast.LENGTH_SHORT).show(); } }); }
public static DevSupportManager create( Context applicationContext, ReactInstanceDevCommandsHandler reactInstanceCommandsHandler, @Nullable String packagerPathForJSBundleName, boolean enableOnCreate) { return create( applicationContext, reactInstanceCommandsHandler, packagerPathForJSBundleName, enableOnCreate, null); }
public static DevSupportManager create( Context applicationContext, ReactInstanceDevCommandsHandler reactInstanceCommandsHandler, @Nullable String packagerPathForJSBundleName, boolean enableOnCreate, @Nullable RedBoxHandler redBoxHandler) { if (!enableOnCreate) { return new DisabledDevSupportManager(); } try { // ProGuard is surprisingly smart in this case and will keep a class if it detects a call to // Class.forName() with a static string. So instead we generate a quasi-dynamic string to // confuse it. String className = new StringBuilder(DEVSUPPORT_IMPL_PACKAGE) .append(".") .append(DEVSUPPORT_IMPL_CLASS) .toString(); Class<?> devSupportManagerClass = Class.forName(className); Constructor constructor = devSupportManagerClass.getConstructor( Context.class, ReactInstanceDevCommandsHandler.class, String.class, boolean.class, RedBoxHandler.class); return (DevSupportManager) constructor.newInstance( applicationContext, reactInstanceCommandsHandler, packagerPathForJSBundleName, true, redBoxHandler); } catch (Exception e) { throw new RuntimeException( "Requested enabled DevSupportManager, but DevSupportManagerImpl class was not found" + " or could not be created", e); } }
public ReactContextBuilder setDevSupportManager(DevSupportManager devSupportManager) { this.devSupportManager = devSupportManager; return this; }
private DevSupportManager getDevSupportManager() { return getReactInstanceManager().getDevSupportManager(); }
public ExceptionsManagerModule(DevSupportManager devSupportManager) { mDevSupportManager = devSupportManager; }
public DevSupportManager getDevSupportManager() { return mDevSupportManager; }
private OpenStackFrameTask(DevSupportManager devSupportManager) { mDevSupportManager = devSupportManager; }
private CopyToHostClipBoardTask(DevSupportManager devSupportManager) { mDevSupportManager = devSupportManager; }