Ver código fonte

避让航栏和状态栏的获取逻辑优化

onecold 1 ano atrás
pai
commit
5247f6c855

+ 2 - 2
build-profile.json5

@@ -30,11 +30,11 @@
         "material": {
           "certpath": "C:\\Users\\xjy08\\.ohos\\config\\default_com.xgplayer.ttmusic.hm4_li00v0NJ2KHEZXa_MEhSBo4Q7SMa2KHpzKM8lnBZT1Y=.cer",
           "keyAlias": "debugKey",
-          "keyPassword": "0000001B29B765FED2070C793D78E2881AEEC8526F57C200F5CEA8D9D0800526063FAE9F272770E638B009",
+          "keyPassword": "0000001BA5BA8BCF0397D117A6121CDBD529A90551EA8AEFCA65626E2F75F588C790AB168F039C8B72A189",
           "profile": "C:\\Users\\xjy08\\.ohos\\config\\default_com.xgplayer.ttmusic.hm4_li00v0NJ2KHEZXa_MEhSBo4Q7SMa2KHpzKM8lnBZT1Y=.p7b",
           "signAlg": "SHA256withECDSA",
           "storeFile": "C:\\Users\\xjy08\\.ohos\\config\\default_com.xgplayer.ttmusic.hm4_li00v0NJ2KHEZXa_MEhSBo4Q7SMa2KHpzKM8lnBZT1Y=.p12",
-          "storePassword": "0000001BE6DE18C77DCD180738D43C3BC0DC4185EC14C2E0CD4965449D6D02D6B73C246C8100854CC5A55D"
+          "storePassword": "0000001B28EBE7DDAD6E1F57270962ACCF1B34838A418C7AFCBE02A07F06F24182D53A18CADBF33380DB17"
         }
       }
     ]

+ 20 - 8
entry/src/main/ets/entryability/EntryAbility.ets

@@ -60,12 +60,13 @@ export default class EntryAbility extends UIAbility {
 
 
     onAvoidAreaChange = (data: window.AvoidAreaOptions) => {
-
-       let topRectHeight =  px2vp(data.area.topRect.height);
-       AppStorage.setOrCreate('topRectHeight', topRectHeight);
-        LogUtil.info('onecold onAvoidAreaChange topRectHeight = '+topRectHeight);
-       let bottomRectHeight =  px2vp(data.area.bottomRect.height);
-       AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight);
+        if (data.type === window.AvoidAreaType.TYPE_SYSTEM) {
+            let topRectHeight =  px2vp(data.area.topRect.height);
+            AppStorage.setOrCreate('topRectHeight', topRectHeight);
+        } else if (data.type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) {
+            let bottomRectHeight = px2vp(data.area.bottomRect.height);
+            AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight);
+        }
 
     }
 
@@ -162,9 +163,20 @@ export default class EntryAbility extends UIAbility {
             }).catch((e: BusinessError) => {
                 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(e));
             })
-            let avoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM)
-            let topRectHeight =  px2vp(avoidArea.topRect.height);
+            // let avoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM)
+            // let topRectHeight =  px2vp(avoidArea.topRect.height);
+            // AppStorage.setOrCreate('topRectHeight', topRectHeight);
+
+            let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; // 以导航条避让为例
+            let avoidArea = windowClass.getWindowAvoidArea(type);
+            let bottomRectHeight = px2vp(avoidArea.bottomRect.height); // 获取到导航条区域的高度
+            AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight);
+
+            type = window.AvoidAreaType.TYPE_SYSTEM; // 以状态栏避让为例
+            avoidArea = windowClass.getWindowAvoidArea(type);
+            let topRectHeight = px2vp(avoidArea.topRect.height) // 获取状态栏区域高度
             AppStorage.setOrCreate('topRectHeight', topRectHeight);
+
             LogUtil.info('onecold  topRectHeight = '+topRectHeight);
             windowClass.on('avoidAreaChange', this.onAvoidAreaChange)
         })

+ 45 - 0
entry/src/main/ets/pages/Demo.ets

@@ -0,0 +1,45 @@
+@Entry
+@Component
+struct Demo {
+  @State message: string = 'Hello World'
+  @State location: number = 0.0
+  @State leftlocation: number = -0.1
+  @State rightlocation: number = 0.1
+
+  // 配置渐变色起始点位周期性移动
+  aboutToAppear(): void {
+    setInterval(() => {
+      this.location += 0.01
+      this.leftlocation += 0.01
+      this.rightlocation += 0.01
+      if (this.location >= 1) {
+        this.location = 0.0
+        this.leftlocation = -0.1
+        this.rightlocation = 0.1
+      }
+    }, 50)
+  }
+
+  build() {
+    Column({ space: 5 }) {
+      Row() {
+        Text(this.message)
+          .maxLines(1)
+          .fontSize(40)
+          .fontWeight(800)
+          .fontColor(Color.White)
+          .padding(10)
+          .blendMode(BlendMode.DST_IN, BlendApplyType.OFFSCREEN) // 设置混合模式
+      }
+      .linearGradient({
+        angle: 110,
+        colors: [[Color.White, this.leftlocation], [Color.Orange, this.location],
+          [Color.White, this.rightlocation]] // 设置渐变色起始点位
+      })
+      .blendMode(BlendMode.SRC_OVER, BlendApplyType.OFFSCREEN)
+    }
+    .width('100%')
+    .backgroundColor(Color.Black)
+    .justifyContent(FlexAlign.Center)
+  }
+}

+ 2 - 1
entry/src/main/resources/base/profile/main_pages.json

@@ -9,6 +9,7 @@
     "pages/SettingPage",
     "pages/VipPage",
     "pages/ScanFilePage",
-    "pages/UserCenter"
+    "pages/UserCenter",
+    "pages/Demo"
   ]
 }