react-native-navigation的迁移库

RNNTabBarPresenter.m 3.4KB

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