From 48dfbdd0f95e0df6afe683aa04112a98d35b62e0 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 22 Feb 2024 15:28:36 +0800 Subject: [PATCH] Fix observation of items for the grid --- .../App/Views/Home/HomeFeedViewIOS.swift | 32 +++++++++++-------- .../App/Views/Home/HomeFeedViewModel.swift | 2 +- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift index c581f6646..92438d1ac 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift @@ -530,8 +530,13 @@ struct AnimatingCellHeight: AnimatableModifier { ) } else { HomeFeedGridView( + listTitle: $listTitle, + isListScrolled: $isListScrolled, + prefersListLayout: $prefersListLayout, + isEditMode: $isEditMode, + selection: $selection, viewModel: viewModel, - isListScrolled: $isListScrolled + showFeatureCards: showFeatureCards ) } }.sheet(isPresented: $viewModel.showLabelsSheet) { @@ -574,10 +579,6 @@ struct AnimatingCellHeight: AnimatableModifier { .dynamicTypeSize(.small ... .accessibility1) } - func menuItems(for item: Models.LibraryItem) -> some View { - libraryItemMenu(dataService: dataService, viewModel: viewModel, item: item) - } - var featureCard: some View { VStack(spacing: 0) { if Color.isDarkMode { @@ -745,7 +746,7 @@ struct AnimatingCellHeight: AnimatableModifier { .listRowSeparatorTint(Color.thBorderColor) .listRowInsets(.init(top: 0, leading: horizontalInset, bottom: 10, trailing: horizontalInset)) .contextMenu { - menuItems(for: item) + libraryItemMenu(dataService: dataService, viewModel: viewModel, item: item) } .swipeActions(edge: .leading, allowsFullSwipe: true) { if let listConfig = viewModel.currentListConfig { @@ -938,11 +939,20 @@ struct AnimatingCellHeight: AnimatableModifier { @EnvironmentObject var dataService: DataService @EnvironmentObject var audioController: AudioController - @State var isContextMenuOpen = false + @Binding var listTitle: String + @Binding var isListScrolled: Bool + @Binding var prefersListLayout: Bool + @Binding var isEditMode: EditMode + @State private var showHideFeatureAlert = false + @Binding var selection: Set @ObservedObject var viewModel: HomeFeedViewModel - @Binding var isListScrolled: Bool + let showFeatureCards: Bool + + @State var shouldScrollToTop = false + @State var topItem: Models.LibraryItem? + @ObservedObject var networkMonitor = NetworkMonitor() func contextMenuActionHandler(item: Models.LibraryItem, action: GridCardAction) { switch action { @@ -972,10 +982,6 @@ struct AnimatingCellHeight: AnimatableModifier { .dynamicTypeSize(.small ... .accessibility1) } - func menuItems(for item: Models.LibraryItem) -> some View { - libraryItemMenu(dataService: dataService, viewModel: viewModel, item: item) - } - var body: some View { VStack(alignment: .leading) { Color.systemBackground.frame(height: 1) @@ -1018,7 +1024,7 @@ struct AnimatingCellHeight: AnimatableModifier { viewModel: viewModel ) .contextMenu { - menuItems(for: item) + libraryItemMenu(dataService: dataService, viewModel: viewModel, item: item) } .onAppear { if idx >= viewModel.fetcher.items.count - 5 { diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift index ceec00508..af5d6d68c 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift @@ -13,7 +13,7 @@ enum LoadingBarStyle { @MainActor final class HomeFeedViewModel: NSObject, ObservableObject { let filterKey: String - @Published var fetcher: LibraryItemFetcher + @ObservedObject var fetcher: LibraryItemFetcher let folderConfigs: [String: LibraryListConfig] @Published var isLoading = false