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 Aug 12, 2016
1 parent 52e6c02 commit 53f3069
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
*/

#import <UIKit/UIKit.h>

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

@interface RCTNavItem : UIView

@property (nonatomic, copy) NSString *title;
@property (nonatomic, strong) UIImage *titleImage;
@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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

@implementation RCTNavItem

@synthesize delegate = _delegate;
@synthesize backButtonItem = _backButtonItem;
@synthesize leftButtonItem = _leftButtonItem;
@synthesize rightButtonItem = _rightButtonItem;
Expand All @@ -24,6 +25,22 @@ - (UIImageView *)titleImageView
}
}

- (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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 53f3069

Please sign in to comment.