Skip to content

Commit 9bd80cb

Browse files
alvarombFacebook Github Bot 0
authored andcommitted
Added the ability to set an image title in the NavigatorIOS
Summary: This pull request adds support for setting an image title in `NavigatorIOS`. It sets the `titleView` property of `UINavigationItem`. Added an example into `UIExplorer` <img width="487" alt="ex" src="https://cloud.githubusercontent.com/assets/289640/16147578/3d552606-3484-11e6-9a26-1e8c113ace03.png"> The code follows the same style as the rest of `RCTNavItem` and `RCTWrapperViewController`. Closes #8182 Differential Revision: D3469073 Pulled By: javache fbshipit-source-id: 2d3e4bad534f92b6e6b24a6b74f2993f3a8c9012
1 parent 39f524d commit 9bd80cb

File tree

7 files changed

+59
-25
lines changed

7 files changed

+59
-25
lines changed

Examples/UIExplorer/NavigatorIOSExample.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
/**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
29
* The examples provided by Facebook are for non-commercial testing and
310
* evaluation purposes only.
411
*
@@ -65,6 +72,13 @@ const NavigatorIOSExamplePage = React.createClass({
6572
component: createExamplePage(null, ViewExample),
6673
});
6774
})}
75+
{this._renderRow('Custom title image Example', () => {
76+
this.props.navigator.push({
77+
title: 'Custom title image Example',
78+
titleImage: require('./relay.png'),
79+
component: createExamplePage(null, ViewExample),
80+
});
81+
})}
6882
{this._renderRow('Custom Right Button', () => {
6983
this.props.navigator.push({
7084
title: NavigatorIOSExample.title,

Libraries/Components/Navigation/NavigatorIOS.ios.js

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ var View = require('View');
2424
var invariant = require('fbjs/lib/invariant');
2525
var logError = require('logError');
2626
var requireNativeComponent = require('requireNativeComponent');
27-
var resolveAssetSource = require('resolveAssetSource');
2827

2928
var TRANSITIONER_REF = 'transitionerRef';
3029

@@ -52,30 +51,31 @@ var NavigatorTransitionerIOS = React.createClass({
5251
});
5352

5453
type Route = {
55-
component: Function;
56-
title: string;
57-
passProps?: Object;
58-
backButtonTitle?: string;
59-
backButtonIcon?: Object;
60-
leftButtonTitle?: string;
61-
leftButtonIcon?: Object;
62-
onLeftButtonPress?: Function;
63-
rightButtonTitle?: string;
64-
rightButtonIcon?: Object;
65-
onRightButtonPress?: Function;
66-
wrapperStyle?: any;
54+
component: Function,
55+
title: string,
56+
titleImage?: Object,
57+
passProps?: Object,
58+
backButtonTitle?: string,
59+
backButtonIcon?: Object,
60+
leftButtonTitle?: string,
61+
leftButtonIcon?: Object,
62+
onLeftButtonPress?: Function,
63+
rightButtonTitle?: string,
64+
rightButtonIcon?: Object,
65+
onRightButtonPress?: Function,
66+
wrapperStyle?: any,
6767
};
6868

6969
type State = {
70-
idStack: Array<number>;
71-
routeStack: Array<Route>;
72-
requestedTopOfStack: number;
73-
observedTopOfStack: number;
74-
progress: number;
75-
fromIndex: number;
76-
toIndex: number;
77-
makingNavigatorRequest: boolean;
78-
updatingAllIndicesAtOrBeyond: ?number;
70+
idStack: Array<number>,
71+
routeStack: Array<Route>,
72+
requestedTopOfStack: number,
73+
observedTopOfStack: number,
74+
progress: number,
75+
fromIndex: number,
76+
toIndex: number,
77+
makingNavigatorRequest: boolean,
78+
updatingAllIndicesAtOrBeyond: ?number,
7979
}
8080

8181
type Event = Object;
@@ -185,6 +185,11 @@ var NavigatorIOS = React.createClass({
185185
*/
186186
title: PropTypes.string.isRequired,
187187

