WFCBaseTabBarController.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // WFCBaseTabBarController.m
  3. // Wildfire Chat
  4. //
  5. // Created by WF Chat on 2017/10/28.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCBaseTabBarController.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import <WFChatUIKit/WFChatUIKit.h>
  11. #import "DiscoverViewController.h"
  12. #import "WFCMeTableViewController.h"
  13. #import "WFCConfig.h"
  14. #ifdef WFC_MOMENTS
  15. #import <WFMomentUIKit/WFMomentUIKit.h>
  16. #import <WFMomentClient/WFMomentClient.h>
  17. #endif
  18. #import "UIImage+ERCategory.h"
  19. #define kClassKey @"rootVCClassString"
  20. #define kTitleKey @"title"
  21. #define kImgKey @"imageName"
  22. #define kSelImgKey @"selectedImageName"
  23. @interface WFCBaseTabBarController ()
  24. @property (nonatomic, strong)UINavigationController *firstNav;
  25. @property (nonatomic, strong)UINavigationController *settingNav;
  26. @end
  27. @implementation WFCBaseTabBarController
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. UIViewController *vc = [WFCUConversationTableViewController new];
  31. vc.title = LocalizedString(@"Message");
  32. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
  33. UITabBarItem *item = nav.tabBarItem;
  34. item.title = LocalizedString(@"Message");
  35. item.image = [UIImage imageNamed:@"tabbar_chat"];
  36. item.selectedImage = [[UIImage imageNamed:@"tabbar_chat_cover"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  37. [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:0.1 green:0.27 blue:0.9 alpha:0.9]} forState:UIControlStateSelected];
  38. [self addChildViewController:nav];
  39. self.firstNav = nav;
  40. vc = [WFCUContactListViewController new];
  41. vc.title = LocalizedString(@"Contact");
  42. nav = [[UINavigationController alloc] initWithRootViewController:vc];
  43. item = nav.tabBarItem;
  44. item.title = LocalizedString(@"Contact");
  45. item.image = [UIImage imageNamed:@"tabbar_contacts"];
  46. item.selectedImage = [[UIImage imageNamed:@"tabbar_contacts_cover"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  47. [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:0.1 green:0.27 blue:0.9 alpha:0.9]} forState:UIControlStateSelected];
  48. [self addChildViewController:nav];
  49. if(WORK_PLATFORM_URL.length) {
  50. WFCUBrowserViewController *browserVC = [WFCUBrowserViewController new];
  51. browserVC.url = WORK_PLATFORM_URL;
  52. browserVC.hidenOpenInBrowser = YES;
  53. vc = browserVC;
  54. vc.title = LocalizedString(@"Work");
  55. nav = [[UINavigationController alloc] initWithRootViewController:vc];
  56. item = nav.tabBarItem;
  57. item.title = LocalizedString(@"Work");
  58. item.image = [UIImage imageNamed:@"tabbar_work"];
  59. item.selectedImage = [[UIImage imageNamed:@"tabbar_work_cover"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  60. [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:0.1 green:0.27 blue:0.9 alpha:0.9]} forState:UIControlStateSelected];
  61. [self addChildViewController:nav];
  62. }
  63. vc = [DiscoverViewController new];
  64. vc.title = LocalizedString(@"Discover");
  65. nav = [[UINavigationController alloc] initWithRootViewController:vc];
  66. item = nav.tabBarItem;
  67. item.title = LocalizedString(@"Discover");
  68. item.image = [UIImage imageNamed:@"tabbar_discover"];
  69. item.selectedImage = [[UIImage imageNamed:@"tabbar_discover_cover"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  70. [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:0.1 green:0.27 blue:0.9 alpha:0.9]} forState:UIControlStateSelected];
  71. [self addChildViewController:nav];
  72. vc = [WFCMeTableViewController new];
  73. vc.title = LocalizedString(@"Me");
  74. nav = [[UINavigationController alloc] initWithRootViewController:vc];
  75. item = nav.tabBarItem;
  76. item.title = LocalizedString(@"Me");
  77. item.image = [UIImage imageNamed:@"tabbar_me"];
  78. item.selectedImage = [[UIImage imageNamed:@"tabbar_me_cover"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  79. [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:0.1 green:0.27 blue:0.9 alpha:0.9]} forState:UIControlStateSelected];
  80. [self addChildViewController:nav];
  81. self.settingNav = nav;
  82. #ifdef WFC_MOMENTS
  83. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUnreadCommentStatusChanged:) name:kReceiveComments object:nil];
  84. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUnreadCommentStatusChanged:) name:kClearUnreadComments object:nil];
  85. #endif
  86. }
  87. - (void)onUnreadCommentStatusChanged:(NSNotification *)notification {
  88. dispatch_async(dispatch_get_main_queue(), ^{
  89. [self updateBadgeNumber];
  90. });
  91. }
  92. - (void)viewWillAppear:(BOOL)animated {
  93. [super viewWillAppear:animated];
  94. [self updateBadgeNumber];
  95. }
  96. - (void)updateBadgeNumber {
  97. #ifdef WFC_MOMENTS
  98. int momentIndex = 2;
  99. if(WORK_PLATFORM_URL.length)
  100. momentIndex = 3;
  101. [self.tabBar showBadgeOnItemIndex:momentIndex badgeValue:[[WFMomentService sharedService] getUnreadCount]];
  102. #endif
  103. }
  104. - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
  105. [super traitCollectionDidChange:previousTraitCollection];
  106. if (@available(iOS 13.0, *)) {
  107. if ([self.traitCollection hasDifferentColorAppearanceComparedToTraitCollection:previousTraitCollection]) {
  108. if([[UIApplication sharedApplication].delegate respondsToSelector:@selector(setupNavBar)]) {
  109. [[UIApplication sharedApplication].delegate performSelector:@selector(setupNavBar)];
  110. }
  111. UIView *superView = self.view.superview;
  112. [self.view removeFromSuperview];
  113. [superView addSubview:self.view];
  114. }
  115. }
  116. }
  117. @end