From ec6dce2991982edbb51295df5e772fc3dc18c008 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sun, 4 Jun 2023 15:13:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=AD=8C=E5=8D=95=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=AD=8C=E5=8D=95=E5=B0=81=E9=9D=A2=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 4 +++ .../SongList/components/Songlist/List.tsx | 36 ++++++++++++------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index 84903b4..5b2e7aa 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -1,3 +1,7 @@ +### 优化 + +- 优化歌单列表歌单封面大小计算方式 + ### 修复 - 修复wy歌单分类切换无效的问题 diff --git a/src/screens/Home/Views/SongList/components/Songlist/List.tsx b/src/screens/Home/Views/SongList/components/Songlist/List.tsx index 9416778..6c4da6b 100644 --- a/src/screens/Home/Views/SongList/components/Songlist/List.tsx +++ b/src/screens/Home/Views/SongList/components/Songlist/List.tsx @@ -58,7 +58,7 @@ export default forwardRef(({ onRefresh, onLoadMore, onOpenD @@ -103,20 +103,30 @@ export default forwardRef(({ onRefresh, onLoadMore, onOpenD // let itemWidth = Math.max(Math.trunc(width * 0.125), MAX_WIDTH) // // if (itemWidth < ) // }, [width]) - const itemWidth = useMemo(() => { - let w = width * 0.9 - GAP - let n = width / (MIN_WIDTH + GAP) - if (n > 10) n = 10 - return Math.floor(w / n) - }, [width]) + // const computedItemWidth = useMemo(() => { + // let w = width - GAP + // let n = width / (MIN_WIDTH + GAP) + // if (n > 10) n = 10 + // return Math.floor(w / n) + // }, [width]) // console.log(Math.trunc(width * 0.125), itemWidth) // console.log(itemWidth, MIN_WIDTH, GAP, width) - const rowNum = useMemo(() => Math.max(Math.floor(width / itemWidth), 2), [itemWidth, width]) + const rowInfo = useMemo(() => { + let w = width - GAP + let n = width / (MIN_WIDTH + GAP) + if (n > 10) n = 10 + let computedItemWidth = Math.floor(w / n) + const num = Math.max(Math.floor(width / computedItemWidth), 2) + return { + num, + width: (width - GAP) / num, + } + }, [width]) // console.log(rowNum) const list = useMemo(() => { const list = [...currentList] - let whiteItemNum = (list.length % rowNum) - if (whiteItemNum > 0) whiteItemNum = rowNum - whiteItemNum + let whiteItemNum = (list.length % rowInfo.num) + if (whiteItemNum > 0) whiteItemNum = rowInfo.num - whiteItemNum for (let i = 0; i < whiteItemNum; i++) { list.push({ id: `white__${i}`, @@ -130,7 +140,7 @@ export default forwardRef(({ onRefresh, onLoadMore, onOpenD }) } return list - }, [currentList, rowNum]) + }, [currentList, rowInfo]) // console.log(listInfo.list.map((item) => item.id)) return ( @@ -140,11 +150,11 @@ export default forwardRef(({ onRefresh, onLoadMore, onOpenD ? null : (