From b47197626804a742b8569cad50d5e0ed92fc765c Mon Sep 17 00:00:00 2001 From: "Devio.org" Date: Sun, 5 Dec 2021 22:33:15 +0800 Subject: [PATCH] Full screen adaptation. --- README.md | 3 ++- .../devio/rn/splashscreen/SplashScreen.java | 21 ++++++++++++++++--- package.json | 4 ++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index af58078b..9eb674f9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # react-native-splash-screen -[![Download](https://img.shields.io/badge/Download-v3.2.0-ff69b4.svg) ](https://www.npmjs.com/package/react-native-splash-screen) +[![Download](https://img.shields.io/badge/Download-v3.3.0-ff69b4.svg) ](https://www.npmjs.com/package/react-native-splash-screen) [ ![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg)](https://github.com/crazycodeboy/react-native-splash-screen/pulls) [ ![react-native-splash-screen release](https://img.shields.io/github/release/crazycodeboy/react-native-splash-screen.svg?maxAge=2592000?style=flat-square)](https://github.com/crazycodeboy/GitHubPopular/releases) [ ![语言 中文](https://img.shields.io/badge/语言-中文-feb252.svg)](https://github.com/crazycodeboy/react-native-splash-screen/blob/master/README.zh.md) @@ -280,6 +280,7 @@ export default class WelcomePage extends Component { | Method | Type | Optional | Description | |--------|----------|----------|-------------------------------------| | show() | function | false | Open splash screen (Native Method ) | +| show(final Activity activity, final boolean fullScreen) | function | false | Open splash screen (Native Method ) | | hide() | function | false | Close splash screen | ## Testing diff --git a/android/src/main/java/org/devio/rn/splashscreen/SplashScreen.java b/android/src/main/java/org/devio/rn/splashscreen/SplashScreen.java index bfba2e4b..f316efe8 100644 --- a/android/src/main/java/org/devio/rn/splashscreen/SplashScreen.java +++ b/android/src/main/java/org/devio/rn/splashscreen/SplashScreen.java @@ -3,6 +3,7 @@ import android.app.Activity; import android.app.Dialog; import android.os.Build; +import android.view.WindowManager; import java.lang.ref.WeakReference; @@ -21,7 +22,7 @@ public class SplashScreen { /** * 打开启动屏 */ - public static void show(final Activity activity, final int themeResId) { + public static void show(final Activity activity, final int themeResId, final boolean fullScreen) { if (activity == null) return; mActivity = new WeakReference(activity); activity.runOnUiThread(new Runnable() { @@ -31,7 +32,9 @@ public void run() { mSplashDialog = new Dialog(activity, themeResId); mSplashDialog.setContentView(R.layout.launch_screen); mSplashDialog.setCancelable(false); - + if (fullScreen) { + setActivityAndroidP(mSplashDialog); + } if (!mSplashDialog.isShowing()) { mSplashDialog.show(); } @@ -46,7 +49,7 @@ public void run() { public static void show(final Activity activity, final boolean fullScreen) { int resourceId = fullScreen ? R.style.SplashScreen_Fullscreen : R.style.SplashScreen_SplashTheme; - show(activity, resourceId); + show(activity, resourceId, fullScreen); } /** @@ -89,4 +92,16 @@ public void run() { } }); } + + private static void setActivityAndroidP(Dialog dialog) { + //设置全屏展示 + if (Build.VERSION.SDK_INT >= 28) { + if (dialog != null && dialog.getWindow() != null) { + dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);//全屏显示 + WindowManager.LayoutParams lp = dialog.getWindow().getAttributes(); + lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; + dialog.getWindow().setAttributes(lp); + } + } + } } diff --git a/package.json b/package.json index 004ae03e..be143cd7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-splash-screen", - "version": "3.2.0", + "version": "3.3.0", "description": "A splash screen for react-native, hide when application loaded ,it works on iOS and Android.", "main": "index.js", "scripts": { @@ -31,4 +31,4 @@ "react-native": ">=0.57.0" }, "homepage": "https://github.com/crazycodeboy/react-native-splash-screen#readme" -} +} \ No newline at end of file