From e0655d19821072f7d2ace9bea42902ab50e9d861 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Thu, 28 May 2015 13:32:44 -0700 Subject: [PATCH] Hacky fix for navigation hidden --- App/Components/Menu.js | 8 ++++---- App/Screens/Themes.js | 5 +++-- index.ios.js | 16 +++++++++++----- .../Components/Navigation/NavigatorIOS.ios.js | 10 ++++++++++ .../react-native/React/Views/RCTNavItem.h | 2 ++ .../react-native/React/Views/RCTNavItem.m | 9 +++++++++ .../React/Views/RCTWrapperViewController.h | 2 ++ .../React/Views/RCTWrapperViewController.m | 8 ++++++++ 8 files changed, 49 insertions(+), 11 deletions(-) diff --git a/App/Components/Menu.js b/App/Components/Menu.js index 9832421..0b4cfed 100644 --- a/App/Components/Menu.js +++ b/App/Components/Menu.js @@ -21,9 +21,9 @@ class Menu extends React.Component{ leftButtonTitle: 'Back', onLeftButtonPress: () => { this.props.navigator.pop(); - this.props.toggleNavigation(); + var self = this; }, - passProps: { navigator: this.props.navigator } + passProps: { navigator: this.props.navigator, toggleNavigation: this.props.toggleNavigation } }) } navigateToSettings() { @@ -39,7 +39,7 @@ class Menu extends React.Component{ this.props.navigator.pop(); this.props.toggleNavigation(); }, - passProps: { navigator: this.props.navigator } + passProps: { navigator: this.props.navigator, toggleNavigation: this.props.toggleNavigation } }) } render() { @@ -84,4 +84,4 @@ var styles = StyleSheet.create({ }, }); -module.exports = Menu; \ No newline at end of file +module.exports = Menu; diff --git a/App/Screens/Themes.js b/App/Screens/Themes.js index f57bdb4..59e950c 100644 --- a/App/Screens/Themes.js +++ b/App/Screens/Themes.js @@ -27,8 +27,9 @@ class Themes extends React.Component{ var styles = StyleSheet.create({ container: { flex: 1, - backgroundColor: 'white' + backgroundColor: 'white', + paddingTop: 60 } }) -module.exports = Themes; \ No newline at end of file +module.exports = Themes; diff --git a/index.ios.js b/index.ios.js index 22540e7..68173ca 100644 --- a/index.ios.js +++ b/index.ios.js @@ -13,28 +13,34 @@ class ReactNativeBug extends React.Component{ constructor(props) { super(props); this.state = { - hideNavbar: true + hideNavbar: false }; } + componentWillMount() { StatusBarIOS.setHidden(true); } + shouldComponentUpdate(nextProps, nextState) { console.log(this.state, nextState); // Object {hideNavbar: true} Object {hideNavbar: false} return true; } + toggleNavigation() { + console.log('clicked'); + this.setState({ hideNavbar: !this.state.hideNavbar }); } + render() { - var initialRoute = { - component: ScreenWithMenu, - title: 'Screen', + var initialRoute = { + component: ScreenWithMenu, + title: 'Screen', passProps: { toggleNavigation: this.toggleNavigation.bind(this) - } + } }; return ( diff --git a/node_modules/react-native/Libraries/Components/Navigation/NavigatorIOS.ios.js b/node_modules/react-native/Libraries/Components/Navigation/NavigatorIOS.ios.js index ef3ecd1..ec5cde9 100644 --- a/node_modules/react-native/Libraries/Components/Navigation/NavigatorIOS.ios.js +++ b/node_modules/react-native/Libraries/Components/Navigation/NavigatorIOS.ios.js @@ -27,6 +27,7 @@ var logError = require('logError'); var merge = require('merge'); var TRANSITIONER_REF = 'transitionerRef'; +var NAVIGATOR_ITEM_REF = 'navigatorItemRef'; var PropTypes = React.PropTypes; @@ -378,6 +379,14 @@ var NavigatorIOS = React.createClass({ }; }, + componentWillReceiveProps: function(nextProps:any) { + if (nextProps.navigationBarHidden !== this.props.navigationBarHidden) { + if (this.refs[NAVIGATOR_ITEM_REF]) { + this.refs[NAVIGATOR_ITEM_REF].setNativeProps({navigationBarHidden: nextProps.navigationBarHidden}); + } + } + }, + childContextTypes: { onFocusRequested: React.PropTypes.func, focusEmitter: React.PropTypes.instanceOf(EventEmitter), @@ -598,6 +607,7 @@ var NavigatorIOS = React.createClass({ this.props.itemWrapperStyle, route.wrapperStyle ]} + ref={NAVIGATOR_ITEM_REF} backButtonIcon={this._imageNameFromSource(route.backButtonIcon)} backButtonTitle={route.backButtonTitle} leftButtonIcon={this._imageNameFromSource(route.leftButtonIcon)} diff --git a/node_modules/react-native/React/Views/RCTNavItem.h b/node_modules/react-native/React/Views/RCTNavItem.h index cd9833a..b172395 100644 --- a/node_modules/react-native/React/Views/RCTNavItem.h +++ b/node_modules/react-native/React/Views/RCTNavItem.h @@ -8,9 +8,11 @@ */ #import +#import "RCTWrapperViewController.h" @interface RCTNavItem : UIView +@property (nonatomic, weak) RCTWrapperViewController *delegate; @property (nonatomic, copy) NSString *title; @property (nonatomic, strong) UIImage *leftButtonIcon; @property (nonatomic, copy) NSString *leftButtonTitle; diff --git a/node_modules/react-native/React/Views/RCTNavItem.m b/node_modules/react-native/React/Views/RCTNavItem.m index f875e6a..e36a562 100644 --- a/node_modules/react-native/React/Views/RCTNavItem.m +++ b/node_modules/react-native/React/Views/RCTNavItem.m @@ -11,6 +11,7 @@ @implementation RCTNavItem +@synthesize delegate = _delegate; @synthesize backButtonItem = _backButtonItem; @synthesize leftButtonItem = _leftButtonItem; @synthesize rightButtonItem = _rightButtonItem; @@ -111,4 +112,12 @@ - (UIBarButtonItem *)rightButtonItem return _rightButtonItem; } +- (void)setNavigationBarHidden:(BOOL)navigationBarHidden +{ + if (navigationBarHidden != _navigationBarHidden) { + _navigationBarHidden = navigationBarHidden; + [self.delegate navigationBarHiddenDidChange:navigationBarHidden]; + } +} + @end diff --git a/node_modules/react-native/React/Views/RCTWrapperViewController.h b/node_modules/react-native/React/Views/RCTWrapperViewController.h index 09e6478..a48030f 100644 --- a/node_modules/react-native/React/Views/RCTWrapperViewController.h +++ b/node_modules/react-native/React/Views/RCTWrapperViewController.h @@ -30,6 +30,8 @@ didMoveToNavigationController:(UINavigationController *)navigationController; - (instancetype)initWithNavItem:(RCTNavItem *)navItem eventDispatcher:(RCTEventDispatcher *)eventDispatcher; +- (void)navigationBarHiddenDidChange:(BOOL)navigationBarHidden; + @property (nonatomic, weak) id navigationListener; @property (nonatomic, strong) RCTNavItem *navItem; diff --git a/node_modules/react-native/React/Views/RCTWrapperViewController.m b/node_modules/react-native/React/Views/RCTWrapperViewController.m index 400ce5f..d314c20 100644 --- a/node_modules/react-native/React/Views/RCTWrapperViewController.m +++ b/node_modules/react-native/React/Views/RCTWrapperViewController.m @@ -45,6 +45,7 @@ - (instancetype)initWithNavItem:(RCTNavItem *)navItem { if (self = [self initWithContentView:navItem eventDispatcher:eventDispatcher]) { _navItem = navItem; + _navItem.delegate = self; } return self; } @@ -57,6 +58,13 @@ - (void)viewWillLayoutSubviews _currentBottomLayoutGuide = self.bottomLayoutGuide; } +- (void)navigationBarHiddenDidChange:(BOOL)navigationBarHidden +{ + [self.navigationController + setNavigationBarHidden:_navItem.navigationBarHidden + animated:YES]; +} + - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated];