2015-01-30 01:10:49 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
#import "RCTWrapperViewController.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"
|
|
|
|
#import "UIView+ReactKit.h"
|
|
|
|
|
|
|
|
@implementation RCTWrapperViewController
|
|
|
|
{
|
|
|
|
UIView *_contentView;
|
2015-02-04 00:02:36 +00:00
|
|
|
RCTEventDispatcher *_eventDispatcher;
|
2015-01-30 01:10:49 +00:00
|
|
|
CGFloat _previousTopLayout;
|
|
|
|
CGFloat _previousBottomLayout;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
|
|
|
|
{
|
|
|
|
RCT_NOT_DESIGNATED_INITIALIZER();
|
|
|
|
}
|
|
|
|
|
2015-02-04 00:02:36 +00:00
|
|
|
- (instancetype)initWithContentView:(UIView *)contentView eventDispatcher:(RCTEventDispatcher *)eventDispatcher
|
2015-01-30 01:10:49 +00:00
|
|
|
{
|
2015-02-04 00:02:36 +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-02-04 00:02:36 +00:00
|
|
|
- (instancetype)initWithNavItem:(RCTNavItem *)navItem eventDispatcher:(RCTEventDispatcher *)eventDispatcher
|
2015-01-30 01:10:49 +00:00
|
|
|
{
|
2015-02-04 00:02:36 +00:00
|
|
|
if ((self = [self initWithContentView:navItem eventDispatcher:eventDispatcher])) {
|
2015-01-30 01:10:49 +00:00
|
|
|
_navItem = navItem;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
|
|
|
[self.navigationController setNavigationBarHidden:!_navItem animated:animated];
|
|
|
|
if (!_navItem) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.navigationItem.title = _navItem.title;
|
|
|
|
|
|
|
|
[self _configureNavBarStyle];
|
|
|
|
|
|
|
|
if (_navItem.rightButtonTitle.length > 0) {
|
|
|
|
self.navigationItem.rightBarButtonItem =
|
|
|
|
[[UIBarButtonItem alloc] initWithTitle:_navItem.rightButtonTitle
|
|
|
|
style:UIBarButtonItemStyleDone
|
|
|
|
target:self
|
2015-02-04 00:02:36 +00:00
|
|
|
action:@selector(rightButtonTapped)];
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_navItem.backButtonTitle.length > 0) {
|
|
|
|
self.navigationItem.backBarButtonItem =
|
|
|
|
[[UIBarButtonItem alloc] initWithTitle:_navItem.backButtonTitle
|
|
|
|
style:UIBarButtonItemStylePlain
|
|
|
|
target:nil
|
|
|
|
action:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)_configureNavBarStyle
|
|
|
|
{
|
|
|
|
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}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)loadView
|
|
|
|
{
|
|
|
|
// Add a wrapper so that UIViewControllerWrapperView (managed by the
|
|
|
|
// UINavigationController) doesn't end up resetting the frames for
|
|
|
|
// `contentView` which is a react-managed view.
|
|
|
|
self.view = [[UIView alloc] init];
|
|
|
|
[self.view addSubview:_contentView];
|
|
|
|
}
|
|
|
|
|
2015-02-04 00:02:36 +00:00
|
|
|
- (void)rightButtonTapped
|
2015-01-30 01:10:49 +00:00
|
|
|
{
|
2015-02-04 00:15:20 +00:00
|
|
|
[_eventDispatcher sendEventWithName:@"topNavRightButtonTap" body:@{@"target":_navItem.reactTag}];
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didMoveToParentViewController:(UIViewController *)parent
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
[super didMoveToParentViewController:parent];
|
|
|
|
if (parent == nil || [parent isKindOfClass:[UINavigationController class]]) {
|
|
|
|
[self.navigationListener wrapperViewController:self didMoveToNavigationController:(UINavigationController *)parent];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|