Search code examples
react-nativescreen-brightness

React Native : How to get device Screen Brightness and render it


I`m creating an React App to display device Info. I want to render Screen Brightness level, not in Console. How do I do it?

DeviceBrightness.getSystemBrightnessLevel().then(function(luminous) {
    console.log(luminous)
})

I expected to render the screen brightness level, not to display in console


Solution

  • import DeviceBrightness from 'react-native-device-brightness';
    export default class App extends Component{
        constructor(props){
        super(props);
        this.state = {
      isLoaded: false,
      brightness: 0,
    };
    
    }
    componentWillMount() {
    DeviceBrightness.getSystemBrightnessLevel()
      .then((luminous) =>{
        this.setState({
          brightness: luminous,
          isLoaded: true,
        });
      });
    

    }

    render() {
    return (
      <View style={styles.container}>
    <Text style={styles.instructions}>{this.state.brightness}</Text>
     </View>
    );
    

    } }