react-native-navigation的迁移库

UIViewController+LayoutProtocol.m 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #import "UIViewController+LayoutProtocol.h"
  2. #import <objc/runtime.h>
  3. @implementation UIViewController (LayoutProtocol)
  4. - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
  5. creator:(id<RNNRootViewCreator>)creator
  6. options:(RNNNavigationOptions *)options
  7. defaultOptions:(RNNNavigationOptions *)defaultOptions
  8. presenter:(RNNBasePresenter *)presenter
  9. eventEmitter:(RNNEventEmitter *)eventEmitter
  10. childViewControllers:(NSArray *)childViewControllers {
  11. self = [self init];
  12. self.options = options;
  13. self.defaultOptions = defaultOptions;
  14. self.layoutInfo = layoutInfo;
  15. self.creator = creator;
  16. self.eventEmitter = eventEmitter;
  17. if ([self respondsToSelector:@selector(setViewControllers:)]) {
  18. [self performSelector:@selector(setViewControllers:) withObject:childViewControllers];
  19. }
  20. self.presenter = presenter;
  21. [self.presenter bindViewController:self];
  22. [self.presenter applyOptionsOnInit:self.resolveOptions];
  23. return self;
  24. }
  25. - (void)mergeOptions:(RNNNavigationOptions *)options {
  26. [self.presenter mergeOptions:options currentOptions:self.resolveOptions];
  27. [self.parentViewController mergeOptions:options];
  28. }
  29. - (RNNNavigationOptions *)resolveOptions {
  30. return (RNNNavigationOptions *) [self.options mergeInOptions:self.getCurrentChild.resolveOptions.copy];
  31. }
  32. - (void)overrideOptions:(RNNNavigationOptions *)options {
  33. [self.options overrideOptions:options];
  34. }
  35. - (void)renderTreeAndWait:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
  36. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  37. dispatch_group_t group = dispatch_group_create();
  38. for (UIViewController* childViewController in self.childViewControllers) {
  39. dispatch_group_enter(group);
  40. dispatch_async(dispatch_get_main_queue(), ^{
  41. [childViewController renderTreeAndWait:wait perform:^{
  42. dispatch_group_leave(group);
  43. }];
  44. });
  45. }
  46. dispatch_group_enter(group);
  47. [self.presenter renderComponents:self.resolveOptions perform:^{
  48. dispatch_group_leave(group);
  49. }];
  50. dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
  51. dispatch_async(dispatch_get_main_queue(), ^{
  52. readyBlock();
  53. });
  54. });
  55. }
  56. - (UIViewController *)getCurrentChild {
  57. return nil;
  58. }
  59. - (CGFloat)getTopBarHeight {
  60. return 0;
  61. }
  62. - (void)onChildWillAppear {
  63. [self.presenter applyOptions:self.resolveOptions];
  64. [((UISplitViewController *)self.parentViewController) onChildWillAppear];
  65. }
  66. - (void)willMoveToParentViewController:(UIViewController *)parent {
  67. if (parent) {
  68. [self.presenter applyOptionsOnWillMoveToParentViewController:self.resolveOptions];
  69. }
  70. }
  71. #pragma mark getters and setters to associated object
  72. - (RNNNavigationOptions *)options {
  73. return objc_getAssociatedObject(self, @selector(options));
  74. }
  75. - (void)setOptions:(RNNNavigationOptions *)options {
  76. objc_setAssociatedObject(self, @selector(options), options, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  77. }
  78. - (RNNNavigationOptions *)defaultOptions {
  79. return objc_getAssociatedObject(self, @selector(defaultOptions));
  80. }
  81. - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
  82. objc_setAssociatedObject(self, @selector(defaultOptions), defaultOptions, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  83. }
  84. - (RNNLayoutInfo *)layoutInfo {
  85. return objc_getAssociatedObject(self, @selector(layoutInfo));
  86. }
  87. - (void)setLayoutInfo:(RNNLayoutInfo *)layoutInfo {
  88. objc_setAssociatedObject(self, @selector(layoutInfo), layoutInfo, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  89. }
  90. - (RNNBasePresenter *)presenter {
  91. return objc_getAssociatedObject(self, @selector(presenter));
  92. }
  93. - (void)setPresenter:(RNNBasePresenter *)presenter {
  94. objc_setAssociatedObject(self, @selector(presenter), presenter, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  95. }
  96. - (RNNEventEmitter *)eventEmitter {
  97. return objc_getAssociatedObject(self, @selector(eventEmitter));
  98. }
  99. - (void)setEventEmitter:(RNNEventEmitter *)eventEmitter {
  100. objc_setAssociatedObject(self, @selector(eventEmitter), eventEmitter, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  101. }
  102. - (id<RNNRootViewCreator>)creator {
  103. return objc_getAssociatedObject(self, @selector(creator));
  104. }
  105. - (void)setCreator:(id<RNNRootViewCreator>)creator {
  106. objc_setAssociatedObject(self, @selector(creator), creator, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  107. }
  108. @end