react-native-navigation的迁移库

TopBarTitlePresenter.m 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #import "TopBarTitlePresenter.h"
  2. #import "UIViewController+RNNOptions.h"
  3. #import "RNNTitleViewHelper.h"
  4. #import "RNNReactTitleView.h"
  5. @implementation TopBarTitlePresenter {
  6. RNNReactTitleView* _customTitleView;
  7. RNNTitleViewHelper* _titleViewHelper;
  8. }
  9. - (void)applyOptions:(RNNTopBarOptions *)options {
  10. [self updateTitleWithOptions:options];
  11. }
  12. - (void)updateTitleWithOptions:(RNNTopBarOptions *)options {
  13. if (options.title.component.hasValue) {
  14. [self setCustomNavigationTitleView:options perform:nil];
  15. }else if (options.subtitle.text.hasValue) {
  16. [self setTitleViewWithSubtitle:options];
  17. }else if (options.title.text.hasValue) {
  18. [self removeTitleComponents];
  19. self.boundViewController.navigationItem.title = options.title.text.get;
  20. }
  21. }
  22. - (void)mergeOptions:(RNNTopBarOptions *)options resolvedOptions:(RNNTopBarOptions *)resolvedOptions {
  23. [self updateTitleWithOptions:options];
  24. }
  25. - (void)setTitleViewWithSubtitle:(RNNTopBarOptions *)options {
  26. if (!_customTitleView && ![options.largeTitle.visible getWithDefaultValue:NO]) {
  27. _titleViewHelper = [[RNNTitleViewHelper alloc] initWithTitleViewOptions:options.title subTitleOptions:options.subtitle viewController:self.boundViewController];
  28. if (options.title.text.hasValue) {
  29. [_titleViewHelper setTitleOptions:options.title];
  30. }
  31. if (options.subtitle.text.hasValue) {
  32. [_titleViewHelper setSubtitleOptions:options.subtitle];
  33. }
  34. [_titleViewHelper setup];
  35. }
  36. }
  37. - (void)renderComponents:(RNNTopBarOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
  38. [self setCustomNavigationTitleView:options perform:readyBlock];
  39. }
  40. - (void)setCustomNavigationTitleView:(RNNTopBarOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
  41. UIViewController<RNNLayoutProtocol>* viewController = self.boundViewController;
  42. if (![options.title.component.waitForRender getWithDefaultValue:NO] && readyBlock) {
  43. readyBlock();
  44. readyBlock = nil;
  45. }
  46. if (options.title.component.name.hasValue) {
  47. _customTitleView = (RNNReactTitleView *)[self.componentRegistry createComponentIfNotExists:options.title.component parentComponentId:viewController.layoutInfo.componentId componentType:RNNComponentTypeTopBarTitle reactViewReadyBlock:readyBlock];
  48. _customTitleView.backgroundColor = UIColor.clearColor;
  49. NSString* alignment = [options.title.component.alignment getWithDefaultValue:@""];
  50. [_customTitleView setAlignment:alignment inFrame:viewController.navigationController.navigationBar.frame];
  51. [_customTitleView layoutIfNeeded];
  52. viewController.navigationItem.titleView = nil;
  53. viewController.navigationItem.titleView = _customTitleView;
  54. [_customTitleView componentDidAppear];
  55. } else {
  56. [_customTitleView removeFromSuperview];
  57. if (readyBlock) {
  58. readyBlock();
  59. }
  60. }
  61. }
  62. - (void)removeTitleComponents {
  63. [_customTitleView componentDidDisappear];
  64. [_customTitleView removeFromSuperview];
  65. _customTitleView = nil;
  66. self.boundViewController.navigationItem.titleView = nil;
  67. }
  68. - (void)componentDidAppear {
  69. [_customTitleView componentDidAppear];
  70. }
  71. - (void)componentDidDisappear {
  72. [_customTitleView componentDidDisappear];
  73. }
  74. @end