Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Libraries/Components/Navigation/NavigatorIOS.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var logError = require('logError');
var requireNativeComponent = require('requireNativeComponent');
var resolveAssetSource = require('resolveAssetSource');

var keyMirror = require('keyMirror');

var TRANSITIONER_REF = 'transitionerRef';

var PropTypes = React.PropTypes;
Expand All @@ -50,6 +52,36 @@ var NavigatorTransitionerIOS = React.createClass({
},
});

var SystemItemsLabels = {
done: true,
cancel: true,
edit: true,
save: true,
add: true,
'flexible-space': true,
'fixed-space': true,
compose: true,
reply: true,
action: true,
organize: true,
bookmarks: true,
search: true,
refresh: true,
stop: true,
camera: true,
trash: true,
play: true,
pause: true,
rewind: true,
'fast-forward': true,
undo: true,
redo: true,
'page-curl': true,
}
var SystemItems = keyMirror(SystemItemsLabels);

type BarButtonSystemItem = $Enum<typeof SystemItemsLabels>;

type Route = {
component: Function;
title: string;
Expand All @@ -61,6 +93,7 @@ type Route = {
onLeftButtonPress?: Function;
rightButtonTitle?: string;
rightButtonIcon?: Object;
rightButtonSystemItem?: BarButtonSystemItem;
onRightButtonPress?: Function;
wrapperStyle?: any;
};
Expand Down Expand Up @@ -243,6 +276,11 @@ var NavigatorIOS = React.createClass({
*/
rightButtonTitle: PropTypes.string,

/**
* If set, the right header button will appear with this system icon
*/
rightButtonSystemItem: PropTypes.oneOf(Object.keys(SystemItems)),

/**
* Called when the right header button is pressed
*/
Expand Down
1 change: 1 addition & 0 deletions React/Views/RCTNavItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@property (nonatomic, copy) NSString *leftButtonTitle;
@property (nonatomic, strong) UIImage *rightButtonIcon;
@property (nonatomic, copy) NSString *rightButtonTitle;
@property (nonatomic, assign) UIBarButtonSystemItem rightButtonSystemItem;
@property (nonatomic, strong) UIImage *backButtonIcon;
@property (nonatomic, copy) NSString *backButtonTitle;
@property (nonatomic, assign) BOOL navigationBarHidden;
Expand Down
18 changes: 18 additions & 0 deletions React/Views/RCTNavItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ @implementation RCTNavItem
@synthesize leftButtonItem = _leftButtonItem;
@synthesize rightButtonItem = _rightButtonItem;

-(id)init {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: { on new line

if (self = [super init]) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use double (( for assignment inside if, i.e.

if ((self = [super init])) {

_rightButtonSystemItem = -1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use NSNotFound instead of -1 as the "null" value? It's more idiomatic for Obj-C (and also doesn't rely on the implementation detail that UIBarButtonSystemItem happens to be an NSInteger rather than NSUInteger).

}
return self;
}

- (void)setBackButtonTitle:(NSString *)backButtonTitle
{
_backButtonTitle = backButtonTitle;
Expand Down Expand Up @@ -101,6 +108,12 @@ - (void)setRightButtonIcon:(UIImage *)rightButtonIcon
_rightButtonItem = nil;
}

- (void)setRightButtonSystemItem:(UIBarButtonSystemItem)rightButtonSystemItem
{
_rightButtonSystemItem = rightButtonSystemItem;
_rightButtonItem = nil;
}

- (UIBarButtonItem *)rightButtonItem
{
if (!_rightButtonItem) {
Expand All @@ -117,6 +130,11 @@ - (UIBarButtonItem *)rightButtonItem
style:UIBarButtonItemStylePlain
target:self
action:@selector(handleRightButtonPress)];
} else if (_rightButtonSystemItem >= 0) {
_rightButtonItem =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:_rightButtonSystemItem
target:self
action:@selector(handleRightButtonPress)];
} else {
_rightButtonItem = nil;
}
Expand Down
9 changes: 8 additions & 1 deletion React/Views/RCTNavItemManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@

#import "RCTViewManager.h"

@interface RCTNavItemManager : RCTViewManager
#import "RCTConvert.h"

@interface RCTConvert (BarButtonSystemItem)

+ (UIBarButtonSystemItem)UIBarButtonSystemItem:(id)json;

@end

@interface RCTNavItemManager : RCTViewManager

@end
32 changes: 32 additions & 0 deletions React/Views/RCTNavItemManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,37 @@
#import "RCTConvert.h"
#import "RCTNavItem.h"

@implementation RCTConvert (BarButtonSystemItem)

RCT_ENUM_CONVERTER(UIBarButtonSystemItem, (@{
@"done": @(UIBarButtonSystemItemDone),
@"cancel": @(UIBarButtonSystemItemCancel),
@"edit": @(UIBarButtonSystemItemEdit),
@"save": @(UIBarButtonSystemItemSave),
@"add": @(UIBarButtonSystemItemAdd),
@"flexible-space": @(UIBarButtonSystemItemFlexibleSpace),
@"fixed-space": @(UIBarButtonSystemItemFixedSpace),
@"compose": @(UIBarButtonSystemItemCompose),
@"reply": @(UIBarButtonSystemItemReply),
@"action": @(UIBarButtonSystemItemAction),
@"organize": @(UIBarButtonSystemItemOrganize),
@"bookmarks": @(UIBarButtonSystemItemBookmarks),
@"search": @(UIBarButtonSystemItemSearch),
@"refresh": @(UIBarButtonSystemItemRefresh),
@"stop": @(UIBarButtonSystemItemStop),
@"camera": @(UIBarButtonSystemItemCamera),
@"trash": @(UIBarButtonSystemItemTrash),
@"play": @(UIBarButtonSystemItemPlay),
@"pause": @(UIBarButtonSystemItemPause),
@"rewind": @(UIBarButtonSystemItemRewind),
@"fast-forward": @(UIBarButtonSystemItemFastForward),
@"undo": @(UIBarButtonSystemItemUndo),
@"redo": @(UIBarButtonSystemItemRedo),
@"page-curl": @(UIBarButtonSystemItemPageCurl)
}), -1, integerValue);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See note about NSNotFound, above


@end

@implementation RCTNavItemManager

RCT_EXPORT_MODULE()
Expand All @@ -38,6 +69,7 @@ - (UIView *)view

RCT_EXPORT_VIEW_PROPERTY(rightButtonIcon, UIImage)
RCT_EXPORT_VIEW_PROPERTY(rightButtonTitle, NSString)
RCT_EXPORT_VIEW_PROPERTY(rightButtonSystemItem, UIBarButtonSystemItem)

RCT_EXPORT_VIEW_PROPERTY(onLeftButtonPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onRightButtonPress, RCTBubblingEventBlock)
Expand Down