Skip to content

Commit

Permalink
feat: enable dev menu on Android (#602)
Browse files Browse the repository at this point in the history
Overridded method that is called on the key event on which the developer menu on Android should be opened. Change added only for debug mode. Should resolve #276.
Clicking cmd+m on macOS in debug mode should open the developer menu on Android, but Action Bar wants to handle that key event in order to trigger showOverflowMenu on the Toolbar. We then override this method and call React's showDevOptionsDialog in it.
  • Loading branch information
WoLewicki authored Aug 14, 2020
1 parent 49561e7 commit 218daa7
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;

import com.facebook.react.ReactApplication;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.views.text.ReactFontManager;

Expand Down Expand Up @@ -45,6 +46,19 @@ public class ScreenStackHeaderConfig extends ViewGroup {
private int mDefaultStartInset;
private int mDefaultStartInsetWithNavigation;

private static class DebugMenuToolbar extends Toolbar {

public DebugMenuToolbar(Context context) {
super(context);
}

@Override
public boolean showOverflowMenu() {
((ReactApplication) getContext().getApplicationContext()).getReactNativeHost().getReactInstanceManager().showDevOptionsDialog();
return true;
}
}

private OnClickListener mBackClickListener = new OnClickListener() {
@Override
public void onClick(View view) {
Expand All @@ -67,7 +81,7 @@ public ScreenStackHeaderConfig(Context context) {
super(context);
setVisibility(View.GONE);

mToolbar = new Toolbar(context);
mToolbar = BuildConfig.DEBUG ? new DebugMenuToolbar(context) : new Toolbar(context);
mDefaultStartInset = mToolbar.getContentInsetStart();
mDefaultStartInsetWithNavigation = mToolbar.getContentInsetStartWithNavigation();

Expand Down

0 comments on commit 218daa7

Please sign in to comment.