From 35feaa9f8cebe0147689ea6e1335eac4d71470a1 Mon Sep 17 00:00:00 2001 From: Daniele Date: Tue, 15 Nov 2022 21:41:36 -0800 Subject: [PATCH] Add option to hide labels from tab bar --- Localizations/en.lproj/Localizable.strings | 1 + .../Sources/ServiceLayer/Utilities/AppPreferences.swift | 6 ++++++ View Controllers/ExploreViewController.swift | 3 ++- View Controllers/MainNavigationViewController.swift | 4 ++++ View Controllers/NotificationsViewController.swift | 5 +++++ View Controllers/TimelinesViewController.swift | 3 ++- Views/SwiftUI/PreferencesView.swift | 2 ++ 7 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Localizations/en.lproj/Localizable.strings b/Localizations/en.lproj/Localizable.strings index f7f6054..2ee0596 100644 --- a/Localizations/en.lproj/Localizable.strings +++ b/Localizations/en.lproj/Localizable.strings @@ -208,6 +208,7 @@ "preferences.blocked-domains" = "Blocked Domains"; "preferences.blocked-users" = "Blocked Users"; "preferences.media" = "Media"; +"preferences.show-labels-in-tab-bar" = "Show labels in tab bar (requires restart)"; "preferences.media.avatars" = "Avatars"; "preferences.media.avatars.animate" = "Animate avatars"; "preferences.media.avatars.animate.everywhere" = "Everywhere"; diff --git a/ServiceLayer/Sources/ServiceLayer/Utilities/AppPreferences.swift b/ServiceLayer/Sources/ServiceLayer/Utilities/AppPreferences.swift index 828fa03..c804843 100644 --- a/ServiceLayer/Sources/ServiceLayer/Utilities/AppPreferences.swift +++ b/ServiceLayer/Sources/ServiceLayer/Utilities/AppPreferences.swift @@ -201,6 +201,11 @@ public extension AppPreferences { get { self[.useUniversalLinks] ?? true } set { self[.useUniversalLinks] = newValue } } + + var showLabelsInTabBar: Bool { + get { self[.showLabelsInTabBar] ?? true } + set { self[.showLabelsInTabBar] = newValue } + } } private extension AppPreferences { @@ -223,6 +228,7 @@ private extension AppPreferences { case notificationSounds case openLinksInDefaultBrowser case useUniversalLinks + case showLabelsInTabBar } subscript(index: Item) -> T? { diff --git a/View Controllers/ExploreViewController.swift b/View Controllers/ExploreViewController.swift index 834bea3..a3e6a84 100644 --- a/View Controllers/ExploreViewController.swift +++ b/View Controllers/ExploreViewController.swift @@ -20,8 +20,9 @@ final class ExploreViewController: UICollectionViewController { super.init(collectionViewLayout: Self.layout()) + let showTabBarLabel = viewModel.identityContext.appPreferences.showLabelsInTabBar tabBarItem = UITabBarItem( - title: NSLocalizedString("main-navigation.explore", comment: ""), + title: showTabBarLabel ? NSLocalizedString("main-navigation.explore", comment: "") : nil, image: UIImage(systemName: "magnifyingglass"), selectedImage: nil) } diff --git a/View Controllers/MainNavigationViewController.swift b/View Controllers/MainNavigationViewController.swift index d37cffb..5d22b55 100644 --- a/View Controllers/MainNavigationViewController.swift +++ b/View Controllers/MainNavigationViewController.swift @@ -127,6 +127,10 @@ private extension MainNavigationViewController { conversationsViewController.tabBarItem = NavigationViewModel.Tab.messages.tabBarItem conversationsViewController.navigationItem.title = NavigationViewModel.Tab.messages.title + if !viewModel.identityContext.appPreferences.showLabelsInTabBar { + conversationsViewController.tabBarItem.title = nil + } + controllers.append(conversationsViewController) setupNewStatusButton() diff --git a/View Controllers/NotificationsViewController.swift b/View Controllers/NotificationsViewController.swift index adee07b..fb21d03 100644 --- a/View Controllers/NotificationsViewController.swift +++ b/View Controllers/NotificationsViewController.swift @@ -39,6 +39,11 @@ final class NotificationsViewController: UIPageViewController { } tabBarItem = NavigationViewModel.Tab.notifications.tabBarItem + + if !viewModel.identityContext.appPreferences.showLabelsInTabBar { + tabBarItem.title = nil + } + } @available(*, unavailable) diff --git a/View Controllers/TimelinesViewController.swift b/View Controllers/TimelinesViewController.swift index 6cfc4b9..e78f15b 100644 --- a/View Controllers/TimelinesViewController.swift +++ b/View Controllers/TimelinesViewController.swift @@ -36,8 +36,9 @@ final class TimelinesViewController: UIPageViewController { setViewControllers([firstViewController], direction: .forward, animated: false) } + let showTabBarLabel = viewModel.identityContext.appPreferences.showLabelsInTabBar tabBarItem = UITabBarItem( - title: NSLocalizedString("main-navigation.timelines", comment: ""), + title: showTabBarLabel ? NSLocalizedString("main-navigation.timelines", comment: "") : nil, image: UIImage(systemName: "newspaper"), selectedImage: nil) diff --git a/Views/SwiftUI/PreferencesView.swift b/Views/SwiftUI/PreferencesView.swift index 296e58d..ab3c404 100644 --- a/Views/SwiftUI/PreferencesView.swift +++ b/Views/SwiftUI/PreferencesView.swift @@ -113,6 +113,8 @@ struct PreferencesView: View { Toggle("preferences.links.use-universal-links", isOn: $identityContext.appPreferences.useUniversalLinks) } + Toggle("preferences.show-labels-in-tab-bar", + isOn: $identityContext.appPreferences.showLabelsInTabBar) } Group { Picker("preferences.media.autoplay.gifs",