Sfoglia il codice sorgente

瀑布流效果横竖屏切换动态调整列数

onecold 11 mesi fa
parent
commit
748beefb6d
1 ha cambiato i file con 24 aggiunte e 4 eliminazioni
  1. 24 4
      entry/src/main/ets/view/LocalMusic.ets

+ 24 - 4
entry/src/main/ets/view/LocalMusic.ets

@@ -209,7 +209,7 @@ export struct LocalMusic {
   private listScroller: ListScroller = new ListScroller()
   private playListScroller: Scroller = new Scroller()
   @State isOneKeyTags:boolean = false
-  @StorageProp('isLandscape') isLandscape: boolean = false;
+  @StorageProp('isLandscape') @Watch('onIsLandscapeChange')  isLandscape: boolean = false;
   @StorageProp('topRectHeight') topRectHeight: number = px2vp(AppUtil.getStatusBarHeight());
   @StorageProp('windowWidth') windowWidth: number = 0;
   @StorageProp('windowHeight') windowHeight: number = 0;
@@ -225,6 +225,20 @@ export struct LocalMusic {
   @StorageProp('currentColorMode') @Watch('onColorModeChange') currentMode: number =
     ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET;
 
+  //瀑布流的列数横竖屏动态切换
+  onIsLandscapeChange() {
+   if(this.isLandscape){
+     this.columns = 4
+   }else{
+     let lastCount = AppStorage.get<number>('columnsCount');
+     if (typeof lastCount != 'undefined') {
+       this.columns = lastCount;
+     }else{
+       this.columns = 2;
+     }
+   }
+  }
+
   onColorModeChange() {
     this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
     if (this.isCustomizeBg) {
@@ -459,6 +473,10 @@ export struct LocalMusic {
 
   // 组件生命周期
   aboutToAppear() {
+    let lastCount = AppStorage.get<number>('columnsCount');
+    if (typeof lastCount != 'undefined') {
+      this.columns = lastCount;
+    }
     if(PreferencesUtil.getBooleanSync('isFirstTiped',true)){
       this.tipPopup = !this.tipPopup
       PreferencesUtil.putSync('isFirstTiped',false)
@@ -3687,7 +3705,9 @@ export struct LocalMusic {
 
           }
 
-          .height(this.columns == 4 ||this.columns==3? 40 : this.columns == 2 ? 48 : 58)
+          .height(this.columns == 4 ||this.columns==3? item.type==CommonConstants.TYPE_IS_DIR?30:40
+            : this.columns == 2 ?  (item.type==CommonConstants.TYPE_IS_DIR?38:48) :
+              (item.type==CommonConstants.TYPE_IS_DIR?48:58))
           .width('100%')
           .justifyContent(FlexAlign.Center)
           .margin({
@@ -4258,7 +4278,7 @@ export struct LocalMusic {
                 this.setEditStrEmpty()
                 this.tempLyricContent = await this.getLyricContent(item);
                 // console.info('onecold 长按this.tempLyricContent' +this.tempLyricContent)
-                if(this.isGridMusic){
+                if(this.isGridMusic||this.twoFingerType==4){
                   this.longItemFilePath = item.filePath
                 }else{
                   this.isShowEdit = !this.isShowEdit;
@@ -4315,7 +4335,7 @@ export struct LocalMusic {
               })
               .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
               .onClick(() => {
-                if(this.isGridMusic){
+                if(this.isGridMusic||this.twoFingerType==4){
                   this.longItemFilePathDetail = item.filePath
                 }else{
                   this.isShowDetail = !this.isShowDetail