From d96a8ca95c64e6ae0b946860b4bcf769cbbe6708 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Fri, 14 Jul 2023 16:45:52 +0800 Subject: [PATCH] Standardize menu across iPhone and iPad --- .../App/Views/Home/HomeFeedViewIOS.swift | 53 +++--------------- .../App/Views/Home/LibraryItemMenu.swift | 54 +++++++++++++++++++ .../Sources/Views/FeedItem/GridCard.swift | 9 ---- 3 files changed, 61 insertions(+), 55 deletions(-) create mode 100644 apple/OmnivoreKit/Sources/App/Views/Home/LibraryItemMenu.swift diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift index 24eb9c03b..64c401c32 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift @@ -317,50 +317,7 @@ struct AnimatingCellHeight: AnimatableModifier { } func menuItems(for item: LinkedItem) -> some View { - Group { - if item.state != "DELETED" { - Button( - action: { viewModel.itemUnderTitleEdit = item }, - label: { Label("Edit Info", systemImage: "info.circle") } - ) - Button( - action: { viewModel.itemUnderLabelEdit = item }, - label: { Label(item.labels?.count == 0 ? "Add Labels" : "Edit Labels", systemImage: "tag") } - ) - Button(action: { - withAnimation(.linear(duration: 0.4)) { - viewModel.setLinkArchived( - dataService: dataService, - objectID: item.objectID, - archived: !item.isArchived - ) - } - }, label: { - Label( - item.isArchived ? "Unarchive" : "Archive", - systemImage: item.isArchived ? "tray.and.arrow.down.fill" : "archivebox" - ) - }) - Button("Remove Item", role: .destructive) { - viewModel.removeLink(dataService: dataService, objectID: item.objectID) - } - if let author = item.author { - Button( - action: { - viewModel.searchTerm = "author:\"\(author)\"" - }, - label: { - Label(String("More by \(author)"), systemImage: "person") - } - ) - } - } else { - Button( - action: { viewModel.recoverItem(dataService: dataService, itemID: item.unwrappedID) }, - label: { Label("Recover", systemImage: "trash.slash") } - ) - } - } + libraryItemMenu(dataService: dataService, viewModel: viewModel, item: item) } var featureCard: some View { @@ -458,6 +415,7 @@ struct AnimatingCellHeight: AnimatableModifier { } var body: some View { + let horizontalInset = CGFloat(UIDevice.isIPad ? 20 : 10) VStack(spacing: 0) { if viewModel.showLoadingBar { ShimmeringLoader() @@ -468,7 +426,7 @@ struct AnimatingCellHeight: AnimatableModifier { List { filtersHeader .listRowSeparator(.hidden, edges: .all) - .listRowInsets(.init(top: 0, leading: 10, bottom: 0, trailing: 10)) + .listRowInsets(.init(top: 0, leading: horizontalInset, bottom: 0, trailing: horizontalInset)) if viewModel.listConfig.hasFeatureCards, !viewModel.hideFeatureSection, @@ -489,7 +447,7 @@ struct AnimatingCellHeight: AnimatableModifier { viewModel: viewModel ) .listRowSeparatorTint(Color.thBorderColor) - .listRowInsets(.init(top: 0, leading: 10, bottom: 10, trailing: 10)) + .listRowInsets(.init(top: 0, leading: horizontalInset, bottom: 10, trailing: horizontalInset)) .contextMenu { menuItems(for: item) } @@ -664,6 +622,9 @@ struct AnimatingCellHeight: AnimatableModifier { isContextMenuOpen: $isContextMenuOpen, viewModel: viewModel ) + .contextMenu { + libraryItemMenu(dataService: dataService, viewModel: viewModel, item: item) + } } Spacer() } diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/LibraryItemMenu.swift b/apple/OmnivoreKit/Sources/App/Views/Home/LibraryItemMenu.swift new file mode 100644 index 000000000..2c06ce60b --- /dev/null +++ b/apple/OmnivoreKit/Sources/App/Views/Home/LibraryItemMenu.swift @@ -0,0 +1,54 @@ +import CoreData +import Models +import Services +import SwiftUI +import UserNotifications +import Utils +import Views + +@MainActor func libraryItemMenu(dataService: DataService, viewModel: HomeFeedViewModel, item: LinkedItem) -> some View { + Group { + if item.state != "DELETED" { + Button( + action: { viewModel.itemUnderTitleEdit = item }, + label: { Label("Edit Info", systemImage: "info.circle") } + ) + Button( + action: { viewModel.itemUnderLabelEdit = item }, + label: { Label(item.labels?.count == 0 ? "Add Labels" : "Edit Labels", systemImage: "tag") } + ) + Button(action: { + withAnimation(.linear(duration: 0.4)) { + viewModel.setLinkArchived( + dataService: dataService, + objectID: item.objectID, + archived: !item.isArchived + ) + } + }, label: { + Label( + item.isArchived ? "Unarchive" : "Archive", + systemImage: item.isArchived ? "tray.and.arrow.down.fill" : "archivebox" + ) + }) + Button("Remove Item", role: .destructive) { + viewModel.removeLink(dataService: dataService, objectID: item.objectID) + } + if let author = item.author { + Button( + action: { + viewModel.searchTerm = "author:\"\(author)\"" + }, + label: { + Label(String("More by \(author)"), systemImage: "person") + } + ) + } + } else { + Button( + action: { viewModel.recoverItem(dataService: dataService, itemID: item.unwrappedID) }, + label: { Label("Recover", systemImage: "trash.slash") } + ) + } + } +} diff --git a/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift b/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift index cf3bb83ec..7228bc3b0 100644 --- a/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift +++ b/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift @@ -89,15 +89,6 @@ public struct GridCard: View { .font(.appHeadline) .foregroundColor(.appGrayTextContrast) .lineLimit(1) - // .onTapGesture { tapHandler() } - Spacer() - - Menu( - content: { contextMenuView }, - label: { Image(systemName: "ellipsis").padding() } - ) - .frame(width: 16, height: 16, alignment: .center) - .onTapGesture { isContextMenuOpen = true } } HStack {