From 16d6a835c03d30a833920cf0d6baf5e8b3fd2878 Mon Sep 17 00:00:00 2001 From: CMK Date: Tue, 20 Jul 2021 20:24:53 +0800 Subject: [PATCH] feat: adapt large content content viewer for tab bar item --- .../Scene/MainTab/MainTabBarController.swift | 17 ++++++++++++++++- .../ThemeService/ThemeService+Appearance.swift | 4 ++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Mastodon/Scene/MainTab/MainTabBarController.swift b/Mastodon/Scene/MainTab/MainTabBarController.swift index 5a85e872..1f9bcb57 100644 --- a/Mastodon/Scene/MainTab/MainTabBarController.swift +++ b/Mastodon/Scene/MainTab/MainTabBarController.swift @@ -42,6 +42,15 @@ class MainTabBarController: UITabBarController { case .me: return UIImage(systemName: "person.fill")! } } + + var largeImage: UIImage { + switch self { + case .home: return UIImage(systemName: "house.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: 80))! + case .search: return UIImage(systemName: "magnifyingglass", withConfiguration: UIImage.SymbolConfiguration(pointSize: 80))! + case .notification: return UIImage(systemName: "bell.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: 80))! + case .me: return UIImage(systemName: "person.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: 80))! + } + } func viewController(context: AppContext, coordinator: SceneCoordinator) -> UIViewController { let viewController: UIViewController @@ -112,13 +121,19 @@ extension MainTabBarController { let tabs = Tab.allCases let viewControllers: [UIViewController] = tabs.map { tab in let viewController = tab.viewController(context: context, coordinator: coordinator) - viewController.tabBarItem.title = "" // set text to empty string for image only style (SDK failed to layout when set to nil) + viewController.tabBarItem.title = tab.title viewController.tabBarItem.image = tab.image viewController.tabBarItem.accessibilityLabel = tab.title + viewController.tabBarItem.largeContentSizeImage = tab.largeImage + viewController.tabBarItem.imageInsets = UIEdgeInsets(top: 6, left: 0, bottom: -6, right: 0) return viewController } setViewControllers(viewControllers, animated: false) selectedIndex = 0 + + UITabBarItem.appearance().setTitleTextAttributes([.foregroundColor : UIColor.clear], for: .normal) + UITabBarItem.appearance().setTitleTextAttributes([.foregroundColor : UIColor.clear], for: .highlighted) + UITabBarItem.appearance().setTitleTextAttributes([.foregroundColor : UIColor.clear], for: .selected) context.apiService.error .receive(on: DispatchQueue.main) diff --git a/Mastodon/Service/ThemeService/ThemeService+Appearance.swift b/Mastodon/Service/ThemeService/ThemeService+Appearance.swift index da14a777..182fe870 100644 --- a/Mastodon/Service/ThemeService/ThemeService+Appearance.swift +++ b/Mastodon/Service/ThemeService/ThemeService+Appearance.swift @@ -30,6 +30,10 @@ extension ThemeService { tabBarAppearance.configureWithDefaultBackground() let tabBarItemAppearance = UITabBarItemAppearance() + tabBarItemAppearance.selected.titleTextAttributes = [.foregroundColor: UIColor.clear] + tabBarItemAppearance.focused.titleTextAttributes = [.foregroundColor: UIColor.clear] + tabBarItemAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.clear] + tabBarItemAppearance.disabled.titleTextAttributes = [.foregroundColor: UIColor.clear] tabBarItemAppearance.selected.iconColor = theme.tabBarItemSelectedIconColor tabBarItemAppearance.focused.iconColor = theme.tabBarItemFocusedIconColor tabBarItemAppearance.normal.iconColor = theme.tabBarItemNormalIconColor