react-native-navigation的迁移库

RNNBottomTabsPresenter.m 3.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #import "RNNBottomTabsPresenter.h"
  2. #import "UITabBarController+RNNOptions.h"
  3. #import "UIViewController+LayoutProtocol.h"
  4. #import "UIViewController+Utils.h"
  5. @implementation RNNBottomTabsPresenter
  6. - (void)applyOptionsOnInit:(RNNNavigationOptions *)options {
  7. [super applyOptionsOnInit:options];
  8. UITabBarController *bottomTabs = self.tabBarController;
  9. RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
  10. [bottomTabs setCurrentTabIndex:[withDefault.bottomTabs.currentTabIndex getWithDefaultValue:0]];
  11. if ([[withDefault.bottomTabs.titleDisplayMode getWithDefaultValue:@"alwaysShow"] isEqualToString:@"alwaysHide"]) {
  12. [bottomTabs centerTabItems];
  13. }
  14. }
  15. - (void)applyOptions:(RNNNavigationOptions *)options {
  16. UITabBarController *bottomTabs = self.tabBarController;
  17. RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
  18. [bottomTabs setTabBarTestID:[withDefault.bottomTabs.testID getWithDefaultValue:nil]];
  19. [bottomTabs setTabBarVisible:[withDefault.bottomTabs.visible getWithDefaultValue:YES] animated:[withDefault.bottomTabs.animate getWithDefaultValue:NO]];
  20. [bottomTabs.view setBackgroundColor:[withDefault.layout.backgroundColor getWithDefaultValue:nil]];
  21. [self setTabBarBackgroundColor:[withDefault.bottomTabs.backgroundColor getWithDefaultValue:UIColor.whiteColor]];
  22. [bottomTabs setTabBarTranslucent:[withDefault.bottomTabs.translucent getWithDefaultValue:NO]];
  23. [bottomTabs setTabBarHideShadow:[withDefault.bottomTabs.hideShadow getWithDefaultValue:NO]];
  24. [bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:[withDefault.bottomTabs.barStyle getWithDefaultValue:@"default"]]];
  25. }
  26. - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)currentOptions {
  27. [super mergeOptions:options resolvedOptions:currentOptions];
  28. UITabBarController *bottomTabs = self.tabBarController;
  29. if (options.bottomTabs.currentTabIndex.hasValue) {
  30. [bottomTabs setCurrentTabIndex:options.bottomTabs.currentTabIndex.get];
  31. [options.bottomTabs.currentTabIndex consume];
  32. }
  33. if (options.bottomTabs.currentTabId.hasValue) {
  34. [bottomTabs setCurrentTabID:options.bottomTabs.currentTabId.get];
  35. [options.bottomTabs.currentTabId consume];
  36. }
  37. if (options.bottomTabs.testID.hasValue) {
  38. [bottomTabs setTabBarTestID:options.bottomTabs.testID.get];
  39. }
  40. if (options.bottomTabs.backgroundColor.hasValue) {
  41. [self setTabBarBackgroundColor:options.bottomTabs.backgroundColor.get];
  42. }
  43. if (options.bottomTabs.barStyle.hasValue) {
  44. [bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:options.bottomTabs.barStyle.get]];
  45. }
  46. if (options.bottomTabs.translucent.hasValue) {
  47. [bottomTabs setTabBarTranslucent:options.bottomTabs.translucent.get];
  48. }
  49. if (options.bottomTabs.hideShadow.hasValue) {
  50. [bottomTabs setTabBarHideShadow:options.bottomTabs.hideShadow.get];
  51. }
  52. if (options.bottomTabs.visible.hasValue) {
  53. if (options.bottomTabs.animate.hasValue) {
  54. [bottomTabs setTabBarVisible:options.bottomTabs.visible.get animated:[options.bottomTabs.animate getWithDefaultValue:NO]];
  55. } else {
  56. [bottomTabs setTabBarVisible:options.bottomTabs.visible.get animated:NO];
  57. }
  58. }
  59. if (options.layout.backgroundColor.hasValue) {
  60. [bottomTabs.view setBackgroundColor:options.layout.backgroundColor.get];
  61. }
  62. }
  63. - (void)setTabBarBackgroundColor:(UIColor *)backgroundColor {
  64. self.tabBar.barTintColor = backgroundColor;
  65. }
  66. - (UITabBarController *)tabBarController {
  67. return (UITabBarController *)self.boundViewController;
  68. }
  69. - (UITabBar *)tabBar {
  70. return self.tabBarController.tabBar;
  71. }
  72. @end