From 35bd189e2ec9ef65b233063bc02c6b7bacaafdf3 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Sun, 6 Mar 2022 20:08:28 -0800 Subject: [PATCH] move onAppear hook to grid item card --- .../Views/Home/Components/FeedCardNavigationLink.swift | 9 ++++++--- .../Sources/App/Views/Home/HomeFeedViewModel.swift | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift index 093310ca1..502efbfc6 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift @@ -53,9 +53,9 @@ struct GridCardNavigationLink: View { ) { EmptyView() } - .onAppear { - viewModel.itemAppeared(item: item, searchQuery: searchQuery, dataService: dataService) - } +// .onAppear { +// viewModel.itemAppeared(item: item, searchQuery: searchQuery, dataService: dataService) +// } GridCard(item: item, isContextMenuOpen: $isContextMenuOpen, actionHandler: actionHandler, tapAction: { withAnimation { scale = 0.95 @@ -65,6 +65,9 @@ struct GridCardNavigationLink: View { } } }) + .onAppear { + viewModel.itemAppeared(item: item, searchQuery: searchQuery, dataService: dataService) + } } .scaleEffect(scale) } diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift index 1d7c11fed..540ae9399 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift @@ -27,8 +27,10 @@ final class HomeFeedViewModel: ObservableObject { let itemIndex = items.firstIndex(where: { $0.id == item.id }) let thresholdIndex = items.index(items.endIndex, offsetBy: -5) + print("itemIndex", itemIndex) // Check if user has scrolled to the last five items in the list if let itemIndex = itemIndex, itemIndex > thresholdIndex, items.count < thresholdIndex + 10 { + print("loading more items") loadItems(dataService: dataService, searchQuery: searchQuery, isRefresh: false) } }