徐勤民 8 bulan lalu
induk
melakukan
348174c4c8
2 mengubah file dengan 36 tambahan dan 3 penghapusan
  1. 6 3
      src/main/ets/utils/WindowHelper.ets
  2. 30 0
      src/main/ets/view/SafeView.ets

+ 6 - 3
src/main/ets/utils/WindowHelper.ets

@@ -78,9 +78,12 @@ export class WindowHelper {
     WindowHelper._windowClass = value;
     if (WindowHelper._windowClass) {
       let avoidArea = WindowHelper._windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR);
-      WindowHelper._bottomRectHeight = avoidArea.bottomRect.height
+      WindowHelper._bottomRectHeight = px2vp(avoidArea.bottomRect.height)
       let avoidArea2 = WindowHelper._windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_CUTOUT);
-      WindowHelper._topRectHeight = avoidArea2.topRect.height
+      WindowHelper._topRectHeight = px2vp(avoidArea2.topRect.height)
+      let avoidArea3 = WindowHelper._windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
+      const a = px2vp(avoidArea3.topRect.height)
+      WindowHelper._topRectHeight = a > WindowHelper._topRectHeight ? a : WindowHelper._topRectHeight
       // console.log('=====>', WindowHelper._topRectHeight)
     }
   }
@@ -106,7 +109,7 @@ export class WindowHelper {
    * @returns
    */
   public static get topRectHeight(): number {
-    return WindowHelper._isFullScreen?WindowHelper._topRectHeight:0
+    return WindowHelper._isFullScreen ? WindowHelper._topRectHeight : 0
   }
 
 

+ 30 - 0
src/main/ets/view/SafeView.ets

@@ -0,0 +1,30 @@
+@Preview
+@Component
+export struct SafeView {
+  @Link isLoading: boolean
+
+  @Builder
+  doNothingBuilder() {
+  }
+
+  @BuilderParam customBuilderParam: () => void = this.doNothingBuilder
+
+  build() {
+    Stack() {
+      this.customBuilderParam()
+      Column() {
+        LoadingProgress()
+          .color(Color.White)
+          .width(80).height(80)
+        Text('努力加载中..')
+          .fontSize(16)
+          .fontColor(Color.White)
+      }
+      .visibility(this.isLoading ? Visibility.Visible : Visibility.None)
+      .width('100%')
+      .height('100%')
+      .backgroundColor('#40000000')
+      .justifyContent(FlexAlign.Center)
+    }
+  }
+}