188+
/**
189+
* If set, the image will appear instead of the text title
190+
*/
191+
titleImage: Image.propTypes.source,
192+
188193
/**
189194
* Specify additional props passed to the component. NavigatorIOS will
190195
* automatically provide "route" and "navigator" components
@@ -404,8 +409,8 @@ var NavigatorIOS = React.createClass({
404409
},
405410

406411
getChildContext: function(): {
407-
onFocusRequested: Function;
408-
focusEmitter: EventEmitter;
412+
onFocusRequested: Function,
413+
focusEmitter: EventEmitter,
409414
} {
410415
return {
411416
onFocusRequested: this._handleFocusRequest,

Libraries/ReactIOS/verifyPropTypes.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ function verifyPropTypes(
2727
if (!viewConfig) {
2828
return; // This happens for UnimplementedView.
2929
}
30-
var componentName = componentInterface.name ||
30+
var componentName =
3131
componentInterface.displayName ||
32+
componentInterface.name ||
3233
'unknown';
34+
3335
if (!componentInterface.propTypes) {
3436
throw new Error(
3537
'`' + componentName + '` has no propTypes defined`'

React/Views/RCTNavItem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
@interface RCTNavItem : UIView
1515

1616
@property (nonatomic, copy) NSString *title;
17+
@property (nonatomic, strong) UIImage *titleImage;
1718
@property (nonatomic, strong) UIImage *leftButtonIcon;
1819
@property (nonatomic, copy) NSString *leftButtonTitle;
1920
@property (nonatomic, strong) UIImage *rightButtonIcon;
@@ -27,6 +28,7 @@
2728
@property (nonatomic, strong) UIColor *titleTextColor;
2829
@property (nonatomic, assign) BOOL translucent;
2930

31+
@property (nonatomic, readonly) UIImageView *titleImageView;
3032
@property (nonatomic, readonly) UIBarButtonItem *backButtonItem;
3133
@property (nonatomic, readonly) UIBarButtonItem *leftButtonItem;
3234
@property (nonatomic, readonly) UIBarButtonItem *rightButtonItem;

React/Views/RCTNavItem.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ @implementation RCTNavItem
1515
@synthesize leftButtonItem = _leftButtonItem;
1616
@synthesize rightButtonItem = _rightButtonItem;
1717

18+
- (UIImageView *)titleImageView
19+
{
20+
if (_titleImage) {
21+
return [[UIImageView alloc] initWithImage:_titleImage];
22+
} else {
23+
return nil;
24+
}
25+
}
26+
1827
- (void)setBackButtonTitle:(NSString *)backButtonTitle
1928
{
2029
_backButtonTitle = backButtonTitle;

React/Views/RCTNavItemManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ - (UIView *)view
2929

3030
RCT_EXPORT_VIEW_PROPERTY(title, NSString)
3131
RCT_EXPORT_VIEW_PROPERTY(titleTextColor, UIColor)
32+
RCT_EXPORT_VIEW_PROPERTY(titleImage, UIImage)
3233

3334
RCT_EXPORT_VIEW_PROPERTY(backButtonIcon, UIImage)
3435
RCT_EXPORT_VIEW_PROPERTY(backButtonTitle, NSString)

React/Views/RCTWrapperViewController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ - (void)viewWillAppear:(BOOL)animated
123123

124124
UINavigationItem *item = self.navigationItem;
125125
item.title = _navItem.title;
126+
item.titleView = _navItem.titleImageView;
126127
item.backBarButtonItem = _navItem.backButtonItem;
127128
item.leftBarButtonItem = _navItem.leftButtonItem;
128129
item.rightBarButtonItem = _navItem.rightButtonItem;

0 commit comments

Comments
 (0)