From 7f0c85eef0f181f3de4cee7ebc2f223298886483 Mon Sep 17 00:00:00 2001 From: Gary Fung Date: Sat, 30 Jan 2021 12:14:56 -0800 Subject: [PATCH 1/2] Address RN error: Warning: StatusBarIOS has been merged with StatusBar and will be removed in a future release. Use StatusBar for mutating the status bar - StatusBarIOS moved to StatusBar - StatusBarSizeIOS module renamed to StatusBarSize accordingly - updated README - version bumped to 0.4.0 --- README.md | 10 ++++---- StatusBarSizeIOS.js => StatusBarSize.js | 32 ++++++++++++------------- package.json | 6 ++--- 3 files changed, 24 insertions(+), 24 deletions(-) rename StatusBarSizeIOS.js => StatusBarSize.js (70%) diff --git a/README.md b/README.md index 22d8480..98f079f 100644 --- a/README.md +++ b/README.md @@ -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) { diff --git a/StatusBarSizeIOS.js b/StatusBarSize.js similarity index 70% rename from StatusBarSizeIOS.js rename to StatusBarSize.js index 9faac08..525b1bd 100644 --- a/StatusBarSizeIOS.js +++ b/StatusBarSize.js @@ -1,10 +1,10 @@ /** - * @providesModule StatusBarSizeIOS + * @providesModule StatusBarSize * @flow */ 'use strict'; -const { NativeEventEmitter, StatusBarIOS, NativeModules } = require('react-native'); +const { NativeEventEmitter, StatusBar, NativeModules } = require('react-native'); const { StatusBarManager } = NativeModules; var DEVICE_STATUS_BAR_HEIGHT_EVENTS = { @@ -24,29 +24,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); @@ -64,7 +64,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 @@ -76,7 +76,7 @@ var StatusBarSizeIOS = { type: string, handler: (height: number) => mixed ) { - getHandlers(type).set(handler, StatusBarIOS.addListener( + getHandlers(type).set(handler, StatusBar.addListener( DEVICE_STATUS_BAR_HEIGHT_EVENTS[type], (statusBarData) => { handler(statusBarData.frame.height); @@ -104,10 +104,10 @@ var StatusBarSizeIOS = { }; -StatusBarIOS.addListener( +StatusBar.addListener( DEVICE_STATUS_BAR_HEIGHT_EVENTS.didChange, (statusBarData) => { - StatusBarSizeIOS.currentHeight = statusBarData.frame.height; + StatusBarSize.currentHeight = statusBarData.frame.height; } ); @@ -115,11 +115,11 @@ StatusBarIOS.addListener( try { StatusBarManager.getHeight( (statusBarFrameData) => { - StatusBarSizeIOS.currentHeight = statusBarFrameData.height; + StatusBarSize.currentHeight = statusBarFrameData.height; } ); } catch (e) { } -module.exports = StatusBarSizeIOS; +module.exports = StatusBarSize; diff --git a/package.json b/package.json index ebb6dd0..443ee50 100644 --- a/package.json +++ b/package.json @@ -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": "git@github.com:jgkim/react-native-status-bar-size.git" }, "files": [ - "StatusBarSizeIOS.js", + "StatusBarSize.js", "README.md" ], "author": "Brent Vatne (https://github.com/brentvatne/)", From 7faaae5f1f3a32cbc8f6c8b5a826aadff77b545c Mon Sep 17 00:00:00 2001 From: Gary Fung Date: Sat, 30 Jan 2021 15:23:18 -0800 Subject: [PATCH 2/2] hook up emitter and listener, as addListener was available on StatusBarIOS but not on StatusBar > TypeError: StatusBar.addListener is not a function --- StatusBarSize.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/StatusBarSize.js b/StatusBarSize.js index 525b1bd..6bed058 100644 --- a/StatusBarSize.js +++ b/StatusBarSize.js @@ -6,6 +6,7 @@ const { NativeEventEmitter, StatusBar, NativeModules } = require('react-native'); const { StatusBarManager } = NativeModules; +const SBemitter = new NativeEventEmitter(StatusBarManager); var DEVICE_STATUS_BAR_HEIGHT_EVENTS = { willChange: 'statusBarFrameWillChange', @@ -76,7 +77,7 @@ var StatusBarSize = { type: string, handler: (height: number) => mixed ) { - getHandlers(type).set(handler, StatusBar.addListener( + getHandlers(type).set(handler, SBemitter.addListener( DEVICE_STATUS_BAR_HEIGHT_EVENTS[type], (statusBarData) => { handler(statusBarData.frame.height); @@ -104,7 +105,7 @@ var StatusBarSize = { }; -StatusBar.addListener( +SBemitter.addListener( DEVICE_STATUS_BAR_HEIGHT_EVENTS.didChange, (statusBarData) => { StatusBarSize.currentHeight = statusBarData.frame.height;