react-native-scrollable-header icon indicating copy to clipboard operation
react-native-scrollable-header copied to clipboard

Status Bar

Open brendandestefano opened this issue 8 years ago • 2 comments

Any idea how you could animate the status bar color? Like from 'light-content' to 'dark-content'?

brendandestefano avatar Feb 08 '18 21:02 brendandestefano

You could add a listener to an animated value and update the color when passing a certain threshold.

animatedValue.addListener(value => {
  const isLight = value > somethreshold;
  if (this.state.isLight !== isLight) this.setState({isLight});
}
...
<StatusBar animated barStyle={this.state.isLight ? ...} />

janicduplessis avatar Feb 08 '18 23:02 janicduplessis

I found the way you suggested was a bit laggy. This is what I found to work best for any future reference:

<StatusBar animated barStyle={ this.state.isLight ? 'light-content' : 'dark-content' } />
<ScrollView
    scrollEventThrottle={ 16 }
    onScroll={ Animated.event(
        [ { nativeEvent: { contentOffset: { y: this.state.scrollY } } } ],
            { listener: _.debounce(this.checkStatusBarColor, 16) }
        ) }
>
...

brendandestefano avatar Feb 12 '18 15:02 brendandestefano