react-native-navigation的迁移库

RNNBottomTabsPresenter.m 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. }
  25. - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)currentOptions {
  26. [super mergeOptions:options resolvedOptions:currentOptions];
  27. UITabBarController *bottomTabs = self.boundViewController;
  28. if (options.bottomTabs.currentTabIndex.hasValue) {
  29. [bottomTabs setCurrentTabIndex:options.bottomTabs.currentTabIndex.get];
  30. [options.bottomTabs.currentTabIndex consume];
  31. }
  32. if (options.bottomTabs.currentTabId.hasValue) {
  33. [bottomTabs setCurrentTabID:options.bottomTabs.currentTabId.get];
  34. [options.bottomTabs.currentTabId consume];
  35. }
  36. if (options.bottomTabs.testID.hasValue) {
  37. [bottomTabs setTabBarTestID:options.bottomTabs.testID.get];
  38. }
  39. if (options.bottomTabs.backgroundColor.hasValue) {
  40. [bottomTabs setTabBarBackgroundColor:options.bottomTabs.backgroundColor.get];
  41. }
  42. if (options.bottomTabs.barStyle.hasValue) {
  43. [bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:options.bottomTabs.barStyle.get]];
  44. }
  45. if (options.bottomTabs.translucent.hasValue) {
  46. [bottomTabs setTabBarTranslucent:options.bottomTabs.translucent.get];
  47. }
  48. if (options.bottomTabs.hideShadow.hasValue) {
  49. [bottomTabs setTabBarHideShadow:options.bottomTabs.hideShadow.get];
  50. }
  51. if (options.bottomTabs.visible.hasValue) {
  52. if (options.bottomTabs.animate.hasValue) {
  53. [bottomTabs setTabBarVisible:options.bottomTabs.visible.get animated:[options.bottomTabs.animate getWithDefaultValue:NO]];
  54. } else {
  55. [bottomTabs setTabBarVisible:options.bottomTabs.visible.get animated:NO];
  56. }
  57. }
  58. }
  59. - (void)viewDidLayoutSubviews {
  60. dispatch_async(dispatch_get_main_queue(), ^{
  61. [self applyDotIndicator];
  62. });
  63. }
  64. - (void)applyDotIndicator {
  65. [self.boundViewController forEachChild:^(UIViewController *child) {
  66. [self applyDotIndicator:child];
  67. }];
  68. }
  69. @end