Skip to content

Commit

Permalink
Fix Constants.topBarHeight (#5252)
Browse files Browse the repository at this point in the history
This approach is still not ideal as it assumes there's a visible stack somewhere in the Hierarchy.
It's better than the current implementation so I'm pushing it and will reiterate in the future if needed.
  • Loading branch information
guyca authored and yogevbd committed Jul 2, 2019
1 parent 8b2d949 commit f19e523
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/ios/Constants.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "Constants.h"
#import "UIViewController+LayoutProtocol.h"

@implementation Constants

Expand All @@ -7,7 +8,7 @@ + (NSDictionary *)getConstants {
}

+ (CGFloat)topBarHeight {
return UIApplication.sharedApplication.delegate.window.rootViewController.navigationController.navigationBar.frame.size.height;
return [UIApplication .sharedApplication.delegate.window.rootViewController getTopBarHeight];
}

+ (CGFloat)statusBarHeight {
Expand Down
2 changes: 2 additions & 0 deletions lib/ios/RNNLayoutProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);

- (UIViewController<RNNLayoutProtocol> *)getCurrentChild;

- (CGFloat) getTopBarHeight;

- (void)mergeOptions:(RNNNavigationOptions *)options;

- (RNNNavigationOptions *)resolveOptions;
Expand Down
4 changes: 4 additions & 0 deletions lib/ios/RNNNavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ - (UIViewController *)getCurrentChild {
return self.topViewController;
}

- (CGFloat)getTopBarHeight {
return self.navigationBar.frame.size.height;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return self.getCurrentChild.supportedInterfaceOrientations;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/ios/RNNRootViewController.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#import "RNNRootViewController.h"
#import <React/RCTConvert.h>
#import "RNNAnimator.h"
#import "RNNPushAnimation.h"
#import "RNNReactView.h"
#import "RNNAnimationsTransitionDelegate.h"
#import "UIViewController+LayoutProtocol.h"

Expand Down Expand Up @@ -93,6 +89,10 @@ - (UIViewController *)getCurrentChild {
return nil;
}

- (CGFloat)getTopBarHeight {
return [[self getCurrentChild] getTopBarHeight];
}

-(void)updateSearchResultsForSearchController:(UISearchController *)searchController {
[self.eventEmitter sendOnSearchBarUpdated:self.layoutInfo.componentId
text:searchController.searchBar.text
Expand Down
12 changes: 8 additions & 4 deletions lib/ios/RNNSideMenuController.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#import "RNNSideMenuController.h"
#import "RNNSideMenuChildVC.h"
#import "MMDrawerController.h"
#import "MMDrawerVisualState.h"

@interface RNNSideMenuController ()
Expand Down Expand Up @@ -92,7 +90,6 @@ - (void)side:(MMDrawerSide)side enabled:(BOOL)enabled {

-(void)setControllers:(NSArray*)controllers {
for (id controller in controllers) {

if ([controller isKindOfClass:[RNNSideMenuChildVC class]]) {
RNNSideMenuChildVC *child = (RNNSideMenuChildVC*)controller;

Expand Down Expand Up @@ -133,12 +130,19 @@ - (UIViewController *)openedViewController {
return self.right;
default:
return self.center;
break;
}
}

- (UIViewController<RNNLayoutProtocol> *)getCurrentChild {
return self.center;
}

- (CGFloat)getTopBarHeight {
for(UIViewController * child in [self childViewControllers]) {
CGFloat childTopBarHeight = [child getTopBarHeight];
if (childTopBarHeight > 0) return childTopBarHeight;
}
return [super getTopBarHeight];
}

@end
8 changes: 8 additions & 0 deletions lib/ios/RNNTabBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ - (UIViewController *)getCurrentChild {
return self.selectedViewController;
}

- (CGFloat)getTopBarHeight {
for(UIViewController * child in [self childViewControllers]) {
CGFloat childTopBarHeight = [child getTopBarHeight];
if (childTopBarHeight > 0) return childTopBarHeight;
}
return [super getTopBarHeight];
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return self.selectedViewController.supportedInterfaceOrientations;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/ios/UIViewController+LayoutProtocol.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ - (UIViewController *)getCurrentChild {
return nil;
}

- (CGFloat)getTopBarHeight {
return 0;
}

- (void)onChildWillAppear {
[self.presenter applyOptions:self.resolveOptions];
[((UISplitViewController *)self.parentViewController) onChildWillAppear];
Expand Down
5 changes: 4 additions & 1 deletion playground/src/services/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const compId = (selfOrCompId) => {
return get(selfOrCompId, 'props.componentId', selfOrCompId);
}

const constants = Navigation.constants;

module.exports = {
mergeOptions,
push,
Expand All @@ -49,5 +51,6 @@ module.exports = {
setDefaultOptions: Navigation.setDefaultOptions.bind(Navigation),
setRoot: Navigation.setRoot.bind(Navigation),
TouchablePreview: Navigation.TouchablePreview,
setStackRoot
setStackRoot,
constants
}

0 comments on commit f19e523

Please sign in to comment.