Control Device Brightness from React Native App

Control Screen Brightness

This is an Example to Control Device Brightness from React Native App using react-native-screen-brightness for Android and IOS. You generally do it in your day to day life but what if you can control the brightness from your own application? Yes, you can do that with the help of the react-native-screen-brightness library.

You can see the use of a screen control feature if you have ever used any UPI or payment transaction app, where you need to scan the QR code for the payment. While scanning the QR code the brightness should be high so that QR code will become more clear other to scan. In this case, you need a screen brightness control feature to provide a better user experience.

To Set the Brightness of the Screen

While using react-native-screen-brightness you can change the screen brightness using



  1. In the case of IOS, Min brightness value is 0 and Max brightness value is 1.
  2. In the case of Android, Min brightness value is 0 and Max brightness value is 255.

To Get the Brightness of the Device

To get the Screen brightness at any point you can use

ScreenBrightness.getBrightness().then(brightness => {
    alert('brightness ' + brightness);

For this example, We are going to use a Slider component which will change the brightness value and a button to get the brightness value. So let’s get started.

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run

npm install -g react-native-cli

Run the following commands to create a new React Native project

react-native init ProjectName

If you want to start a new project with a specific React Native version, you can use the --version argument:

react-native init ProjectName --version X.XX.X
react-native init ProjectName --version react-native@next

This will make a project structure with an index file named App.js in your project directory.

Installation of Dependencies

To use Slider and ScreenBrightness component we need to install react-native-community/slider and react-native-screen-brightness dependencies.
To install this open the terminal and jump into your project using

cd ProjectName

Run the following command to install

npm install --save react-native-screen-brightness
npm install --save @react-native-community/slider

This command will copy all the dependencies into your node_module directory.

Linking of Dependencies

After the installation of the dependencies, you need to link the dependencies using

react-native link @react-native-community/slider
react-native link react-native-screen-brightness

After linking the dependency if you face  Could not Compile Settings File project/android/settings.gradle error while building and installing the project then you can find the solution here.

Hurree!! it is ready for IOS but for Android devices, you need to add some additional permission for that so open the manifest file of your Android project and add

<uses-permission android:name="android.permission.WRITE_SETTINGS" tools:ignore="ProtectedPermissions" />


Now Open App.js in any code editor and replace the code with the following code


/*Example to Control Device Brightness using React Native Application*/
import React, {Component} from 'react';
//Import React
import {Platform, StyleSheet, Text, View, Button, PermissionsAndroid} from 'react-native';
//Import React Native Basic Components
import ScreenBrightness from 'react-native-screen-brightness';
//Import Scren brightness control library
import Slider from '@react-native-community/slider';
//Import Slider to change the brightness

export default class App extends Component {
  constructor(props) {
    this.state = {
      //Initial Brightness
      brightness: 0.2

    ScreenBrightness.getBrightness().then(brightness => {
      alert('brightness ' + brightness);

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.largeText}>Example to Control Screen Brightness in React Native</Text>
        <Text style={{color: 'black'}}>Current Brightness : {this.state.brightness}</Text>
        <View style={{width:200}}>
          {/*Slider with max, min, step and initial value*/}
            onValueChange={(brightness) => {
              this.setState({ brightness });
        <Button title="Get Current Brightness Value" onPress={this.getBrightness.bind(this)}/>

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  largeText: {
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,

To Run the React Native App

Open the terminal again and jump into your project using.
cd ProjectName
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

If you are facing any issue while running the project in an Android device then please scroll down for the solution.

Output Screenshots





Known issue with Android devices

If you are facing the issue in android devices then please follow the below steps:

1. You need to open the project in Android Studio. If you have no idea how to do it then open Android Studio and click the open project option and select the YourProjectName>android directory and click open. Probably you will see the following error.

2. Now Open Project Level build.gradle and make sure it is updated like this.

3. Update the build.gradle file of Module:react-native-screen-brightness to the same compileSdkVersion, buildToolsVersion, minSdkVersion, targetSdkVersion as mentioned in your Project Level build.gradle. Here is mine

4. Now You can see the react-native-screen-brightness directory in the left navigation. Click to expand it and under that expand java and then expand the package mentioned. you will find two java files ScreenBrightnessModule and ScreenBrightnessPackage files their.

5. Please replace the content of both java files with the attached java files. Both files have some changes which are very hard to explain one by one as we have to replace some method so instead of making the changes override the code with these attached Java files.

a) (Please remove .zip in the file name after download)

b) (Please remove .zip in the file name after download)

6. If you have linked your project properly then you have seen an additional line new ScreenBrightnessPackage in MainApplication. Here you can see the red underline. Now to resolve this just pass a random number in it.

7. Now run your project again I hope everything will work well.

8. As you all know Android above API 23 needs runtime permission but in the case of android.permission.WRITE_SETTINGS, I am still struggling to set up runtime permission as it is returning null while asking runtime permission. If I got any solution related to that I’ll surely update the post.

9. Meanwhile, if you run the app in your android device you will see this yellow box.

which shows “Unable to set system brightness” because you have no permission to change the system settings. To solve this issue Open Settings option of your device > Apps & Notifications > App > Search for the YourApplicationName and open the app info by clicking on it.


10. In the last of the Info, you will see Write system settings click on it and switch it on. Now you are good to go.
11. Open your App again and try, It should work now. 🙂

This is how you can Control Device Brightness from React Native App using react-native-screen-brightness for Android and IOS. If you have any doubts or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. 🙂

Related Posts

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.