xiongzhu 3 年之前
父節點
當前提交
7794797456
共有 5 個文件被更改,包括 66 次插入8 次删除
  1. 1 0
      config.xml
  2. 4 4
      package-lock.json
  3. 2 2
      package.json
  4. 57 0
      scripts/android/fixNotch.js
  5. 2 2
      yarn.lock

+ 1 - 0
config.xml

@@ -39,6 +39,7 @@
 	<hook src="scripts/incrementBuildNum.js" type="after_prepare"/>
 	<platform name="android">
 		<hook type="after_plugin_install" src="scripts/android/fixQRScanner.js"/>
+		<hook type="after_plugin_install" src="scripts/android/fixNotch.js"/>
 		<hook type="after_prepare" src="scripts/android/leftShift2doLast.js"/>
 		<hook type="after_prepare" src="scripts/android/imageSaver.js"/>
 		<allow-intent href="market:*"/>

+ 4 - 4
package-lock.json

@@ -576,8 +576,8 @@
     },
     "node_modules/cordova-plugin-android-notch": {
       "version": "1.0.3",
-      "resolved": "https://registry.npmmirror.com/cordova-plugin-android-notch/download/cordova-plugin-android-notch-1.0.3.tgz",
-      "integrity": "sha1-plze5hj4KirR3Z7wp8M+SXFxUkg=",
+      "resolved": "https://registry.npmmirror.com/cordova-plugin-android-notch/-/cordova-plugin-android-notch-1.0.3.tgz",
+      "integrity": "sha512-4Nsqzrl26wzUAH4zSFY/RxLemxSqmi2Uppw1/Gyt0d2JMtJOW6aj9ZNLVUpFF8tqGmBsUJQi33/Z8JIpah9NDg==",
       "dev": true,
       "engines": {
         "cordovaDependencies": {
@@ -3496,8 +3496,8 @@
     },
     "cordova-plugin-android-notch": {
       "version": "1.0.3",
-      "resolved": "https://registry.npmmirror.com/cordova-plugin-android-notch/download/cordova-plugin-android-notch-1.0.3.tgz",
-      "integrity": "sha1-plze5hj4KirR3Z7wp8M+SXFxUkg=",
+      "resolved": "https://registry.npmmirror.com/cordova-plugin-android-notch/-/cordova-plugin-android-notch-1.0.3.tgz",
+      "integrity": "sha512-4Nsqzrl26wzUAH4zSFY/RxLemxSqmi2Uppw1/Gyt0d2JMtJOW6aj9ZNLVUpFF8tqGmBsUJQi33/Z8JIpah9NDg==",
       "dev": true
     },
     "cordova-plugin-appinfo": {

+ 2 - 2
package.json

@@ -54,7 +54,6 @@
       "cordova-plugin-code-push": {},
       "cordova-save-image-gallery": {},
       "cordova-plugin-remote-injection": {},
-      "cordova-plugin-android-notch": {},
       "cordova-plugin-appinfo": {},
       "cordova-plugin-purchase": {},
       "cordova-plugin-x-socialsharing": {
@@ -82,7 +81,8 @@
       },
       "cordova-plugin-inappbrowser": {},
       "cordova-plugin-cache-clear": {},
-      "cordova-plugin-umeng": {}
+      "cordova-plugin-umeng": {},
+      "cordova-plugin-android-notch": {}
     },
     "platforms": [
       "android",

+ 57 - 0
scripts/android/fixNotch.js

@@ -0,0 +1,57 @@
+const fs = require("fs");
+const path = require("path");
+const https = require("https");
+module.exports = function (context) {
+    if (
+        context.opts.plugin &&
+        context.opts.plugin.id === "cordova-plugin-android-notch"
+    ) {
+        const projectRoot = context.opts.projectRoot;
+
+        const cordovaCommon = context.requireCordovaModule("cordova-common");
+        const { ConfigParser } = cordovaCommon;
+        const appConfig = new ConfigParser(
+            path.resolve(projectRoot, "config.xml")
+        );
+
+        let projectName = appConfig.name();
+
+        const file = path.resolve(
+            projectRoot,
+            "platforms",
+            "android",
+            "app",
+            "src",
+            "main",
+            "java",
+            "com",
+            "tobspr",
+            "androidnotch",
+            "AndroidNotch.java"
+        );
+        if (fs.existsSync(file)) {
+            fs.writeFileSync(
+                file,
+                fs
+                    .readFileSync(file)
+                    .toString()
+                    .replaceAll(
+                        "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetLeft() / density) : 0));",
+                        "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetLeft() / density) : (insets.getStableInsetLeft() / density)));"
+                    )
+                    .replaceAll(
+                        "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetRight() / density) : 0));",
+                        "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetRight() / density) : (insets.getStableInsetRight() / density)));"
+                    )
+                    .replaceAll(
+                        "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetTop() / density) : 0));",
+                        "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetTop() / density) : (insets.getStableInsetTop() / density)));"
+                    )
+                    .replaceAll(
+                        "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetBottom() / density) : 0));",
+                        "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetBottom() / density) : (insets.getStableInsetBottom() / density)));"
+                    )
+            );
+        }
+    }
+};

+ 2 - 2
yarn.lock

@@ -331,8 +331,8 @@
     "xcode" "^2.0.0"
 
 "cordova-plugin-android-notch@^1.0.3":
-  "integrity" "sha1-plze5hj4KirR3Z7wp8M+SXFxUkg="
-  "resolved" "https://registry.npmmirror.com/cordova-plugin-android-notch/download/cordova-plugin-android-notch-1.0.3.tgz"
+  "integrity" "sha512-4Nsqzrl26wzUAH4zSFY/RxLemxSqmi2Uppw1/Gyt0d2JMtJOW6aj9ZNLVUpFF8tqGmBsUJQi33/Z8JIpah9NDg=="
+  "resolved" "https://registry.npmmirror.com/cordova-plugin-android-notch/-/cordova-plugin-android-notch-1.0.3.tgz"
   "version" "1.0.3"
 
 "cordova-plugin-appinfo@^2.1.2":