react-native-navigation的迁移库

RNNTabBarPresenter.m 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #import "RNNTabBarPresenter.h"
  2. #import "UITabBarController+RNNOptions.h"
  3. #import "UIViewController+LayoutProtocol.h"
  4. #import "UIViewController+Utils.h"
  5. @implementation RNNTabBarPresenter
  6. -(instancetype)initWithDefaultOptions:(RNNNavigationOptions *)defaultOptions {
  7. self = [super initWithDefaultOptions:defaultOptions];
  8. return self;
  9. }
  10. - (void)applyOptionsOnInit:(RNNNavigationOptions *)options {
  11. UITabBarController *tabBarController = self.boundViewController;
  12. [tabBarController rnn_setCurrentTabIndex:[options.bottomTabs.currentTabIndex getWithDefaultValue:0]];
  13. }
  14. - (void)applyOptions:(RNNNavigationOptions *)options {
  15. UITabBarController *tabBarController = self.boundViewController;
  16. [tabBarController rnn_setTabBarTestID:[options.bottomTabs.testID getWithDefaultValue:nil]];
  17. [tabBarController rnn_setTabBarBackgroundColor:[options.bottomTabs.backgroundColor getWithDefaultValue:nil]];
  18. [tabBarController rnn_setTabBarTranslucent:[options.bottomTabs.translucent getWithDefaultValue:NO]];
  19. [tabBarController rnn_setTabBarHideShadow:[options.bottomTabs.hideShadow getWithDefaultValue:NO]];
  20. [tabBarController rnn_setTabBarStyle:[RCTConvert UIBarStyle:[options.bottomTabs.barStyle getWithDefaultValue:@"default"]]];
  21. [tabBarController rnn_setTabBarVisible:[options.bottomTabs.visible getWithDefaultValue:YES] animated:[options.bottomTabs.animate getWithDefaultValue:NO]];
  22. }
  23. - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions {
  24. [super mergeOptions:newOptions currentOptions:currentOptions];
  25. UITabBarController *tabBarController = self.boundViewController;
  26. if (newOptions.bottomTabs.currentTabIndex.hasValue) {
  27. [tabBarController rnn_setCurrentTabIndex:newOptions.bottomTabs.currentTabIndex.get];
  28. [newOptions.bottomTabs.currentTabIndex consume];
  29. }
  30. if (newOptions.bottomTabs.currentTabId.hasValue) {
  31. [tabBarController rnn_setCurrentTabID:newOptions.bottomTabs.currentTabId.get];
  32. [newOptions.bottomTabs.currentTabId consume];
  33. }
  34. if (newOptions.bottomTabs.testID.hasValue) {
  35. [tabBarController rnn_setTabBarTestID:newOptions.bottomTabs.testID.get];
  36. }
  37. if (newOptions.bottomTabs.backgroundColor.hasValue) {
  38. [tabBarController rnn_setTabBarBackgroundColor:newOptions.bottomTabs.backgroundColor.get];
  39. }
  40. if (newOptions.bottomTabs.barStyle.hasValue) {
  41. [tabBarController rnn_setTabBarStyle:[RCTConvert UIBarStyle:newOptions.bottomTabs.barStyle.get]];
  42. }
  43. if (newOptions.bottomTabs.translucent.hasValue) {
  44. [tabBarController rnn_setTabBarTranslucent:newOptions.bottomTabs.translucent.get];
  45. }
  46. if (newOptions.bottomTabs.hideShadow.hasValue) {
  47. [tabBarController rnn_setTabBarHideShadow:newOptions.bottomTabs.hideShadow.get];
  48. }
  49. if (newOptions.bottomTabs.visible.hasValue) {
  50. if (newOptions.bottomTabs.animate.hasValue) {
  51. [tabBarController rnn_setTabBarVisible:newOptions.bottomTabs.visible.get animated:[newOptions.bottomTabs.animate getWithDefaultValue:NO]];
  52. } else {
  53. [tabBarController rnn_setTabBarVisible:newOptions.bottomTabs.visible.get animated:NO];
  54. }
  55. }
  56. }
  57. - (void)viewDidLayoutSubviews {
  58. dispatch_async(dispatch_get_main_queue(), ^{
  59. [self applyDotIndicator];
  60. });
  61. }
  62. - (void)applyDotIndicator {
  63. [self.boundViewController forEachChild:^(UIViewController *child) {
  64. [self applyDotIndicator:child];
  65. }];
  66. }
  67. @end