react-native-dimmer
A plugin that allows you to enable (eventually lock the device) and disable the screen dim in your React Native app. Works in both iOS and Android.
Installation
$ npm install react-native-dimmer --save
iOS
In the XCode's "Project navigator", right click on your project's
"Libraries" folder ➜ Add Files to <...>
.
Go to node_modules
➜ react-native-dimmer
➜ select the contents
of ios
folder. Make sure RNDimmer.m
is listed under "Compile Sources"
in your project's "Build Phases" tab.
Android
Add react-native-dimmer
to your ./android/settings.gradle
file as follows:
include ':react-native-dimmer'project(':react-native-dimmer').projectDir = new File(settingsDir, '../node_modules/react-native-dimmer/android')
Include it as dependency in ./android/app/build.gradle
file:
dependencies { ... compile project(':react-native-dimmer')}
Finally, you need to add the package within the ReactInstanceManager
of your
MainActivity (./android/app/src/main/java/your/bundle/MainActivity.java
):
// <---- import this one ...@Overrideprotected List<ReactPackage> { return Arrays.<ReactPackage>;}
After that, you will need to recompile
your project with react-native run-android
.
Usage
;;... ... { // Enable dimmer this; } { // Disable dimmer this; } async { try await RNDimmer; console; catch e console; } ...