2015-03-23 22:07:33 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
#import "RCTWrapperViewController.h"
|
|
|
|
|
2015-03-06 17:54:10 +00:00
|
|
|
#import <UIKit/UIScrollView.h>
|
|
|
|
|
2015-02-04 00:02:36 +00:00
|
|
|
#import "RCTEventDispatcher.h"
|
2015-01-30 01:10:49 +00:00
|
|
|
#import "RCTNavItem.h"
|
|
|
|
#import "RCTUtils.h"
|
2015-03-06 17:54:10 +00:00
|
|
|
#import "RCTViewControllerProtocol.h"
|
2015-03-26 13:32:01 +00:00
|
|
|
#import "UIView+React.h"
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
@implementation RCTWrapperViewController
|
|
|
|
{
|
2015-03-06 17:54:10 +00:00
|
|
|
UIView *_wrapperView;
|
2015-01-30 01:10:49 +00:00
|
|
|
UIView *_contentView;
|
2015-02-04 00:02:36 +00:00
|
|
|
RCTEventDispatcher *_eventDispatcher;
|
2015-01-30 01:10:49 +00:00
|
|
|
CGFloat _previousTopLayout;
|
|
|
|
CGFloat _previousBottomLayout;
|
|
|
|
}
|
|
|
|
|
2015-03-06 17:54:10 +00:00
|
|
|
@synthesize currentTopLayoutGuide = _currentTopLayoutGuide;
|
|
|
|
@synthesize currentBottomLayoutGuide = _currentBottomLayoutGuide;
|
|
|
|
|
|
|
|
- (instancetype)initWithContentView:(UIView *)contentView
|
|
|
|
eventDispatcher:(RCTEventDispatcher *)eventDispatcher
|
2015-01-30 01:10:49 +00:00
|
|
|
{
|
2015-03-06 17:54:10 +00:00
|
|
|
if (self = [super initWithNibName:nil bundle:nil]) {
|
2015-01-30 01:10:49 +00:00
|
|
|
_contentView = contentView;
|
|
|
|
_eventDispatcher = eventDispatcher;
|
|
|
|
self.automaticallyAdjustsScrollViewInsets = NO;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-03-06 17:54:10 +00:00
|
|
|
- (instancetype)initWithNavItem:(RCTNavItem *)navItem
|
|
|
|
eventDispatcher:(RCTEventDispatcher *)eventDispatcher
|
2015-01-30 01:10:49 +00:00
|
|
|
{
|
2015-03-06 17:54:10 +00:00
|
|
|
if (self = [self initWithContentView:navItem eventDispatcher:eventDispatcher]) {
|
2015-01-30 01:10:49 +00:00
|
|
|
_navItem = navItem;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-03-06 17:54:10 +00:00
|
|
|
- (void)viewWillLayoutSubviews
|
|
|
|
{
|
|
|
|
[super viewWillLayoutSubviews];
|
|
|
|
|
|
|
|
_currentTopLayoutGuide = self.topLayoutGuide;
|
|
|
|
_currentBottomLayoutGuide = self.bottomLayoutGuide;
|
|
|
|
}
|
|
|
|
|
2015-01-30 01:10:49 +00:00
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
2015-03-06 17:54:10 +00:00
|
|
|
// TODO: find a way to make this less-tightly coupled to navigation controller
|
|
|
|
if ([self.parentViewController isKindOfClass:[UINavigationController class]])
|
|
|
|
{
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2015-03-06 17:54:10 +00:00
|
|
|
[self.navigationController setNavigationBarHidden:!_navItem animated:animated];
|
|
|
|
if (!_navItem) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2015-03-06 17:54:10 +00:00
|
|
|
self.navigationItem.title = _navItem.title;
|
|
|
|
|
|
|
|
UINavigationBar *bar = self.navigationController.navigationBar;
|
|
|
|
if (_navItem.barTintColor) {
|
|
|
|
bar.barTintColor = _navItem.barTintColor;
|
|
|
|
}
|
|
|
|
if (_navItem.tintColor) {
|
|
|
|
BOOL canSetTintColor = _navItem.barTintColor == nil;
|
|
|
|
if (canSetTintColor) {
|
|
|
|
bar.tintColor = _navItem.tintColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_navItem.titleTextColor) {
|
|
|
|
[bar setTitleTextAttributes:@{NSForegroundColorAttributeName : _navItem.titleTextColor}];
|
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2015-03-06 17:54:10 +00:00
|
|
|
if (_navItem.rightButtonTitle.length > 0) {
|
|
|
|
self.navigationItem.rightBarButtonItem =
|
2015-01-30 01:10:49 +00:00
|
|
|
[[UIBarButtonItem alloc] initWithTitle:_navItem.rightButtonTitle
|
2015-03-06 17:54:10 +00:00
|
|
|
style:UIBarButtonItemStyleDone
|
2015-01-30 01:10:49 +00:00
|
|
|
target:self
|
2015-03-06 17:54:10 +00:00
|
|
|
action:@selector(handleNavRightButtonTapped)];
|
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2015-03-06 17:54:10 +00:00
|
|
|
if (_navItem.backButtonTitle.length > 0) {
|
|
|
|
self.navigationItem.backBarButtonItem =
|
2015-01-30 01:10:49 +00:00
|
|
|
[[UIBarButtonItem alloc] initWithTitle:_navItem.backButtonTitle
|
2015-03-06 17:54:10 +00:00
|
|
|
style:UIBarButtonItemStylePlain
|
|
|
|
target:nil
|
|
|
|
action:nil];
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)loadView
|
|
|
|
{
|
2015-03-11 19:29:36 +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 17:54:10 +00:00
|
|
|
//`contentView` which is a react-managed view.
|
|
|
|
_wrapperView = [[UIView alloc] initWithFrame:_contentView.bounds];
|
|
|
|
[_wrapperView addSubview:_contentView];
|
|
|
|
self.view = _wrapperView;
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-06 17:54:10 +00:00
|
|
|
- (void)handleNavRightButtonTapped
|
2015-01-30 01:10:49 +00:00
|
|
|
{
|
2015-03-06 17:54:10 +00:00
|
|
|
[_eventDispatcher sendInputEventWithName:@"topNavRightButtonTap"
|
|
|
|
body:@{@"target":_navItem.reactTag}];
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didMoveToParentViewController:(UIViewController *)parent
|
|
|
|
{
|
2015-03-06 17:54:10 +00:00
|
|
|
// There's no clear setter for navigation controllers, but did move to parent
|
|
|
|
// view controller provides the desired effect. This is called after a pop
|
|
|
|
// finishes, be it a swipe to go back or a standard tap on the back button
|
2015-01-30 01:10:49 +00:00
|
|
|
[super didMoveToParentViewController:parent];
|
|
|
|
if (parent == nil || [parent isKindOfClass:[UINavigationController class]]) {
|
|
|
|
[self.navigationListener wrapperViewController:self didMoveToNavigationController:(UINavigationController *)parent];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|