react-native-navigation的迁移库

RNNSplitViewController.m 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #import "RNNSplitViewController.h"
  2. @implementation RNNSplitViewController
  3. - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo childViewControllers:(NSArray *)childViewControllers options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNSplitViewControllerPresenter *)presenter {
  4. self = [super init];
  5. self.defaultOptions = defaultOptions;
  6. self.options = options;
  7. self.presenter = presenter;
  8. [self.presenter bindViewController:self];
  9. [self.presenter applyOptionsOnInit:self.options];
  10. self.layoutInfo = layoutInfo;
  11. self.navigationController.delegate = self;
  12. [self bindChildViewControllers:childViewControllers];
  13. return self;
  14. }
  15. - (void)willMoveToParentViewController:(UIViewController *)parent {
  16. if (parent) {
  17. [_presenter applyOptionsOnWillMoveToParentViewController:self.resolveOptions];
  18. }
  19. }
  20. - (void)onChildWillAppear {
  21. [_presenter applyOptions:self.resolveOptions];
  22. [((UISplitViewController<RNNParentProtocol> *)self.parentViewController) onChildWillAppear];
  23. }
  24. - (RNNNavigationOptions *)resolveOptions {
  25. return [(RNNNavigationOptions *)[self.options mergeInOptions:self.getCurrentChild.resolveOptions.copy] withDefault:self.defaultOptions];
  26. }
  27. - (void)mergeOptions:(RNNNavigationOptions *)options {
  28. [_presenter mergeOptions:options currentOptions:self.options defaultOptions:self.defaultOptions];
  29. [((UISplitViewController<RNNLayoutProtocol> *)self.parentViewController) mergeOptions:options];
  30. }
  31. - (void)overrideOptions:(RNNNavigationOptions *)options {
  32. [self.options overrideOptions:options];
  33. }
  34. - (void)renderTreeAndWait:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
  35. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  36. dispatch_group_t group = dispatch_group_create();
  37. for (UIViewController<RNNLayoutProtocol>* childViewController in self.childViewControllers) {
  38. dispatch_group_enter(group);
  39. dispatch_async(dispatch_get_main_queue(), ^{
  40. [childViewController renderTreeAndWait:wait perform:^{
  41. dispatch_group_leave(group);
  42. }];
  43. });
  44. }
  45. dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
  46. dispatch_async(dispatch_get_main_queue(), ^{
  47. readyBlock();
  48. });
  49. });
  50. }
  51. - (void)bindChildViewControllers:(NSArray<UIViewController<RNNLayoutProtocol> *> *)viewControllers {
  52. [self setViewControllers:viewControllers];
  53. UIViewController<UISplitViewControllerDelegate>* masterViewController = viewControllers[0];
  54. self.delegate = masterViewController;
  55. }
  56. -(void)viewWillAppear:(BOOL)animated{
  57. [super viewWillAppear:animated];
  58. }
  59. - (UIViewController *)getCurrentChild {
  60. return self.viewControllers[0];
  61. }
  62. @end