package com.reactnativenavigation.react;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.view.KeyEvent;

import com.facebook.react.ReactInstanceManager;

public class JsDevReloadHandler {
	private static final String RELOAD_BROADCAST = "com.reactnativenavigation.broadcast.RELOAD";
	private final BroadcastReceiver reloadReceiver = new BroadcastReceiver() {
		@Override
		public void onReceive(final Context context, final Intent intent) {
			reloadReactNative();
		}
	};
	private final ReactInstanceManager reactInstanceManager;
	private long firstRTimestamp = 0;

	public JsDevReloadHandler(final ReactInstanceManager reactInstanceManager) {
		this.reactInstanceManager = reactInstanceManager;
	}

	public void onActivityResumed(Activity activity) {
		activity.registerReceiver(reloadReceiver, new IntentFilter(RELOAD_BROADCAST));
	}

	public void onActivityPaused(Activity activity) {
		activity.unregisterReceiver(reloadReceiver);
	}

	public boolean onKeyUp(int keyCode) {
		if (!reactInstanceManager.getDevSupportManager().getDevSupportEnabled()) {
			return false;
		}

		if (keyCode == KeyEvent.KEYCODE_MENU) {
			reactInstanceManager.getDevSupportManager().showDevOptionsDialog();
			return true;
		}

		if (keyCode == KeyEvent.KEYCODE_R) {
			if (lessThan500MillisSinceLastR()) {
				reloadReactNative();
				return true;
			}
			firstRTimestamp = System.currentTimeMillis();
		}
		return false;
	}

	private boolean lessThan500MillisSinceLastR() {
		return firstRTimestamp != 0 && System.currentTimeMillis() - firstRTimestamp < 1000;
	}

	private void reloadReactNative() {
		reactInstanceManager.getDevSupportManager().handleReloadJS();
	}
}

@@ -320,16 +320,86 @@
 ndler %7B%0A
+    public interface ReloadListener %7B%0A        void onReload();%0A    %7D%0A%0A
 %09private
@@ -767,24 +767,63 @@
 mp = 0;%0A
-%0A%09public
+    private ReloadListener reloadListener;%0A%0A   
  JsDevRe
@@ -937,24 +937,285 @@
 anager;%0A%09%7D%0A%0A
+    public void addReloadListener(ReloadListener listener) %7B%0A        reloadListener = listener;%0A    %7D%0A%0A    public void removeReloadListener(ReloadListener listener) %7B%0A        if (reloadListener == listener) %7B%0A            reloadListener = null;%0A        %7D%0A    %7D%0A%0A
 %09public void
@@ -2083,24 +2083,59 @@
 tNative() %7B%0A
+        reloadListener.onReload();%0A
 %09%09reactInsta

Support listening to reload events