Git Product home page Git Product logo

react-native-status-bar-size's Introduction

react-native-status-bar-size

Watch and respond to changes in the iOS status bar height.

Add it to your project

  1. Run npm install react-native-status-bar-size --save
  2. Follow the example below to use it in JS

Deprecated change Event

The change event has been deprecated. The didChange event should be used instead. It's still available but may be removed in a later version.

Example

var MyApp = React.createClass({
   getInitialState: function() {
     return {
       currentStatusBarHeight: StatusBarSizeIOS.currentHeight,
     };
   },

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

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

   _handleStatusBarSizeWillChange: function(nextStatusBarHeight) {
     console.log('Will Change: ' + nextStatusBarHeight);
   },

   _handleStatusBarSizeDidChange: function(currentStatusBarHeight) {
     console.log('changed');
     this.setState({ currentStatusBarHeight: currentStatusBarHeight });
   },

   render: function() {
     return (
       <View style={{flex: 1, backgroundColor: 'white', justifyContent: 'center', alignItems: 'center'}}>
         <Text>Current status bar height is: {this.state.currentStatusBarHeight}</Text>
       </View>
     );
   },
});

Demo gif

react-native-status-bar-size's People

Contributors

aronallen avatar brentvatne avatar ckknight avatar dsibiski avatar jedlau avatar jgkim avatar npomfret avatar rajaishwary avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-native-status-bar-size's Issues

[RFC] Can I drop statusBar*WillChange and add an API directly to react-native?

I'd like to make a change to react-native that will fix an issue with the current iOS status bar height calculation and expose an API as part of react-native.

  • The undocumented NativeModules.StatusBarManager.getHeight is going to go away and the format of the statusBarFrameDidChange event will change, so this library will break. But there will be an API that replaces in in react-native itself.
  • I am not going to include the x and width frame properties, usage of them doesn't make sense and keeping them makes doing this cross-platform a mess (They are basically always x=0 and width=viewport.width; and because Android only has a status bar height definition I'd have to overcomplicate the Android StatusBarManager to also lookup screen width for something no-one would use)
  • The problem with height calculation is that the In-Call Status Bar is declared by iOS as making the StatusBar 40px, however when that happens iOS actually pushes the app down 20px. In other words the app still has only 20px to care about. This is an issue now because iPhone X has a 44px Status Bar and we need a native way of exposing this and on top of that iOS 11 has a new behaviour where the Status Bar height is 0 in landscape mode. I found a way to fix this by subtracting the y offset of the root view. However this cannot be done before the status bar actually changes, so I have to drop the statusBarFrameWillChange event.
    • If you explicitly want the actual height of the Status Bar instead of the height of the overlap you have to deal with that is still possible, I expose the y offset as well so you just have to frame.y + frame.height and you'll get the value you had before.

Does this sound ok?

can the OS force the status bar to show at times?

I'm worried that the React Native APIs to hide the status bar can be overriden by the OS. This is particularly a problem for this reason: if you design your app to not include a status bar, but then iOS forces it to show for some reason, then it could break the design of your app.

I'm wondering if and when are the times it can be forced to show? Is it only phone calls or recording video in another app and that sort of thing? Or can it just appear for less important reasons (and often) whenever the iOS wants to?

Weird use of types is causing a Flow error

On this line - https://github.com/brentvatne/react-native-status-bar-size/blob/master/StatusBarSizeIOS.js#L88

You're using a Function type as the key to index into an object. Is this a mistake?

I'm surprised you guys have // @flow at the top of the file, because Flow would have caught the issue for you. At the moment, Flow insists on checking your module as part of my project, and I have no way to even stifle the Flow error short of forking your package.

Not compatible with RN>=0.66

When using RN >= 0.66 this error is thrown:

Invariant Violation: StatusBarIOS has been removed from React Native. Has been merged with StatusBar. See https://reactnative.dev/docs/statusbar

react-native-status-bar-size uses StatusBarIOS in the addListener function

Update:
โ€“ I attempted working on a fix but I couldn't since I am blocked RN migrating the StatusBarIOS events to StatusBar
โ€“ Related issue facebook/react-native#32297

StatusBarSizeIOS.currentHeight === null ?

Hi,
I have some issues getting the status bar size, in getInitialState() I get null when calling StatusBarSizeIOS.currentHeight.

Also, if I do device rotate left nothing will trigger, but then when I do device rotate right I get a 'willChange' event, and the value I get is 0, which is wrong completely.

So basically, I cannot get status bar size at all, and in rare occasions when I do get a value- it's wrong.

libRNStatusBarSize.a not found

Hi there,
I'm trying to get the iOS status bar height using this package
but then I'm not able to find and add libRNStatusBarSize.a file in my xcode after npm install
what am I missing?

any comments will be appreciated!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.