35 KiB
id, title, original_id
| id | title | original_id |
|---|---|---|
| version-0.21-statusbar | statusbar | statusbar |
StatusBar # | Edit on GitHub |
Component to control the app status bar.
Usage with Navigator #
It is possible to have multiple StatusBar components mounted at the same
time. The props will be merged in the order the StatusBar components were
mounted. One use case is to specify status bar styles per route using Navigator.
Props #
animated bool #
If the transition between status bar property changes should be animated. Supported for backgroundColor, barStyle and hidden.
hidden bool #
If the status bar is hidden.
androidtranslucent bool #
If the status bar is translucent. When translucent is set to true, the app will draw under the status bar. This is useful when using a semi transparent status bar color.
iosbarStyle enum('default', 'light-content') #
Sets the color of the status bar text.
iosnetworkActivityIndicatorVisible bool #
If the network activity indicator should be visible.
iosshowHideTransition enum('fade', 'slide') #
The transition effect when showing and hiding the status bar using the hidden
prop. Defaults to 'fade'.
Examples # | Edit on GitHub |
const React = require('react-native'); const { StyleSheet, View, Text, TouchableHighlight, StatusBar, } = React;
type BarStyle = 'default' | 'light-content'; type ShowHideTransition = 'fade' | 'slide';
type State = { animated: boolean, backgroundColor: string, hidden?: boolean, showHideTransition: ShowHideTransition, translucent?: boolean, barStyle?: BarStyle, networkActivityIndicatorVisible?: boolean };
exports.framework = 'React'; exports.title = '<StatusBar>'; exports.description = 'Component for controlling the status bar';
const colors = [ '#ff0000', '#00ff00', '#0000ff', ];
const barStyles = [ 'default', 'light-content', ];
const showHideTransitions = [ 'fade', 'slide', ];
const StatusBarExample = React.createClass({ getInitialState(): State { return { animated: true, backgroundColor: this._getValue(colors, 0), showHideTransition: this._getValue(showHideTransitions, 0), }; },
_colorIndex: 0, _barStyleIndex: 0, _showHideTransitionIndex: 0,
_getValue(values: Array<any>, index: number): any { return values[index % values.length]; },
render() { return ( <View> <StatusBar backgroundColor={this.state.backgroundColor} translucent={this.state.translucent} hidden={this.state.hidden} showHideTransition={this.state.showHideTransition} animated={this.state.animated} barStyle={this.state.barStyle} networkActivityIndicatorVisible={this.state.networkActivityIndicatorVisible} /> <View> <TouchableHighlight style={styles.wrapper} onPress={() => this.setState({animated: !this.state.animated})}> <View style={styles.button}> <Text>animated: {this.state.animated ? 'true' : 'false'}</Text> </View> </TouchableHighlight> </View> <View> <TouchableHighlight style={styles.wrapper} onPress={() => this.setState({hidden: !this.state.hidden})}> <View style={styles.button}> <Text>hidden: {this.state.hidden ? 'true' : 'false'}</Text> </View> </TouchableHighlight> </View> <Text style={styles.title}>iOS</Text> <View> <TouchableHighlight style={styles.wrapper} onPress={() => { this._barStyleIndex++; this.setState({barStyle: this._getValue(barStyles, this._barStyleIndex)}); }}> <View style={styles.button}> <Text>style: '{this._getValue(barStyles, this._barStyleIndex)}'</Text> </View> </TouchableHighlight> </View> <View> <TouchableHighlight style={styles.wrapper} onPress={() => this.setState({ networkActivityIndicatorVisible: !this.state.networkActivityIndicatorVisible, })}> <View style={styles.button}> <Text> networkActivityIndicatorVisible: {this.state.networkActivityIndicatorVisible ? 'true' : 'false'} </Text> </View> </TouchableHighlight> </View> <View> <TouchableHighlight style={styles.wrapper} onPress={() => { this._showHideTransitionIndex++; this.setState({ showHideTransition: this._getValue(showHideTransitions, this._showHideTransitionIndex), }); }}> <View style={styles.button}> <Text> showHideTransition: '{this._getValue(showHideTransitions, this._showHideTransitionIndex)}' </Text> </View> </TouchableHighlight> </View> <Text style={styles.title}>Android</Text> <View> <TouchableHighlight style={styles.wrapper} onPress={() => { this._colorIndex++; this.setState({backgroundColor: this._getValue(colors, this._colorIndex)}); }}> <View style={styles.button}> <Text>backgroundColor: '{this._getValue(colors, this._colorIndex)}'</Text> </View> </TouchableHighlight> </View> <View> <TouchableHighlight style={styles.wrapper} onPress={() => { this.setState({ translucent: !this.state.translucent, backgroundColor: !this.state.translucent ? 'rgba(0, 0, 0, 0.4)' : 'black', }); }}> <View style={styles.button}> <Text>translucent: {this.state.translucent ? 'true' : 'false'}</Text> </View> </TouchableHighlight> </View> </View> ); }, });
exports.examples = [{ title: 'Status Bar', render() { return <StatusBarExample />; }, }];
var styles = StyleSheet.create({ wrapper: { borderRadius: 5, marginBottom: 5, }, button: { borderRadius: 5, backgroundColor: '#eeeeee', padding: 10, }, title: { marginTop: 16, marginBottom: 8, fontWeight: 'bold', } });