react-native-navigation的迁移库

RNNBottomTabsPresenter.m 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. UITabBarController *bottomTabs = self.boundViewController;
  8. RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
  9. [bottomTabs setCurrentTabIndex:[withDefault.bottomTabs.currentTabIndex getWithDefaultValue:0]];
  10. }
  11. - (void)applyOptions:(RNNNavigationOptions *)options {
  12. UITabBarController *bottomTabs = self.boundViewController;
  13. RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
  14. [bottomTabs setTabBarTestID:[withDefault.bottomTabs.testID getWithDefaultValue:nil]];
  15. [bottomTabs setTabBarBackgroundColor:[withDefault.bottomTabs.backgroundColor getWithDefaultValue:nil]];
  16. [bottomTabs setTabBarTranslucent:[withDefault.bottomTabs.translucent getWithDefaultValue:NO]];
  17. [bottomTabs setTabBarHideShadow:[withDefault.bottomTabs.hideShadow getWithDefaultValue:NO]];
  18. [bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:[withDefault.bottomTabs.barStyle getWithDefaultValue:@"default"]]];
  19. [bottomTabs setTabBarVisible:[withDefault.bottomTabs.visible getWithDefaultValue:YES] animated:[withDefault.bottomTabs.animate getWithDefaultValue:NO]];
  20. }
  21. - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)currentOptions {
  22. [super mergeOptions:options resolvedOptions:currentOptions];
  23. UITabBarController *bottomTabs = self.boundViewController;
  24. if (options.bottomTabs.currentTabIndex.hasValue) {
  25. [bottomTabs setCurrentTabIndex:options.bottomTabs.currentTabIndex.get];
  26. [options.bottomTabs.currentTabIndex consume];
  27. }
  28. if (options.bottomTabs.currentTabId.hasValue) {
  29. [bottomTabs setCurrentTabID:options.bottomTabs.currentTabId.get];
  30. [options.bottomTabs.currentTabId consume];
  31. }
  32. if (options.bottomTabs.testID.hasValue) {
  33. [bottomTabs setTabBarTestID:options.bottomTabs.testID.get];
  34. }
  35. if (options.bottomTabs.backgroundColor.hasValue) {
  36. [bottomTabs setTabBarBackgroundColor:options.bottomTabs.backgroundColor.get];
  37. }
  38. if (options.bottomTabs.barStyle.hasValue) {
  39. [bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:options.bottomTabs.barStyle.get]];
  40. }
  41. if (options.bottomTabs.translucent.hasValue) {
  42. [bottomTabs setTabBarTranslucent:options.bottomTabs.translucent.get];
  43. }
  44. if (options.bottomTabs.hideShadow.hasValue) {
  45. [bottomTabs setTabBarHideShadow:options.bottomTabs.hideShadow.get];
  46. }
  47. if (options.bottomTabs.visible.hasValue) {
  48. if (options.bottomTabs.animate.hasValue) {
  49. [bottomTabs setTabBarVisible:options.bottomTabs.visible.get animated:[options.bottomTabs.animate getWithDefaultValue:NO]];
  50. } else {
  51. [bottomTabs setTabBarVisible:options.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