react-native-navigation的迁移库

RNNTabBarPresenter.m 3.5KB

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