From 9bdc96c5671ae1b6b7c175e085f5e7e7dbc2439f Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Fri, 4 Mar 2022 15:51:13 -0800 Subject: [PATCH 1/5] add context menu to ios reader view --- .../App/Views/LinkItemDetailView.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift index 04f1e7e1c..337426600 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift @@ -169,6 +169,25 @@ struct LinkItemDetailView: View { ) .padding(.horizontal) .scaleEffect(navBarVisibilityRatio) + Menu( + content: { + Group { + Button( + action: {}, + label: { Label("Archive", systemImage: "archivebox") } + ) + Button( + action: {}, + label: { Label("Delete Link", systemImage: "trash") } + ) + } + }, + label: { + Image.profile + .padding(.horizontal) + .scaleEffect(navBarVisibilityRatio) + } + ) } .frame(height: readerViewNavBarHeight * navBarVisibilityRatio) .opacity(navBarVisibilityRatio) From 1ca25c87bd3e2954d4aadc5a6c1758e9cd105e01 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Sat, 5 Mar 2022 08:35:22 -0800 Subject: [PATCH 2/5] add pull to refresh for ipad grid view --- .../App/Views/Home/HomeFeedViewIOS.swift | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift index f4a82b029..43126d025 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift @@ -329,9 +329,21 @@ import Views } } .padding() - .background(Color(.systemGroupedBackground)) + .background( + GeometryReader { + Color(.systemGroupedBackground).preference( + key: ScrollViewOffsetPreferenceKey.self, + value: $0.frame(in: .global).origin.y + ) + } + ) + .onPreferenceChange(ScrollViewOffsetPreferenceKey.self) { offset in + if !viewModel.isLoading, abs(offset) > 240 { + viewModel.loadItems(dataService: dataService, searchQuery: searchQuery, isRefresh: true) + } + } - if viewModel.isLoading { + if viewModel.items.isEmpty, viewModel.isLoading { LoadingSection() } } @@ -339,3 +351,11 @@ import Views } #endif + +struct ScrollViewOffsetPreferenceKey: PreferenceKey { + typealias Value = CGFloat + static var defaultValue = CGFloat.zero + static func reduce(value: inout Value, nextValue: () -> Value) { + value += nextValue() + } +} From 35bd189e2ec9ef65b233063bc02c6b7bacaafdf3 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Sun, 6 Mar 2022 20:08:28 -0800 Subject: [PATCH 3/5] 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) } } From 2c1d010d6a7163f6448eba0dcbaa0e8f4e346cc7 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Mon, 7 Mar 2022 17:42:53 -0800 Subject: [PATCH 4/5] add a render ID to FeedItem to identify it in ForEach renders (solves stale item issue after refresh) --- .../App/Views/Home/Components/FeedCardNavigationLink.swift | 3 --- .../OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift | 4 ++-- .../Sources/App/Views/Home/HomeFeedViewModel.swift | 2 -- apple/OmnivoreKit/Sources/Models/FeedItem.swift | 1 + 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift index 502efbfc6..3d60094ff 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift @@ -53,9 +53,6 @@ struct GridCardNavigationLink: View { ) { EmptyView() } -// .onAppear { -// viewModel.itemAppeared(item: item, searchQuery: searchQuery, dataService: dataService) -// } GridCard(item: item, isContextMenuOpen: $isContextMenuOpen, actionHandler: actionHandler, tapAction: { withAnimation { scale = 0.95 diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift index 43126d025..cacd54ce8 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift @@ -301,7 +301,7 @@ import Views var body: some View { ScrollView { LazyVGrid(columns: columns, spacing: 20) { - ForEach(viewModel.items) { item in + ForEach(viewModel.items, id: \.renderID) { item in let link = GridCardNavigationLink( item: item, searchQuery: searchQuery, @@ -338,7 +338,7 @@ import Views } ) .onPreferenceChange(ScrollViewOffsetPreferenceKey.self) { offset in - if !viewModel.isLoading, abs(offset) > 240 { + if !viewModel.isLoading, offset > 240 { viewModel.loadItems(dataService: dataService, searchQuery: searchQuery, isRefresh: true) } } diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift index 540ae9399..1d7c11fed 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift @@ -27,10 +27,8 @@ 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) } } diff --git a/apple/OmnivoreKit/Sources/Models/FeedItem.swift b/apple/OmnivoreKit/Sources/Models/FeedItem.swift index 4b4010ab5..b61022b01 100644 --- a/apple/OmnivoreKit/Sources/Models/FeedItem.swift +++ b/apple/OmnivoreKit/Sources/Models/FeedItem.swift @@ -12,6 +12,7 @@ public struct HomeFeedData { public struct FeedItem: Identifiable, Hashable, Decodable { public let id: String + public let renderID = UUID() public let title: String public var readingProgress: Double public var readingProgressAnchor: Int From 0c4d68ae307316d05d58e382f4beba120380efc9 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Mon, 7 Mar 2022 17:45:45 -0800 Subject: [PATCH 5/5] create feature flag for showing menu options on link item detail view --- .../App/Views/LinkItemDetailView.swift | 38 ++++++++++--------- .../Sources/Utils/FeatureFlags.swift | 1 + 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift index 337426600..d6f276e69 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift @@ -169,25 +169,27 @@ struct LinkItemDetailView: View { ) .padding(.horizontal) .scaleEffect(navBarVisibilityRatio) - Menu( - content: { - Group { - Button( - action: {}, - label: { Label("Archive", systemImage: "archivebox") } - ) - Button( - action: {}, - label: { Label("Delete Link", systemImage: "trash") } - ) + if FeatureFlag.showLinkOptionsOnReaderView { + Menu( + content: { + Group { + Button( + action: {}, + label: { Label("Archive", systemImage: "archivebox") } + ) + Button( + action: {}, + label: { Label("Delete Link", systemImage: "trash") } + ) + } + }, + label: { + Image.profile + .padding(.horizontal) + .scaleEffect(navBarVisibilityRatio) } - }, - label: { - Image.profile - .padding(.horizontal) - .scaleEffect(navBarVisibilityRatio) - } - ) + ) + } } .frame(height: readerViewNavBarHeight * navBarVisibilityRatio) .opacity(navBarVisibilityRatio) diff --git a/apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift b/apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift index 67a1faf37..a5a911bd4 100644 --- a/apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift +++ b/apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift @@ -15,4 +15,5 @@ public enum FeatureFlag { public static let enableShareButton = false public static let enableSnooze = false public static let showFeedItemTags = false + public static let showLinkOptionsOnReaderView = false }