react-native-navigation的迁移库

RNNBottomTabsPresenter.m 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.boundViewController;
  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.boundViewController;
  17. RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
  18. [bottomTabs setTabBarTestID:[withDefault.bottomTabs.testID getWithDefaultValue:nil]];
  19. [bottomTabs setTabBarBackgroundColor:[withDefault.bottomTabs.backgroundColor getWithDefaultValue:nil]];
  20. [bottomTabs setTabBarTranslucent:[withDefault.bottomTabs.translucent getWithDefaultValue:NO]];
  21. [bottomTabs setTabBarHideShadow:[withDefault.bottomTabs.hideShadow getWithDefaultValue:NO]];
  22. [bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:[withDefault.bottomTabs.barStyle getWithDefaultValue:@"default"]]];
  23. [bottomTabs setTabBarVisible:[withDefault.bottomTabs.visible getWithDefaultValue:YES] animated:[withDefault.bottomTabs.animate getWithDefaultValue:NO]];
  24. [bottomTabs.view setBackgroundColor:[withDefault.layout.backgroundColor getWithDefaultValue:nil]];
  25. }
  26. - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)currentOptions {
  27. [super mergeOptions:options resolvedOptions:currentOptions];
  28. UITabBarController *bottomTabs = self.boundViewController;
  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. [bottomTabs 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)viewDidLayoutSubviews {
  64. dispatch_async(dispatch_get_main_queue(), ^{
  65. [self applyDotIndicator];
  66. });
  67. }
  68. - (void)applyDotIndicator {
  69. [self.boundViewController forEachChild:^(UIViewController *child) {
  70. [self applyDotIndicator:child];
  71. }];
  72. }
  73. @end