123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
-
- #import "UIViewController+LayoutProtocol.h"
- #import <objc/runtime.h>
-
- @implementation UIViewController (LayoutProtocol)
-
- - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
- creator:(id<RNNComponentViewCreator>)creator
- options:(RNNNavigationOptions *)options
- defaultOptions:(RNNNavigationOptions *)defaultOptions
- presenter:(RNNBasePresenter *)presenter
- eventEmitter:(RNNEventEmitter *)eventEmitter
- childViewControllers:(NSArray *)childViewControllers {
- self = [self init];
-
- self.options = options;
- self.defaultOptions = defaultOptions;
- self.layoutInfo = layoutInfo;
- self.creator = creator;
- self.eventEmitter = eventEmitter;
- if ([self respondsToSelector:@selector(setViewControllers:)]) {
- [self performSelector:@selector(setViewControllers:) withObject:childViewControllers];
- }
- self.presenter = presenter;
- [self.presenter boundViewController:self];
- [self.presenter applyOptionsOnInit:self.resolveOptions];
-
- return self;
- }
-
- - (void)mergeOptions:(RNNNavigationOptions *)options {
- [self.options overrideOptions:options];
- [self.presenter mergeOptions:options resolvedOptions:self.resolveOptions];
- [self.parentViewController mergeChildOptions:options];
- }
-
- - (void)mergeChildOptions:(RNNNavigationOptions *)options {
- [self.presenter mergeOptions:options resolvedOptions:self.resolveOptions];
- [self.parentViewController mergeChildOptions:options];
- }
-
- - (RNNNavigationOptions *)resolveOptions {
- return (RNNNavigationOptions *) [self.options mergeInOptions:self.getCurrentChild.resolveOptions.copy];
- }
-
- - (void)overrideOptions:(RNNNavigationOptions *)options {
- [self.options overrideOptions:options];
- }
-
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
- UIInterfaceOrientationMask interfaceOrientationMask = self.presenter ? [self.presenter getOrientation:[self resolveOptions]] : [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[[UIApplication sharedApplication] keyWindow]];
- return interfaceOrientationMask;
- }
-
- - (void)renderTreeAndWait:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
- dispatch_group_t group = dispatch_group_create();
- for (UIViewController* childViewController in self.childViewControllers) {
- dispatch_group_enter(group);
- dispatch_async(dispatch_get_main_queue(), ^{
- [childViewController renderTreeAndWait:wait perform:^{
- dispatch_group_leave(group);
- }];
- });
- }
-
- dispatch_group_enter(group);
- [self.presenter renderComponents:self.resolveOptions perform:^{
- dispatch_group_leave(group);
- }];
- dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
-
- dispatch_async(dispatch_get_main_queue(), ^{
- readyBlock();
- });
- });
- }
-
- - (UIViewController *)getCurrentChild {
- return nil;
- }
-
- - (CGFloat)getTopBarHeight {
- return 0;
- }
-
- - (void)onChildWillAppear {
- [self.presenter applyOptions:self.resolveOptions];
- [((UISplitViewController *)self.parentViewController) onChildWillAppear];
- }
-
- - (void)willMoveToParentViewController:(UIViewController *)parent {
- if (parent) {
- [self.presenter applyOptionsOnWillMoveToParentViewController:self.resolveOptions];
- }
- }
-
- #pragma mark getters and setters to associated object
-
- - (RNNNavigationOptions *)options {
- return objc_getAssociatedObject(self, @selector(options));
- }
-
- - (void)setOptions:(RNNNavigationOptions *)options {
- objc_setAssociatedObject(self, @selector(options), options, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- }
-
- - (RNNNavigationOptions *)defaultOptions {
- return objc_getAssociatedObject(self, @selector(defaultOptions));
- }
-
- - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
- objc_setAssociatedObject(self, @selector(defaultOptions), defaultOptions, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- }
-
- - (RNNLayoutInfo *)layoutInfo {
- return objc_getAssociatedObject(self, @selector(layoutInfo));
- }
-
- - (void)setLayoutInfo:(RNNLayoutInfo *)layoutInfo {
- objc_setAssociatedObject(self, @selector(layoutInfo), layoutInfo, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- }
-
- - (RNNBasePresenter *)presenter {
- return objc_getAssociatedObject(self, @selector(presenter));
- }
-
- - (void)setPresenter:(RNNBasePresenter *)presenter {
- objc_setAssociatedObject(self, @selector(presenter), presenter, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- }
-
- - (RNNEventEmitter *)eventEmitter {
- return objc_getAssociatedObject(self, @selector(eventEmitter));
- }
-
- - (void)setEventEmitter:(RNNEventEmitter *)eventEmitter {
- objc_setAssociatedObject(self, @selector(eventEmitter), eventEmitter, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- }
-
- - (id<RNNComponentViewCreator>)creator {
- return objc_getAssociatedObject(self, @selector(creator));
- }
-
- - (void)setCreator:(id<RNNComponentViewCreator>)creator {
- objc_setAssociatedObject(self, @selector(creator), creator, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- }
-
-
-
- @end
|