Skip to content

Commit

Permalink
Some cleanup and organize navigation bar color updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiannucci committed Aug 10, 2019
1 parent e540667 commit dfcdfec
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 45 deletions.
2 changes: 1 addition & 1 deletion NavigationReactNative/sample/twitter/App.js
Expand Up @@ -26,7 +26,7 @@ stateNavigator.navigate('home');

export default () => (
Platform.OS === 'ios' ? (
<TabBarIOS barTintColor="#ffffff" selectedTintColor="#006dbf">
<TabBarIOS>
<TabBarItemIOS title="Home">
<NavigationHandler stateNavigator={stateNavigator}>
<NavigationStack />
Expand Down
2 changes: 1 addition & 1 deletion NavigationReactNative/sample/twitter/Home.ios.js
Expand Up @@ -5,7 +5,7 @@ import Tweets from './Tweets';

export default ({tweets}) => (
<ScrollView contentInsetAdjustmentBehavior="automatic" style={styles.view}>
<NavigationBarIOS title="Home" barTintColor="#ffffff" selectedTintColor="#006dbf" />
<NavigationBarIOS title="Home" />
<Tweets tweets={tweets} />
</ScrollView>
);
Expand Down
2 changes: 1 addition & 1 deletion NavigationReactNative/sample/twitter/Timeline.js
Expand Up @@ -16,7 +16,7 @@ export default ({timeline: {id, name, username, logo, bio,
onIconClicked={() => {
stateNavigator.navigateBack(1)
}} />
<NavigationBarIOS title={name} barTintColor="#ffffff" selectedTintColor="#006dbf" />
<NavigationBarIOS title={name} />
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={styles.view}>
Expand Down
2 changes: 1 addition & 1 deletion NavigationReactNative/sample/twitter/Tweet.js
Expand Up @@ -16,7 +16,7 @@ export default ({tweet: {account: {id: accountId, name, username, logo},
onIconClicked={() => {
stateNavigator.navigateBack(1)
}} />
<NavigationBarIOS title="Tweet" barTintColor="#ffffff" selectedTintColor="#006dbf" />
<NavigationBarIOS title="Tweet" />
<ScrollView contentInsetAdjustmentBehavior="automatic" style={styles.view}>
<View>
<View style={styles.heading}>
Expand Down
2 changes: 1 addition & 1 deletion NavigationReactNative/sample/zoom/Detail.js
Expand Up @@ -7,7 +7,7 @@ export default ({colors, color}) => (
<NavigationContext.Consumer>
{({stateNavigator}) => (
<ScrollView contentInsetAdjustmentBehavior="automatic">
<NavigationBarIOS tintColor={color} titleColor={color === 'red' ? color : null} title="Color">
<NavigationBarIOS tintColor={color} titleColor={color} title="Color">
<RightBarIOS>
<BarButtonIOS systemItem="cancel" onPress={() => {
stateNavigator.navigateBack(1);
Expand Down
2 changes: 1 addition & 1 deletion NavigationReactNative/src/TabBarIOS.tsx
@@ -1,7 +1,7 @@
import React from 'react';
import { requireNativeComponent, Platform, StyleSheet } from 'react-native';

var TabBar = ({children, barTintColor, tintColor}) => <NVTabBar style={styles.tabBar} barTintColor={barTintColor} tintColor={tintColor}>{children}</NVTabBar>;
var TabBar = props => <NVTabBar {...props} style={styles.tabBar} />;

var NVTabBar = requireNativeComponent<any>('NVTabBar', null);

Expand Down
2 changes: 2 additions & 0 deletions NavigationReactNative/src/ios/NVNavigationBarView.h
Expand Up @@ -9,6 +9,8 @@
@property (nonatomic, copy) UIColor *tintColor;
@property (nonatomic, copy) UIColor *titleColor;

-(void)updateColors;

#define NAVIGATION_BAR ((int) 28)

@end
22 changes: 13 additions & 9 deletions NavigationReactNative/src/ios/NVNavigationBarView.m
Expand Up @@ -19,7 +19,19 @@ - (void)didSetProps:(NSArray<NSString *> *)changedProps
if ([changedProps containsObject:@"title"]) {
[self.reactViewController.navigationItem setTitle:self.title];
}


[self updateColors];
}

- (void)willMoveToSuperview:(nullable UIView *)newSuperview
{
[super willMoveToSuperview:newSuperview];
if (!newSuperview) {
[self.reactViewController.navigationController setNavigationBarHidden:false];
}
}

-(void)updateColors {
[self.reactViewController.navigationController.navigationBar setBarTintColor:self.barTintColor];
[self.reactViewController.navigationController.navigationBar setTintColor: self.tintColor];

Expand All @@ -46,12 +58,4 @@ - (void)didSetProps:(NSArray<NSString *> *)changedProps
}
}

- (void)willMoveToSuperview:(nullable UIView *)newSuperview
{
[super willMoveToSuperview:newSuperview];
if (!newSuperview) {
[self.reactViewController.navigationController setNavigationBarHidden:false];
}
}

@end
22 changes: 1 addition & 21 deletions NavigationReactNative/src/ios/NVSceneController.m
Expand Up @@ -45,30 +45,10 @@ - (void)viewWillAppear:(BOOL)animated
if (navigationBar.title.length != 0) {
[self.navigationItem setTitle:navigationBar.title];
}
[self.navigationController.navigationBar setBarTintColor:navigationBar.barTintColor];
[self.navigationController.navigationBar setTintColor:navigationBar.tintColor];

NSMutableDictionary *titleAttributes = [self.navigationController.navigationBar.titleTextAttributes mutableCopy];
if (titleAttributes == nil) {
titleAttributes = @{}.mutableCopy;
}
[titleAttributes removeObjectForKey:NSForegroundColorAttributeName];
if (navigationBar.titleColor != nil) {
titleAttributes[NSForegroundColorAttributeName] = navigationBar.titleColor;
}
[self.navigationController.navigationBar setTitleTextAttributes:titleAttributes];
[navigationBar updateColors];

if (@available(iOS 11.0, *)) {
NSMutableDictionary *largeTitleTextAttributes = [self.navigationController.navigationBar.largeTitleTextAttributes mutableCopy];
if (largeTitleTextAttributes == nil) {
largeTitleTextAttributes = @{}.mutableCopy;
}
[largeTitleTextAttributes removeObjectForKey:NSForegroundColorAttributeName];
if (navigationBar.titleColor != nil) {
largeTitleTextAttributes[NSForegroundColorAttributeName] = navigationBar.titleColor;
}
[self.navigationController.navigationBar setLargeTitleTextAttributes:largeTitleTextAttributes];

self.navigationController.navigationBar.prefersLargeTitles = true;
[self.navigationItem setLargeTitleDisplayMode:navigationBar.largeTitle ? UINavigationItemLargeTitleDisplayModeAlways : UINavigationItemLargeTitleDisplayModeNever];
}
Expand Down
12 changes: 3 additions & 9 deletions NavigationReactNative/src/ios/NVTabBarView.m
Expand Up @@ -22,15 +22,9 @@ - (id)init
- (void)didSetProps:(NSArray<NSString *> *)changedProps
{
[super didSetProps:changedProps];
if ([changedProps containsObject:@"barTintColor"]) {
[_tabBarController.tabBar setBarTintColor:self.barTintColor];
}
if ([changedProps containsObject:@"selectedTintColor"]) {
[_tabBarController.tabBar setTintColor: self.selectedTintColor];
}
if ([changedProps containsObject:@"unselectedTintColor"]) {
[_tabBarController.tabBar setUnselectedItemTintColor: self.unselectedTintColor];
}
[_tabBarController.tabBar setBarTintColor:self.barTintColor];
[_tabBarController.tabBar setTintColor: self.selectedTintColor];
[_tabBarController.tabBar setUnselectedItemTintColor: self.unselectedTintColor];
}

- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex
Expand Down

0 comments on commit dfcdfec

Please sign in to comment.