Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StatusBarIOS moved to StatusBar to address RN deprecation and removal #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ It's still available but may be removed in a later version.
var MyApp = React.createClass({
getInitialState: function() {
return {
currentStatusBarHeight: StatusBarSizeIOS.currentHeight,
currentStatusBarHeight: StatusBarSize.currentHeight,
};
},

componentDidMount: function() {
StatusBarSizeIOS.addEventListener('willChange', this._handleStatusBarSizeWillChange);
StatusBarSizeIOS.addEventListener('didChange', this._handleStatusBarSizeDidChange);
StatusBarSize.addEventListener('willChange', this._handleStatusBarSizeWillChange);
StatusBarSize.addEventListener('didChange', this._handleStatusBarSizeDidChange);
},

componentWillUnmount: function() {
StatusBarSizeIOS.removeEventListener('willChange', this._handleStatusBarSizeWillChange);
StatusBarSizeIOS.removeEventListener('didChange', this._handleStatusBarSizeDidChange);
StatusBarSize.removeEventListener('willChange', this._handleStatusBarSizeWillChange);
StatusBarSize.removeEventListener('didChange', this._handleStatusBarSizeDidChange);
},

_handleStatusBarSizeWillChange: function(nextStatusBarHeight) {
Expand Down
33 changes: 17 additions & 16 deletions StatusBarSizeIOS.js → StatusBarSize.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/**
* @providesModule StatusBarSizeIOS
* @providesModule StatusBarSize
* @flow
*/
'use strict';

const { NativeEventEmitter, StatusBarIOS, NativeModules } = require('react-native');
const { NativeEventEmitter, StatusBar, NativeModules } = require('react-native');
const { StatusBarManager } = NativeModules;
const SBemitter = new NativeEventEmitter(StatusBarManager);

var DEVICE_STATUS_BAR_HEIGHT_EVENTS = {
willChange: 'statusBarFrameWillChange',
Expand All @@ -24,29 +25,29 @@ function getHandlers(type) {
}

/**
* `StatusBarSizeIOS` can tell you what the current height of the status bar
* `StatusBarSize` can tell you what the current height of the status bar
* is, so that you can adjust your layout accordingly when a phone call
* notification comes up, for example.
*
* ### Basic Usage
*
* To see the current height, you can check `StatusBarSizeIOS.currentHeight`, which
* To see the current height, you can check `StatusBarSize.currentHeight`, which
* will be kept up-to-date. However, `currentHeight` will be null at launch
* while `StatusBarSizeIOS` retrieves it over the bridge.
* while `StatusBarSize` retrieves it over the bridge.
*
* ```
* getInitialState: function () {
* return {
* currentStatusBarHeight: StatusBarSizeIOS.currentHeight,
* currentStatusBarHeight: StatusBarSize.currentHeight,
* };
* },
* componentDidMount: function () {
* StatusBarSizeIOS.addEventListener('willChange', this._handleStatusBarFrameWillChange);
* StatusBarSizeIOS.addEventListener('didChange', this._handleStatusBarFrameDidChange);
* StatusBarSize.addEventListener('willChange', this._handleStatusBarFrameWillChange);
* StatusBarSize.addEventListener('didChange', this._handleStatusBarFrameDidChange);
* },
* componentWillUnmount: function () {
* StatusBarSizeIOS.removeEventListener('willChange', this._handleStatusBarFrameWillChange);
* StatusBarSizeIOS.removeEventListener('didChange', this._handleStatusBarFrameDidChange);
* StatusBarSize.removeEventListener('willChange', this._handleStatusBarFrameWillChange);
* StatusBarSize.removeEventListener('didChange', this._handleStatusBarFrameDidChange);
* },
* _handleStatusBarFrameWillChange: function (upcomingStatusBarHeight) {
* console.log('Upcoming StatusBar Height:' + upcomingStatusBarHeight);
Expand All @@ -64,7 +65,7 @@ function getHandlers(type) {
* Open up the phone call status bar in the simulator to see it change.
*/

var StatusBarSizeIOS = {
var StatusBarSize = {

/**
* Add a handler to Status Bar size changes by listening to the event type
Expand All @@ -76,7 +77,7 @@ var StatusBarSizeIOS = {
type: string,
handler: (height: number) => mixed
) {
getHandlers(type).set(handler, StatusBarIOS.addListener(
getHandlers(type).set(handler, SBemitter.addListener(
DEVICE_STATUS_BAR_HEIGHT_EVENTS[type],
(statusBarData) => {
handler(statusBarData.frame.height);
Expand Down Expand Up @@ -104,22 +105,22 @@ var StatusBarSizeIOS = {

};

StatusBarIOS.addListener(
SBemitter.addListener(
DEVICE_STATUS_BAR_HEIGHT_EVENTS.didChange,
(statusBarData) => {
StatusBarSizeIOS.currentHeight = statusBarData.frame.height;
StatusBarSize.currentHeight = statusBarData.frame.height;
}
);

//Wrap in try catch to avoid error on android
try {
StatusBarManager.getHeight(
(statusBarFrameData) => {
StatusBarSizeIOS.currentHeight = statusBarFrameData.height;
StatusBarSize.currentHeight = statusBarFrameData.height;
}
);
} catch (e) {

}

module.exports = StatusBarSizeIOS;
module.exports = StatusBarSize;
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "react-native-status-bar-size",
"version": "0.3.3",
"version": "0.4.0",
"description": "Watch and respond to changes in the iOS status bar height",
"main": "StatusBarSizeIOS.js",
"main": "StatusBarSize.js",
"repository": {
"type": "git",
"url": "[email protected]:jgkim/react-native-status-bar-size.git"
},
"files": [
"StatusBarSizeIOS.js",
"StatusBarSize.js",
"README.md"
],
"author": "Brent Vatne <[email protected]> (https://github.com/brentvatne/)",
Expand Down