123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- //
- // WFCBaseTabBarController.m
- // Wildfire Chat
- //
- // Created by WF Chat on 2017/10/28.
- // Copyright © 2017年 WildFireChat. All rights reserved.
- //
- #import "WFCBaseTabBarController.h"
- #import <WFChatClient/WFCChatClient.h>
- #import <WFChatUIKit/WFChatUIKit.h>
- #import "DiscoverViewController.h"
- #import "WFCMeTableViewController.h"
- #import "WFCConfig.h"
- #ifdef WFC_MOMENTS
- #import <WFMomentUIKit/WFMomentUIKit.h>
- #import <WFMomentClient/WFMomentClient.h>
- #endif
- #import "UIImage+ERCategory.h"
- #define kClassKey @"rootVCClassString"
- #define kTitleKey @"title"
- #define kImgKey @"imageName"
- #define kSelImgKey @"selectedImageName"
- @interface WFCBaseTabBarController ()
- @property (nonatomic, strong)UINavigationController *firstNav;
- @property (nonatomic, strong)UINavigationController *settingNav;
- @end
- @implementation WFCBaseTabBarController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- UIViewController *vc = [WFCUConversationTableViewController new];
- vc.title = LocalizedString(@"Message");
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
- UITabBarItem *item = nav.tabBarItem;
- item.title = LocalizedString(@"Message");
- item.image = [UIImage imageNamed:@"tabbar_chat"];
- item.selectedImage = [[UIImage imageNamed:@"tabbar_chat_cover"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:0.1 green:0.27 blue:0.9 alpha:0.9]} forState:UIControlStateSelected];
- [self addChildViewController:nav];
-
- self.firstNav = nav;
-
-
- vc = [WFCUContactListViewController new];
- vc.title = LocalizedString(@"Contact");
- nav = [[UINavigationController alloc] initWithRootViewController:vc];
- item = nav.tabBarItem;
- item.title = LocalizedString(@"Contact");
- item.image = [UIImage imageNamed:@"tabbar_contacts"];
- item.selectedImage = [[UIImage imageNamed:@"tabbar_contacts_cover"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:0.1 green:0.27 blue:0.9 alpha:0.9]} forState:UIControlStateSelected];
- [self addChildViewController:nav];
-
- if(WORK_PLATFORM_URL.length) {
- WFCUBrowserViewController *browserVC = [WFCUBrowserViewController new];
- browserVC.url = WORK_PLATFORM_URL;
- browserVC.hidenOpenInBrowser = YES;
-
- vc = browserVC;
- vc.title = LocalizedString(@"Work");
- nav = [[UINavigationController alloc] initWithRootViewController:vc];
- item = nav.tabBarItem;
- item.title = LocalizedString(@"Work");
- item.image = [UIImage imageNamed:@"tabbar_work"];
- item.selectedImage = [[UIImage imageNamed:@"tabbar_work_cover"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:0.1 green:0.27 blue:0.9 alpha:0.9]} forState:UIControlStateSelected];
- [self addChildViewController:nav];
- }
-
- vc = [DiscoverViewController new];
- vc.title = LocalizedString(@"Discover");
- nav = [[UINavigationController alloc] initWithRootViewController:vc];
- item = nav.tabBarItem;
- item.title = LocalizedString(@"Discover");
- item.image = [UIImage imageNamed:@"tabbar_discover"];
- item.selectedImage = [[UIImage imageNamed:@"tabbar_discover_cover"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:0.1 green:0.27 blue:0.9 alpha:0.9]} forState:UIControlStateSelected];
- [self addChildViewController:nav];
-
- vc = [WFCMeTableViewController new];
- vc.title = LocalizedString(@"Me");
- nav = [[UINavigationController alloc] initWithRootViewController:vc];
- item = nav.tabBarItem;
- item.title = LocalizedString(@"Me");
- item.image = [UIImage imageNamed:@"tabbar_me"];
- item.selectedImage = [[UIImage imageNamed:@"tabbar_me_cover"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:0.1 green:0.27 blue:0.9 alpha:0.9]} forState:UIControlStateSelected];
- [self addChildViewController:nav];
- self.settingNav = nav;
- #ifdef WFC_MOMENTS
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUnreadCommentStatusChanged:) name:kReceiveComments object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUnreadCommentStatusChanged:) name:kClearUnreadComments object:nil];
- #endif
- }
- - (void)onUnreadCommentStatusChanged:(NSNotification *)notification {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self updateBadgeNumber];
- });
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self updateBadgeNumber];
- }
- - (void)updateBadgeNumber {
- #ifdef WFC_MOMENTS
- int momentIndex = 2;
- if(WORK_PLATFORM_URL.length)
- momentIndex = 3;
- [self.tabBar showBadgeOnItemIndex:momentIndex badgeValue:[[WFMomentService sharedService] getUnreadCount]];
- #endif
- }
- - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
- [super traitCollectionDidChange:previousTraitCollection];
- if (@available(iOS 13.0, *)) {
- if ([self.traitCollection hasDifferentColorAppearanceComparedToTraitCollection:previousTraitCollection]) {
- if([[UIApplication sharedApplication].delegate respondsToSelector:@selector(setupNavBar)]) {
- [[UIApplication sharedApplication].delegate performSelector:@selector(setupNavBar)];
- }
- UIView *superView = self.view.superview;
- [self.view removeFromSuperview];
- [superView addSubview:self.view];
- }
- }
- }
- @end
|