Przeglądaj źródła

专辑返回到原来的scroll index

chendeben 1 rok temu
rodzic
commit
e5cf189b70
1 zmienionych plików z 24 dodań i 9 usunięć
  1. 24 9
      entry/src/main/ets/view/LocalMusic.ets

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

@@ -384,10 +384,15 @@ export struct LocalMusic {
       this.onModeChange()
       this.isCanBack = false
       this.titleBarModel.setLeftIconMain($r('app.media.menu'))
-      // 返回专辑列表时恢复滚动偏移量
+      // 返回专辑列表时恢复滚动偏移量,支持列表和网格
       setTimeout(() => {
-        let lastOffset = this.albumScrollMap.get('lastScrollOffset') ?? 0
-        this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
+        if (this.isGridMusic) {
+          let lastOffset = this.albumScrollMap.get('lastGridScrollOffset') ?? 0
+          this.scroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
+        } else {
+          let lastOffset = this.albumScrollMap.get('lastListScrollOffset') ?? 0
+          this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
+        }
       }, 200)
       return
     }
@@ -3799,15 +3804,25 @@ export struct LocalMusic {
 
         break;
       case CommonConstants.TYPE_IS_ALBUM:
-        // 进入专辑前安全保存当前滚动偏移量,防止currentOffset为undefined导致崩溃
+        // 进入专辑前安全保存当前滚动偏移量,支持列表和网格
         let offset = 0
-        if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
-          let cur = this.listScroller.currentOffset()
-          if (cur && typeof cur.yOffset === 'number') {
-            offset = cur.yOffset
+        if (this.isGridMusic) {
+          if (this.scroller && typeof this.scroller.currentOffset === 'function') {
+            let cur = this.scroller.currentOffset()
+            if (cur && typeof cur.yOffset === 'number') {
+              offset = cur.yOffset
+            }
+          }
+          this.albumScrollMap.set('lastGridScrollOffset', offset)
+        } else {
+          if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
+            let cur = this.listScroller.currentOffset()
+            if (cur && typeof cur.yOffset === 'number') {
+              offset = cur.yOffset
+            }
           }
+          this.albumScrollMap.set('lastListScrollOffset', offset)
         }
-        this.albumScrollMap.set('lastScrollOffset', offset)
         let albumList = this.albumMap.get(item.name)
         if (albumList !== undefined && ArrayUtil.isNotEmpty(albumList)) {
           Utility.doSortListAscending(albumList)