RN-Androidがフルスクリーンかどうかを判断し、フルスクリーンを開いていますか?


RNScreenpxModule Androidのブリッジモジュールは、機種がフルスクリーンかどうかを判断し、フルスクリーンを開いているかを判断します.このモジュールを通じて、いくつかのRNの中の安卓全画のUI高さに適応します.
package com.regan.ebankhome;

import android.app.Activity;
import android.content.Context;
import android.graphics.Point;
import android.os.Build;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import androidx.core.content.ContextCompat;

import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.uimanager.IllegalViewOperationException;

import java.util.HashMap;
import java.util.Map;

public class RNScreenpxModule extends ReactContextBaseJavaModule {


    private int w = 0; //              
    private int h = 0; //              
    private volatile static boolean mHasCheckAllScreen;
    private volatile static boolean mIsAllScreenDevice;   //      
    private volatile static boolean notNavigationBarExist; //          (         )


    public RNScreenpxModule(ReactApplicationContext reactApplicationContext) {
        super(reactApplicationContext);

        WindowManager wd = (WindowManager) reactApplicationContext.getSystemService(Context.WINDOW_SERVICE);

        // 1.              
        w = RNScreenpxModule.getRealPXFromScreenW(reactApplicationContext);
        h = RNScreenpxModule.getRealPXFromScreenH(reactApplicationContext);

        // 2.         
        mIsAllScreenDevice = RNScreenpxModule.isAllScreenDevice(reactApplicationContext);
        Log.e("ssss", mIsAllScreenDevice + "===0===     ??????");

        if (mIsAllScreenDevice) {
            Log.e("ssss", notNavigationBarExist + "===0===     ??????");
            notNavigationBarExist = Settings.Global.getInt(reactApplicationContext.getContentResolver(), "force_fsg_nav_bar", 0) != 0;
            Log.e("ssss", notNavigationBarExist + "===0===     ??????");

        }


    }

    /**
     *              
     *
     * @param context
     */
    public static int getRealPXFromScreenH(Context context) {
        WindowManager wd = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display defaultDisplay = wd.getDefaultDisplay();
        Point point = new Point();
        defaultDisplay.getSize(point);
        int x = point.x;
        int y = point.y;
        return y;
    }


    /**
     *              
     *
     * @param context
     */
    public static int getRealPXFromScreenW(Context context) {
        WindowManager wd = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display defaultDisplay = wd.getDefaultDisplay();
        Point point = new Point();
        defaultDisplay.getSize(point);
        int x = point.x;
        int y = point.y;
        return x;
    }



    /**
     *              
     *
     * @param context
     * @return
     */
    public static boolean isAllScreenDevice(Context context) {
        if (mHasCheckAllScreen) {
            return mIsAllScreenDevice;
        }
        mHasCheckAllScreen = true;
        mIsAllScreenDevice = false;
        //    API 21 ,       。。。
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            return false;
        }
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        if (windowManager != null) {
            Display display = windowManager.getDefaultDisplay();
            Point point = new Point();
            display.getRealSize(point);
            float width, height;
            if (point.x < point.y) {
                width = point.x;
                height = point.y;
            } else {
                width = point.y;
                height = point.x;
            }
            if (height / width >= 1.97f) {
                mIsAllScreenDevice = true;
            }
        }
        return mIsAllScreenDevice;
    }


    /**
     *     JS        ,  "ScreenpxModule"
     *
     * @return
     */
    @Override
    public String getName() {
        return "ScreenpxModule";
    }


    /**
     *           
     *            JavaScript  ,Java        @ReactMethod
     *      JS    React.NativeModules.ScreenpxModule.getScreenW().then()...
     *
     * @param promise
     */
    @ReactMethod
    public void getScreenW(Promise promise) {
        promise.resolve(w);
    }

    @ReactMethod
    public void getScreenH(Promise promise) {
        promise.resolve(h);
    }

    @ReactMethod
    public void checkFullScreen(Promise promise) {

        Boolean fullScreenAndNotNavigationBarExist = mIsAllScreenDevice && notNavigationBarExist;

        //           
        if (fullScreenAndNotNavigationBarExist) {
            promise.resolve(true);
        } else {
            //                    
            promise.resolve(false);
        }
    }

}

使用
  componentDidMount() {
    !isiOS() ? LocalStoreUtils.isUseFullScreen_Android('get')
      .then((res) => {
        this.setState({chooseViewheight: res ? app.screenH : app.height});
      }) : null;

  }
export const height = Dimensions.get("window").height;
export const screenH = Dimensions.get("screen").height;