Skip to content

Commit

Permalink
Update navigation bar's title and tint color on #resetTo / #replace.
Browse files Browse the repository at this point in the history
* Approach borrowed from: facebook#1403 (comment)

* Would need to follow similar pattern to update other navigation / nav bar props on resetTo / replace,
  but want to limit the changes from RN master for now.
  • Loading branch information
drtangible committed Apr 14, 2016
1 parent bd6d7d4 commit 305e074
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion React/Views/RCTNavItem.h
Expand Up @@ -8,12 +8,13 @@
*/

#import <UIKit/UIKit.h>

#import "RCTWrapperViewController.h"
#import "RCTComponent.h"

@interface RCTNavItem : UIView

@property (nonatomic, copy) NSString *title;
@property (nonatomic, weak) RCTWrapperViewController *delegate;
@property (nonatomic, strong) UIImage *leftButtonIcon;
@property (nonatomic, copy) NSString *leftButtonTitle;
@property (nonatomic, strong) UIImage *rightButtonIcon;
Expand Down
17 changes: 17 additions & 0 deletions React/Views/RCTNavItem.m
Expand Up @@ -11,10 +11,27 @@

@implementation RCTNavItem

@synthesize delegate = _delegate;
@synthesize backButtonItem = _backButtonItem;
@synthesize leftButtonItem = _leftButtonItem;
@synthesize rightButtonItem = _rightButtonItem;

- (void)setTitle:(NSString *)title
{
if (title != _title) {
_title = title;
[self.delegate titleDidChange:title];
}
}

- (void)setBarTintColor:(UIColor *)barTintColor
{
if (barTintColor != _barTintColor) {
_barTintColor = barTintColor;
[self.delegate barTintColorDidChange:barTintColor];
}
}

- (void)setBackButtonTitle:(NSString *)backButtonTitle
{
_backButtonTitle = backButtonTitle;
Expand Down
3 changes: 3 additions & 0 deletions React/Views/RCTWrapperViewController.h
Expand Up @@ -26,6 +26,9 @@ didMoveToNavigationController:(UINavigationController *)navigationController;
- (instancetype)initWithContentView:(UIView *)contentView NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithNavItem:(RCTNavItem *)navItem;

- (void)titleDidChange:(NSString *)title;
- (void)barTintColorDidChange:(UIColor *)barTintColor;

@property (nonatomic, weak) id<RCTWrapperViewControllerNavigationListener> navigationListener;
@property (nonatomic, strong) RCTNavItem *navItem;

Expand Down
14 changes: 14 additions & 0 deletions React/Views/RCTWrapperViewController.m
Expand Up @@ -45,6 +45,7 @@ - (instancetype)initWithNavItem:(RCTNavItem *)navItem
{
if ((self = [self initWithContentView:navItem])) {
_navItem = navItem;
_navItem.delegate = self;
}
return self;
}
Expand All @@ -60,6 +61,19 @@ - (void)viewWillLayoutSubviews
_currentBottomLayoutGuide = self.bottomLayoutGuide;
}


- (void)titleDidChange:(NSString *)title
{
UINavigationItem *item = self.navigationItem;
item.title = title;
}

- (void)barTintColorDidChange:(UIColor *)barTintColor
{
UINavigationBar *bar = self.navigationController.navigationBar;
bar.barTintColor = barTintColor;
}

static BOOL RCTFindScrollViewAndRefreshContentInsetInView(UIView *view)
{
if ([view conformsToProtocol:@protocol(RCTAutoInsetsProtocol)]) {
Expand Down

0 comments on commit 305e074

Please sign in to comment.