From 0c8eecf3fb3f0f4211198a156aaa1aed1be52b31 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Wed, 6 Dec 2023 18:12:13 +0800 Subject: [PATCH] Byline in grid cards, improve safe area handling --- .../Sources/App/PrimaryContentCategory.swift | 9 ---- .../Sources/App/Views/LibrarySplitView.swift | 1 + .../Sources/App/Views/LibraryTabView.swift | 3 +- .../App/Views/TabBar/CustomTabBar.swift | 2 +- .../Sources/Views/FeedItem/CardUtils.swift | 27 +++++++++++ .../Sources/Views/FeedItem/GridCard.swift | 46 ++++++++++++------- .../Views/FeedItem/LibraryItemCard.swift | 27 +---------- 7 files changed, 61 insertions(+), 54 deletions(-) create mode 100644 apple/OmnivoreKit/Sources/Views/FeedItem/CardUtils.swift diff --git a/apple/OmnivoreKit/Sources/App/PrimaryContentCategory.swift b/apple/OmnivoreKit/Sources/App/PrimaryContentCategory.swift index 73a5d0c1e..f2a7b0940 100644 --- a/apple/OmnivoreKit/Sources/App/PrimaryContentCategory.swift +++ b/apple/OmnivoreKit/Sources/App/PrimaryContentCategory.swift @@ -35,15 +35,6 @@ enum PrimaryContentCategory: Identifiable, Hashable, Equatable { Label { Text(title) } icon: { image.renderingMode(.template) } } - @MainActor @ViewBuilder var destinationView: some View { - switch self { - case .feed: - LibraryListView() - case .profile: - ProfileView() - } - } - func hash(into hasher: inout Hasher) { hasher.combine(id) } diff --git a/apple/OmnivoreKit/Sources/App/Views/LibrarySplitView.swift b/apple/OmnivoreKit/Sources/App/Views/LibrarySplitView.swift index 773338c9d..90e72d7f6 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LibrarySplitView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LibrarySplitView.swift @@ -39,6 +39,7 @@ public struct LibrarySplitView: View { HomeFeedContainerView(viewModel: inboxViewModel) .navigationViewStyle(.stack) + .navigationBarTitleDisplayMode(.inline) .tag("following") } .navigationBarTitleDisplayMode(.inline) diff --git a/apple/OmnivoreKit/Sources/App/Views/LibraryTabView.swift b/apple/OmnivoreKit/Sources/App/Views/LibraryTabView.swift index 85b8d63eb..fd36257a8 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LibraryTabView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LibraryTabView.swift @@ -55,11 +55,13 @@ struct LibraryTabView: View { TabView(selection: $selectedTab) { NavigationView { HomeFeedContainerView(viewModel: followingViewModel) + .navigationBarTitleDisplayMode(.inline) .navigationViewStyle(.stack) }.tag("following") NavigationView { HomeFeedContainerView(viewModel: libraryViewModel) + .navigationBarTitleDisplayMode(.inline) .navigationViewStyle(.stack) }.tag("inbox") @@ -84,7 +86,6 @@ struct LibraryTabView: View { .fullScreenCover(isPresented: $showExpandedAudioPlayer) { ExpandedAudioPlayer() } - .ignoresSafeArea() .navigationBarHidden(true) } } diff --git a/apple/OmnivoreKit/Sources/App/Views/TabBar/CustomTabBar.swift b/apple/OmnivoreKit/Sources/App/Views/TabBar/CustomTabBar.swift index 548f38689..5d32c63b9 100644 --- a/apple/OmnivoreKit/Sources/App/Views/TabBar/CustomTabBar.swift +++ b/apple/OmnivoreKit/Sources/App/Views/TabBar/CustomTabBar.swift @@ -10,7 +10,7 @@ struct CustomTabBar: View { TabBarButton(key: "profile", image: Image.tabProfile, selectedTab: $selectedTab) } .padding(.top, 10) - .padding(.bottom, 40) + .padding(.bottom, 10) .background(Color.themeTabBarColor) } } diff --git a/apple/OmnivoreKit/Sources/Views/FeedItem/CardUtils.swift b/apple/OmnivoreKit/Sources/Views/FeedItem/CardUtils.swift new file mode 100644 index 000000000..defdcd95e --- /dev/null +++ b/apple/OmnivoreKit/Sources/Views/FeedItem/CardUtils.swift @@ -0,0 +1,27 @@ + +import Foundation + +func cardShouldHideUrl(_ url: String?) -> Bool { + if let url = url, let origin = URL(string: url)?.host { + let hideHosts = ["storage.googleapis.com", "omnivore.app"] + if hideHosts.contains(origin) { + return true + } + } + + return false +} + +func cardSiteName(_ originalArticleUrl: String?) -> String? { + if cardShouldHideUrl(originalArticleUrl) { + return nil + } + + if let url = originalArticleUrl, + let originalHost = URL(string: url)?.host?.replacingOccurrences(of: "^www\\.", with: "", options: .regularExpression) + { + return originalHost + } + + return nil +} diff --git a/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift b/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift index 5ee53b457..17e4a1396 100644 --- a/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift +++ b/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift @@ -123,6 +123,34 @@ public struct GridCard: View { } } + var bylineStr: String { + // It seems like it could be cleaner just having author, instead of + // concating, maybe we fall back + if let author = item.author { + return author + } else if let publisherDisplayName = item.publisherDisplayName { + return publisherDisplayName + } + + return "" + } + + var byLine: some View { + if let origin = cardSiteName(item.pageURLString) { + Text(bylineStr + " | " + origin) + .font(.caption2) + .foregroundColor(Color.themeLibraryItemSubtle) + .frame(maxWidth: .infinity, alignment: .leading) + .lineLimit(1) + } else { + Text(bylineStr) + .font(.caption2) + .foregroundColor(Color.themeLibraryItemSubtle) + .frame(maxWidth: .infinity, alignment: .leading) + .lineLimit(1) + } + } + public var body: some View { GeometryReader { geo in VStack(alignment: .leading, spacing: 0) { @@ -138,23 +166,7 @@ public struct GridCard: View { .lineLimit(1) } - HStack { - if let author = item.author { - Text("by \(author)") - .font(.appCaptionTwo) - .foregroundColor(.appGrayText) - .lineLimit(1) - } - - if let publisherDisplayName = item.publisherDisplayName { - Text(publisherDisplayName) - .font(.appCaptionTwo) - .foregroundColor(.appGrayText) - .lineLimit(1) - } - - Spacer() - } + byLine } .frame(height: 30) .padding(.horizontal, 10) diff --git a/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift b/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift index af4885352..ac052ab9e 100644 --- a/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift +++ b/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift @@ -289,33 +289,8 @@ public struct LibraryItemCard: View { return "" } - func shouldHideUrl(_ url: String?) -> Bool { - if let url = url, let origin = URL(string: url)?.host { - let hideHosts = ["storage.googleapis.com", "omnivore.app"] - if hideHosts.contains(origin) { - return true - } - } - - return false - } - - func siteName(_ originalArticleUrl: String?) -> String? { - if shouldHideUrl(originalArticleUrl) { - return nil - } - - if let url = originalArticleUrl, - let originalHost = URL(string: url)?.host?.replacingOccurrences(of: "^www\\.", with: "", options: .regularExpression) - { - return originalHost - } - - return nil - } - var byLine: some View { - if let origin = siteName(item.pageURLString) { + if let origin = cardSiteName(item.pageURLString) { Text(bylineStr + " | " + origin) .font(.caption2) .foregroundColor(Color.themeLibraryItemSubtle)