/** * The examples provided by Facebook are for non-commercial testing and * evaluation purposes only. * * Facebook reserves all rights not expressly granted. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * @flow */ 'use strict'; 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 = ''; exports.description = 'Component for controlling the status bar'; const colors = [ '#ff0000', '#00ff00', '#0000ff', ]; const barStyles = [ 'default', 'light-content', ]; const showHideTransitions = [ 'fade', 'slide', ]; function getValue(values: Array, index: number): any { return values[index % values.length]; } const StatusBarExample = React.createClass({ getInitialState(): State { return { animated: true, backgroundColor: getValue(colors, 0), showHideTransition: getValue(showHideTransitions, 0), }; }, _colorIndex: 0, _barStyleIndex: 0, _showHideTransitionIndex: 0, render() { return ( ); }, }); const StatusBarStaticExample = React.createClass({ _colorIndex: 0, _barStyleIndex: 0, _showHideTransitionIndex: 0, getInitialState() { return { backgroundColor: getValue(colors, 0), barStyle: getValue(barStyles, 0), hidden: false, networkActivityIndicatorVisible: false, translucent: false, }; }, render() { return ( { const hidden = !this.state.hidden; StatusBar.setHidden(hidden, 'slide'); this.setState({hidden}); }}> hidden: {this.state.hidden ? 'true' : 'false'} iOS { this._barStyleIndex++; const barStyle = getValue(barStyles, this._barStyleIndex); StatusBar.setBarStyle(barStyle, true); this.setState({barStyle}); }}> style: '{getValue(barStyles, this._barStyleIndex)}' { const networkActivityIndicatorVisible = !this.state.networkActivityIndicatorVisible; StatusBar.setNetworkActivityIndicatorVisible(networkActivityIndicatorVisible); this.setState({networkActivityIndicatorVisible}); }}> networkActivityIndicatorVisible: {this.state.networkActivityIndicatorVisible ? 'true' : 'false'} Android { this._colorIndex++; const backgroundColor = getValue(colors, this._colorIndex); StatusBar.setBackgroundColor(backgroundColor, true); this.setState({backgroundColor}); }}> backgroundColor: '{getValue(colors, this._colorIndex)}' { const translucent = !this.state.translucent; const backgroundColor = !this.state.translucent ? 'rgba(0, 0, 0, 0.4)' : 'black'; StatusBar.setTranslucent(translucent); StatusBar.setBackgroundColor(backgroundColor, true); this.setState({ translucent, backgroundColor, }); }}> translucent: {this.state.translucent ? 'true' : 'false'} ); }, }); exports.examples = [{ title: 'StatusBar', render() { return ; }, }, { title: 'StatusBar static API', render() { return ; }, }]; var styles = StyleSheet.create({ wrapper: { borderRadius: 5, marginBottom: 5, }, button: { borderRadius: 5, backgroundColor: '#eeeeee', padding: 10, }, title: { marginTop: 16, marginBottom: 8, fontWeight: 'bold', } });