mirror of
https://github.com/status-im/react-native.git
synced 2025-01-09 17:15:54 +00:00
9e6e573e19
Summary: Continuation on #3959 (started by cancan101). Rebased to latest master, adds support for left system icon, fixes issues mentioned in previous PR. <img width="432" alt="screen shot 2016-09-05 at 13 54 41" src="https://cloud.githubusercontent.com/assets/7275322/18248478/5b7aa25c-7370-11e6-8c51-01a2b7fd1030.png"> Closes https://github.com/facebook/react-native/pull/9742 Differential Revision: D3836850 Pulled By: javache fbshipit-source-id: ef9f6e42211ed18bf5f3dc1eb7a8b1318d939674
177 lines
5.0 KiB
Objective-C
177 lines
5.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 "RCTNavItem.h"
|
|
|
|
@implementation RCTNavItem
|
|
|
|
@synthesize backButtonItem = _backButtonItem;
|
|
@synthesize leftButtonItem = _leftButtonItem;
|
|
@synthesize rightButtonItem = _rightButtonItem;
|
|
|
|
- (UIImageView *)titleImageView
|
|
{
|
|
if (_titleImage) {
|
|
return [[UIImageView alloc] initWithImage:_titleImage];
|
|
} else {
|
|
return nil;
|
|
}
|
|
}
|
|
|
|
-(instancetype)init
|
|
{
|
|
if (self = [super init]) {
|
|
_leftButtonSystemIcon = NSNotFound;
|
|
_rightButtonSystemIcon = NSNotFound;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)setBackButtonTitle:(NSString *)backButtonTitle
|
|
{
|
|
_backButtonTitle = backButtonTitle;
|
|
_backButtonItem = nil;
|
|
}
|
|
|
|
- (void)setBackButtonIcon:(UIImage *)backButtonIcon
|
|
{
|
|
_backButtonIcon = backButtonIcon;
|
|
_backButtonItem = nil;
|
|
}
|
|
|
|
- (UIBarButtonItem *)backButtonItem
|
|
{
|
|
if (!_backButtonItem) {
|
|
if (_backButtonIcon) {
|
|
_backButtonItem = [[UIBarButtonItem alloc] initWithImage:_backButtonIcon
|
|
style:UIBarButtonItemStylePlain
|
|
target:nil
|
|
action:nil];
|
|
} else if (_backButtonTitle.length) {
|
|
_backButtonItem = [[UIBarButtonItem alloc] initWithTitle:_backButtonTitle
|
|
style:UIBarButtonItemStylePlain
|
|
target:nil
|
|
action:nil];
|
|
} else {
|
|
_backButtonItem = nil;
|
|
}
|
|
}
|
|
return _backButtonItem;
|
|
}
|
|
|
|
- (void)setLeftButtonTitle:(NSString *)leftButtonTitle
|
|
{
|
|
_leftButtonTitle = leftButtonTitle;
|
|
_leftButtonItem = nil;
|
|
}
|
|
|
|
- (void)setLeftButtonIcon:(UIImage *)leftButtonIcon
|
|
{
|
|
_leftButtonIcon = leftButtonIcon;
|
|
_leftButtonItem = nil;
|
|
}
|
|
|
|
- (void)setLeftButtonSystemIcon:(UIBarButtonSystemItem)leftButtonSystemIcon
|
|
{
|
|
_leftButtonSystemIcon = leftButtonSystemIcon;
|
|
_leftButtonItem = nil;
|
|
}
|
|
|
|
- (UIBarButtonItem *)leftButtonItem
|
|
{
|
|
if (!_leftButtonItem) {
|
|
if (_leftButtonIcon) {
|
|
_leftButtonItem =
|
|
[[UIBarButtonItem alloc] initWithImage:_leftButtonIcon
|
|
style:UIBarButtonItemStylePlain
|
|
target:self
|
|
action:@selector(handleLeftButtonPress)];
|
|
|
|
} else if (_leftButtonTitle.length) {
|
|
_leftButtonItem =
|
|
[[UIBarButtonItem alloc] initWithTitle:_leftButtonTitle
|
|
style:UIBarButtonItemStylePlain
|
|
target:self
|
|
action:@selector(handleLeftButtonPress)];
|
|
|
|
} else if (_leftButtonSystemIcon != NSNotFound) {
|
|
_leftButtonItem =
|
|
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:_leftButtonSystemIcon
|
|
target:self
|
|
action:@selector(handleLeftButtonPress)];
|
|
} else {
|
|
_leftButtonItem = nil;
|
|
}
|
|
}
|
|
return _leftButtonItem;
|
|
}
|
|
|
|
- (void)handleLeftButtonPress
|
|
{
|
|
if (_onLeftButtonPress) {
|
|
_onLeftButtonPress(nil);
|
|
}
|
|
}
|
|
|
|
- (void)setRightButtonTitle:(NSString *)rightButtonTitle
|
|
{
|
|
_rightButtonTitle = rightButtonTitle;
|
|
_rightButtonItem = nil;
|
|
}
|
|
|
|
- (void)setRightButtonIcon:(UIImage *)rightButtonIcon
|
|
{
|
|
_rightButtonIcon = rightButtonIcon;
|
|
_rightButtonItem = nil;
|
|
}
|
|
|
|
- (void)setRightButtonSystemIcon:(UIBarButtonSystemItem)rightButtonSystemIcon
|
|
{
|
|
_rightButtonSystemIcon = rightButtonSystemIcon;
|
|
_rightButtonItem = nil;
|
|
}
|
|
|
|
- (UIBarButtonItem *)rightButtonItem
|
|
{
|
|
if (!_rightButtonItem) {
|
|
if (_rightButtonIcon) {
|
|
_rightButtonItem =
|
|
[[UIBarButtonItem alloc] initWithImage:_rightButtonIcon
|
|
style:UIBarButtonItemStylePlain
|
|
target:self
|
|
action:@selector(handleRightButtonPress)];
|
|
|
|
} else if (_rightButtonTitle.length) {
|
|
_rightButtonItem =
|
|
[[UIBarButtonItem alloc] initWithTitle:_rightButtonTitle
|
|
style:UIBarButtonItemStylePlain
|
|
target:self
|
|
action:@selector(handleRightButtonPress)];
|
|
|
|
} else if (_rightButtonSystemIcon != NSNotFound) {
|
|
_rightButtonItem =
|
|
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:_rightButtonSystemIcon
|
|
target:self
|
|
action:@selector(handleRightButtonPress)];
|
|
} else {
|
|
_rightButtonItem = nil;
|
|
}
|
|
}
|
|
return _rightButtonItem;
|
|
}
|
|
|
|
- (void)handleRightButtonPress
|
|
{
|
|
if (_onRightButtonPress) {
|
|
_onRightButtonPress(nil);
|
|
}
|
|
}
|
|
|
|
@end
|