Skip to content

Instantly share code, notes, and snippets.

@dhrrgn
Last active May 20, 2021 21:05
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dhrrgn/16a8dfa7581a682627c6 to your computer and use it in GitHub Desktop.
Save dhrrgn/16a8dfa7581a682627c6 to your computer and use it in GitHub Desktop.
package com.yourapp.navbar;
import android.app.Activity;
import android.view.View;
import com.facebook.react.ReactActivity;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
public class NavigationBarAndroid extends ReactContextBaseJavaModule {
public NavigationBarAndroid(ReactApplicationContext reactContext) {
super(reactContext);
}
@Override
public String getName() {
return "NavigationBarAndroid";
}
@ReactMethod
public void hide() {
Activity reactActivity = getCurrentActivity();
if (reactActivity) {
View decorView = reactActivity.getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
}
}
package com.yourapp.navbar;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class NavigationBarAndroidPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new NavigationBarAndroid(reactContext));
return modules;
}
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
@Jijuan
Copy link

Jijuan commented Apr 16, 2017

line 25 in NavigationBarAndroid.java, should be changed to if(reactActivity != null).

@Jijuan
Copy link

Jijuan commented Apr 16, 2017

And, the method 'hide' sould be changed to use 'startActivityForResult'. This is because we use 'MainApplication' not 'MainActivity'.

@nateblog
Copy link

Hi good day, please help on how to implement the code properly. I am currently having an error under NavigationBarAndroidPackage.java line 25 saying it can not override.

@nateblog
Copy link

I managed to take away the error but still not working, the navigation is still showing

@Donhv
Copy link

Donhv commented Feb 26, 2018

@Jijuan can u show me full code NavigationBarAndroid.java

@vwnb
Copy link

vwnb commented May 23, 2018

@Jijuan I would also be very interested, if you have the time. Or anyone else who knows native Android code well enough to construct those changes? Blindly jumping into using startActivityForResult isn't yielding much result :(

@hto
Copy link

hto commented Mar 13, 2019

You can also try this. (I'm use React Native Wix Navigation V2.)
https://gist.github.com/hto/7ed5ef629bd8bdf651c73f3680541ad5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment