From e11ada827727511e048f14df6e9d6e3eedc67231 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Wed, 11 Oct 2023 17:32:22 +0200 Subject: [PATCH] Show a little red badge when there are notifications (#1132) --- .../Scene/Root/MainTab/MainTabBarController.swift | 15 ++++++++------- .../Scene/Root/Sidebar/SidebarViewModel.swift | 14 +++++++------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Mastodon/Scene/Root/MainTab/MainTabBarController.swift b/Mastodon/Scene/Root/MainTab/MainTabBarController.swift index c74d05a4e..c6efa0857 100644 --- a/Mastodon/Scene/Root/MainTab/MainTabBarController.swift +++ b/Mastodon/Scene/Root/MainTab/MainTabBarController.swift @@ -231,14 +231,15 @@ extension MainTabBarController { let count = UserDefaults.shared.getNotificationCountWithAccessToken(accessToken: authentication.accessToken) return count > 0 } ?? false + + let image: UIImage + if hasUnreadPushNotification { + let imageConfiguration = UIImage.SymbolConfiguration(paletteColors: [.red, SystemTheme.tabBarItemNormalIconColor]) + image = UIImage(systemName: "bell.badge", withConfiguration: imageConfiguration)! + } else { + image = Tab.notifications.image + } - let image: UIImage = { - if hasUnreadPushNotification { - return UIImage(systemName: "bell.badge")! - } else { - return Tab.notifications.image - } - }() notificationViewController.tabBarItem.image = image.imageWithoutBaseline() notificationViewController.navigationController?.tabBarItem.image = image.imageWithoutBaseline() } diff --git a/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift b/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift index 6362cfe95..f3675799e 100644 --- a/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift +++ b/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift @@ -119,13 +119,13 @@ extension SidebarViewModel { return count > 0 }() - let image: UIImage = { - if hasUnreadPushNotification { - return UIImage(systemName: "bell.badge")! - } else { - return MainTabBarController.Tab.notifications.image - } - }() + let image: UIImage + if hasUnreadPushNotification { + let imageConfiguration = UIImage.SymbolConfiguration(paletteColors: [.red, SystemTheme.tabBarItemNormalIconColor]) + image = UIImage(systemName: "bell.badge", withConfiguration: imageConfiguration)! + } else { + image = MainTabBarController.Tab.notifications.image + } cell.item?.image = image cell.item?.activeImage = image.withTintColor(Asset.Colors.Brand.blurple.color, renderingMode: .alwaysOriginal) cell.setNeedsUpdateConfiguration()