react-native-navigation的迁移库

RNNBottomTabsPresenter.m 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. if ([[withDefault.bottomTabs.titleDisplayMode getWithDefaultValue:@"alwaysShow"] isEqualToString:@"alwaysHide"]) {
  11. [bottomTabs centerTabItems];
  12. }
  13. }
  14. - (void)applyOptions:(RNNNavigationOptions *)options {
  15. UITabBarController *bottomTabs = self.boundViewController;
  16. RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
  17. [bottomTabs setTabBarTestID:[withDefault.bottomTabs.testID getWithDefaultValue:nil]];
  18. [bottomTabs setTabBarBackgroundColor:[withDefault.bottomTabs.backgroundColor getWithDefaultValue:nil]];
  19. [bottomTabs setTabBarTranslucent:[withDefault.bottomTabs.translucent getWithDefaultValue:NO]];
  20. [bottomTabs setTabBarHideShadow:[withDefault.bottomTabs.hideShadow getWithDefaultValue:NO]];
  21. [bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:[withDefault.bottomTabs.barStyle getWithDefaultValue:@"default"]]];
  22. [bottomTabs setTabBarVisible:[withDefault.bottomTabs.visible getWithDefaultValue:YES] animated:[withDefault.bottomTabs.animate getWithDefaultValue:NO]];
  23. }
  24. - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)currentOptions {
  25. [super mergeOptions:options resolvedOptions:currentOptions];
  26. UITabBarController *bottomTabs = self.boundViewController;
  27. if (options.bottomTabs.currentTabIndex.hasValue) {
  28. [bottomTabs setCurrentTabIndex:options.bottomTabs.currentTabIndex.get];
  29. [options.bottomTabs.currentTabIndex consume];
  30. }
  31. if (options.bottomTabs.currentTabId.hasValue) {
  32. [bottomTabs setCurrentTabID:options.bottomTabs.currentTabId.get];
  33. [options.bottomTabs.currentTabId consume];
  34. }
  35. if (options.bottomTabs.testID.hasValue) {
  36. [bottomTabs setTabBarTestID:options.bottomTabs.testID.get];
  37. }
  38. if (options.bottomTabs.backgroundColor.hasValue) {
  39. [bottomTabs setTabBarBackgroundColor:options.bottomTabs.backgroundColor.get];
  40. }
  41. if (options.bottomTabs.barStyle.hasValue) {
  42. [bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:options.bottomTabs.barStyle.get]];
  43. }
  44. if (options.bottomTabs.translucent.hasValue) {
  45. [bottomTabs setTabBarTranslucent:options.bottomTabs.translucent.get];
  46. }
  47. if (options.bottomTabs.hideShadow.hasValue) {
  48. [bottomTabs setTabBarHideShadow:options.bottomTabs.hideShadow.get];
  49. }
  50. if (options.bottomTabs.visible.hasValue) {
  51. if (options.bottomTabs.animate.hasValue) {
  52. [bottomTabs setTabBarVisible:options.bottomTabs.visible.get animated:[options.bottomTabs.animate getWithDefaultValue:NO]];
  53. } else {
  54. [bottomTabs setTabBarVisible:options.bottomTabs.visible.get animated:NO];
  55. }
  56. }
  57. }
  58. - (void)viewDidLayoutSubviews {
  59. dispatch_async(dispatch_get_main_queue(), ^{
  60. [self applyDotIndicator];
  61. });
  62. }
  63. - (void)applyDotIndicator {
  64. [self.boundViewController forEachChild:^(UIViewController *child) {
  65. [self applyDotIndicator:child];
  66. }];
  67. }
  68. @end