From f7f37b47aced56566417084f2f64a81da3de5be9 Mon Sep 17 00:00:00 2001 From: hryeong66 Date: Tue, 6 Aug 2024 20:45:45 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20refresh=20=EB=90=A0=EB=95=8C=20?= =?UTF-8?q?=EB=B0=88=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=EC=95=88=EB=90=98=EB=8A=94=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/View/Meme/MemeListView.swift | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Projects/Core/DesignSystem/Sources/View/Meme/MemeListView.swift b/Projects/Core/DesignSystem/Sources/View/Meme/MemeListView.swift index c5cde64..371ff03 100644 --- a/Projects/Core/DesignSystem/Sources/View/Meme/MemeListView.swift +++ b/Projects/Core/DesignSystem/Sources/View/Meme/MemeListView.swift @@ -10,13 +10,6 @@ import PPACModels public struct MemeListView: View { @Binding var memeDetailList: [MemeDetail] - private let columns = Array( - repeating: GridItem( - .flexible(), - spacing: 12, - alignment: .center - ), count: 2 - ) private let memeClickHandler: ((MemeDetail) -> ())? private let memeCopyHandler: ((MemeDetail) -> ())? private let onAppearLastMemeHandler: (() -> ())? @@ -82,10 +75,13 @@ public struct MemeListView: View { } } } - // FIXME: pull to refresh 했을 때 onAppear가 호출되지 않아서 onChange로 임시 호출, 수정필요 -// .onChange(of: memeDetailList) { -// onAppearLastMemeHandler?() -// } + .onChange(of: memeDetailList, initial: false) { oldList, newList in + // refresh되면서 newList가 oldList보다 작아진 순간에만 호출되도록 + guard newList.count < oldList.count else { return } + if newList.contains(where: { $0.id == lastMemeId }) { + onAppearLastMemeHandler?() + } + } .frame(maxWidth: .infinity) } .scrollTargetBehavior(.viewAligned)