2015-03-23 20:28:42 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-03-23 20:28:42 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-03-23 20:28:42 +00:00
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
#import "RCTWrapperViewController.h"
|
|
|
|
|
2015-03-06 00:36:41 +00:00
|
|
|
#import <UIKit/UIScrollView.h>
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
#import "RCTEventDispatcher.h"
|
|
|
|
#import "RCTUtils.h"
|
2015-03-26 09:58:06 +00:00
|
|
|
#import "UIView+React.h"
|
2015-09-04 12:50:01 +00:00
|
|
|
#import "RCTAutoInsetsProtocol.h"
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
@implementation RCTWrapperViewController
|
|
|
|
{
|
2015-03-06 00:36:41 +00:00
|
|
|
UIView *_wrapperView;
|
2015-02-20 04:10:52 +00:00
|
|
|
UIView *_contentView;
|
2015-09-04 12:50:01 +00:00
|
|
|
RCTEventDispatcher *_eventDispatcher;
|
|
|
|
CGFloat _previousTopLayoutLength;
|
|
|
|
CGFloat _previousBottomLayoutLength;
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2017-12-20 23:17:05 +00:00
|
|
|
id<UILayoutSupport> _currentTopLayoutGuide;
|
|
|
|
id<UILayoutSupport> _currentBottomLayoutGuide;
|
|
|
|
}
|
2015-03-06 00:36:41 +00:00
|
|
|
|
|
|
|
- (instancetype)initWithContentView:(UIView *)contentView
|
2015-02-20 04:10:52 +00:00
|
|
|
{
|
2015-06-15 14:53:45 +00:00
|
|
|
RCTAssertParam(contentView);
|
|
|
|
|
|
|
|
if ((self = [super initWithNibName:nil bundle:nil])) {
|
2015-02-20 04:10:52 +00:00
|
|
|
_contentView = contentView;
|
|
|
|
self.automaticallyAdjustsScrollViewInsets = NO;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-08-24 10:14:33 +00:00
|
|
|
RCT_NOT_IMPLEMENTED(- (instancetype)initWithNibName:(NSString *)nn bundle:(NSBundle *)nb)
|
|
|
|
RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
|
2015-06-15 14:53:45 +00:00
|
|
|
|
2015-03-06 00:36:41 +00:00
|
|
|
- (void)viewWillLayoutSubviews
|
|
|
|
{
|
|
|
|
[super viewWillLayoutSubviews];
|
|
|
|
|
|
|
|
_currentTopLayoutGuide = self.topLayoutGuide;
|
|
|
|
_currentBottomLayoutGuide = self.bottomLayoutGuide;
|
|
|
|
}
|
|
|
|
|
2015-09-04 12:50:01 +00:00
|
|
|
static BOOL RCTFindScrollViewAndRefreshContentInsetInView(UIView *view)
|
|
|
|
{
|
|
|
|
if ([view conformsToProtocol:@protocol(RCTAutoInsetsProtocol)]) {
|
|
|
|
[(id <RCTAutoInsetsProtocol>) view refreshContentInset];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
for (UIView *subview in view.subviews) {
|
|
|
|
if (RCTFindScrollViewAndRefreshContentInsetInView(subview)) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLayoutSubviews
|
|
|
|
{
|
|
|
|
[super viewDidLayoutSubviews];
|
|
|
|
|
|
|
|
if (_previousTopLayoutLength != _currentTopLayoutGuide.length ||
|
|
|
|
_previousBottomLayoutLength != _currentBottomLayoutGuide.length) {
|
|
|
|
RCTFindScrollViewAndRefreshContentInsetInView(_contentView);
|
|
|
|
_previousTopLayoutLength = _currentTopLayoutGuide.length;
|
|
|
|
_previousBottomLayoutLength = _currentBottomLayoutGuide.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
- (void)loadView
|
|
|
|
{
|
2015-03-11 02:03:59 +00:00
|
|
|
// Add a wrapper so that the wrapper view managed by the
|
|
|
|
// UINavigationController doesn't end up resetting the frames for
|
2015-03-06 00:36:41 +00:00
|
|
|
//`contentView` which is a react-managed view.
|
|
|
|
_wrapperView = [[UIView alloc] initWithFrame:_contentView.bounds];
|
|
|
|
[_wrapperView addSubview:_contentView];
|
|
|
|
self.view = _wrapperView;
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|