From eebfd33b70f89a7214ba6aa0804bdf5907033bc2 Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Mon, 23 Jan 2017 12:49:17 -0800 Subject: [PATCH] Expose StatusBar height on iOS Summary: Following the PR https://github.com/facebook/react-native/pull/6195, this adds a `HEIGHT` constant on `StatusBar` for iOS. Combined with `statusBarFrameDidChange` and `statusBarFrameWillChange` StatusBar native events, it solves various problems with In-Call cellar bar / Location bar / others 40pt status bars, and offers a correct `keyboardVerticalOffset` value for the KeyboardAvoidingView component. Closes https://github.com/facebook/react-native/pull/12041 Differential Revision: D4450924 Pulled By: hramos fbshipit-source-id: 664798260f4226140f3fa3f9222a415a305d0d78 --- Examples/UIExplorer/js/StatusBarExample.js | 3 +-- Libraries/Components/StatusBar/StatusBar.js | 4 +--- React/Modules/RCTStatusBarManager.m | 7 +++++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Examples/UIExplorer/js/StatusBarExample.js b/Examples/UIExplorer/js/StatusBarExample.js index 8c60b22ba8f..4c95731a5d8 100644 --- a/Examples/UIExplorer/js/StatusBarExample.js +++ b/Examples/UIExplorer/js/StatusBarExample.js @@ -438,11 +438,10 @@ const examples = [{ render() { return ( - Height (Android only): {StatusBar.currentHeight} pts + Height: {StatusBar.currentHeight} pts ); }, - platform: 'android', }]; exports.examples = examples; diff --git a/Libraries/Components/StatusBar/StatusBar.js b/Libraries/Components/StatusBar/StatusBar.js index f1712b4a52d..68a67d18d08 100644 --- a/Libraries/Components/StatusBar/StatusBar.js +++ b/Libraries/Components/StatusBar/StatusBar.js @@ -134,7 +134,7 @@ function createStackEntry(props: any): any { * * ### Constants * - * `currentHeight` (Android only) The height of the status bar. + * `currentHeight` The height of the status bar. */ class StatusBar extends React.Component { props: { @@ -169,8 +169,6 @@ class StatusBar extends React.Component { // discussion in #6195. /** * The current height of the status bar on the device. - * - * @platform android */ static currentHeight = StatusBarManager.HEIGHT; diff --git a/React/Modules/RCTStatusBarManager.m b/React/Modules/RCTStatusBarManager.m index 849d09436bd..2e28f3f9906 100644 --- a/React/Modules/RCTStatusBarManager.m +++ b/React/Modules/RCTStatusBarManager.m @@ -132,6 +132,13 @@ RCT_EXPORT_METHOD(setNetworkActivityIndicatorVisible:(BOOL)visible) RCTSharedApplication().networkActivityIndicatorVisible = visible; } +- (NSDictionary *)constantsToExport +{ + return @{ + @"HEIGHT": @([UIApplication sharedApplication].statusBarFrame.size.height) + }; +} + #endif //TARGET_OS_TV @end