mirror of
https://github.com/status-im/react-native.git
synced 2025-01-09 09:12:02 +00:00
b97ce93cea
Summary: NavigatorIOS supports four new properties: - **rightButtonImageSource:** The source of an image to display in the top right. This must be a static image since UINavigationController only supports UIImages. Adding support for UIImageViews (or arbitrary views) is more complicated because custom views do not fade on touch and do not have hit slop the same way that UIImage buttons do. Usage: `rightButtonImageSource: ix('ImageName')` - **backButtonImageSource:** Use a custom image for the back button. This does not replace the back caret (`<`) but instead replaces the text next to it. - **leftButtonTitle**: Text for the left nav button, which supersedes the previous nav item's back button when specified. The main use case for this is your initial screen/UIVC which has nothing to go back to (since it is the first VC on the stack) but need to display a left button. This does hide the back button if there would have been one otherwise. - **leftButtonImageSource:** Image source for the left button, super Closes https://github.com/facebook/react-native/pull/263 Github Author: James Ide <ide@jameside.com> Test Plan: Imported from GitHub, without a `Test Plan:` line.
130 lines
4.0 KiB
Objective-C
130 lines
4.0 KiB
Objective-C
/**
|
|
* 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.
|
|
*/
|
|
|
|
#import "RCTWrapperViewController.h"
|
|
|
|
#import <UIKit/UIScrollView.h>
|
|
|
|
#import "RCTEventDispatcher.h"
|
|
#import "RCTNavItem.h"
|
|
#import "RCTUtils.h"
|
|
#import "RCTViewControllerProtocol.h"
|
|
#import "UIView+React.h"
|
|
|
|
@implementation RCTWrapperViewController
|
|
{
|
|
UIView *_wrapperView;
|
|
UIView *_contentView;
|
|
RCTEventDispatcher *_eventDispatcher;
|
|
CGFloat _previousTopLayout;
|
|
CGFloat _previousBottomLayout;
|
|
}
|
|
|
|
@synthesize currentTopLayoutGuide = _currentTopLayoutGuide;
|
|
@synthesize currentBottomLayoutGuide = _currentBottomLayoutGuide;
|
|
|
|
- (instancetype)initWithContentView:(UIView *)contentView
|
|
eventDispatcher:(RCTEventDispatcher *)eventDispatcher
|
|
{
|
|
if (self = [super initWithNibName:nil bundle:nil]) {
|
|
_contentView = contentView;
|
|
_eventDispatcher = eventDispatcher;
|
|
self.automaticallyAdjustsScrollViewInsets = NO;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initWithNavItem:(RCTNavItem *)navItem
|
|
eventDispatcher:(RCTEventDispatcher *)eventDispatcher
|
|
{
|
|
if (self = [self initWithContentView:navItem eventDispatcher:eventDispatcher]) {
|
|
_navItem = navItem;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)viewWillLayoutSubviews
|
|
{
|
|
[super viewWillLayoutSubviews];
|
|
|
|
_currentTopLayoutGuide = self.topLayoutGuide;
|
|
_currentBottomLayoutGuide = self.bottomLayoutGuide;
|
|
}
|
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
{
|
|
[super viewWillAppear:animated];
|
|
|
|
// TODO: find a way to make this less-tightly coupled to navigation controller
|
|
if ([self.parentViewController isKindOfClass:[UINavigationController class]])
|
|
{
|
|
[self.navigationController
|
|
setNavigationBarHidden:_navItem.navigationBarHidden
|
|
animated:animated];
|
|
|
|
if (!_navItem) {
|
|
return;
|
|
}
|
|
|
|
UINavigationBar *bar = self.navigationController.navigationBar;
|
|
bar.barTintColor = _navItem.barTintColor;
|
|
bar.tintColor = _navItem.tintColor;
|
|
if (_navItem.titleTextColor) {
|
|
[bar setTitleTextAttributes:@{NSForegroundColorAttributeName : _navItem.titleTextColor}];
|
|
}
|
|
|
|
UINavigationItem *item = self.navigationItem;
|
|
item.title = _navItem.title;
|
|
item.backBarButtonItem = _navItem.backButtonItem;
|
|
if ((item.leftBarButtonItem = _navItem.leftButtonItem)) {
|
|
item.leftBarButtonItem.target = self;
|
|
item.leftBarButtonItem.action = @selector(handleNavLeftButtonTapped);
|
|
}
|
|
if ((item.rightBarButtonItem = _navItem.rightButtonItem)) {
|
|
item.rightBarButtonItem.target = self;
|
|
item.rightBarButtonItem.action = @selector(handleNavRightButtonTapped);
|
|
}
|
|
}
|
|
}
|
|
|
|
- (void)loadView
|
|
{
|
|
// Add a wrapper so that the wrapper view managed by the
|
|
// UINavigationController doesn't end up resetting the frames for
|
|
//`contentView` which is a react-managed view.
|
|
_wrapperView = [[UIView alloc] initWithFrame:_contentView.bounds];
|
|
[_wrapperView addSubview:_contentView];
|
|
self.view = _wrapperView;
|
|
}
|
|
|
|
- (void)handleNavLeftButtonTapped
|
|
{
|
|
[_eventDispatcher sendInputEventWithName:@"topNavLeftButtonTap"
|
|
body:@{@"target":_navItem.reactTag}];
|
|
}
|
|
|
|
- (void)handleNavRightButtonTapped
|
|
{
|
|
[_eventDispatcher sendInputEventWithName:@"topNavRightButtonTap"
|
|
body:@{@"target":_navItem.reactTag}];
|
|
}
|
|
|
|
- (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
|