react-native-safe-area-context icon indicating copy to clipboard operation
react-native-safe-area-context copied to clipboard

Add documentation to enable notch on android

Open nschild opened this issue 2 years ago • 4 comments

It might be convenient to include the needed android config to enable notches here

Add these lines to MainActivity.java

import android.view.WindowManager;
import android.os.Build;
import android.os.Bundle;

...
protected void onCreate(Bundle savedInstanceState) { <-- existing

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
            layoutParams.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
            getWindow().setAttributes(layoutParams);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }
        
        super.onCreate(savedInstanceState); <-- existing
        ...

Credit: https://dev.to/brunolemos/adding-notch-support-to-your-react-native-android-app-3ci3 https://stackoverflow.com/a/29311321

nschild avatar Sep 10 '21 21:09 nschild

For samsung not changes all headerTitle content on top screen

anatooly avatar Nov 25 '21 15:11 anatooly

Edit, this code works better.

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            Window w = getWindow();
            w.setStatusBarColor(Color.TRANSPARENT);
            w.setNavigationBarColor(Color.TRANSPARENT);
            w.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | 
View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    }

https://unicorn-utterances.com/posts/draw-under-navbar-using-react-native/

nschild avatar Jan 05 '22 20:01 nschild

Thank you so much for these links! I had a bad time trying to achive this.

andreav avatar Nov 07 '22 17:11 andreav

PRs would be really appreciated here

jacobp100 avatar Jan 19 '23 16:01 jacobp100