Coder Social home page Coder Social logo

react-native-screen-brightness's Introduction

react-native-screen-brightness

Access and update the system brightness on a device.

React Native compatibility

React Native version Compatible react-native-screen-brightness version
v0.60+ v2.x
v0.27 - v0.59 v1.x

Install

Install with yarn or npm.

yarn add react-native-screen-brightness
npm i --save react-native-screen-brightness

Example

import ScreenBrightness from 'react-native-screen-brightness';

ScreenBrightness.setBrightness(0.5); // between 0 and 1

ScreenBrightness.getBrightness().then(brightness => {
  console.log('brightness', brightness);
});

react-native-screen-brightness's People

Contributors

atticoos avatar brianmuse avatar cchestnut91 avatar christophermark avatar koenpunt avatar mars-lan avatar matthiasleitner avatar yinghang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-screen-brightness's Issues

Setbrightness null

I am use version 1.0.1 and RN 0.58.6, _tlreactnativeScreenBrightness.default.setBrigthness always null

NPM Build failing on IOS and Android

Could you please public 0.2.0 to NPM? This way people wont have to do all of these manual fixes themselves.

Just for reference: #12 does fix the build issues on IOS.

If you need any more info from me let me know.

Please make the androidx.core version able to set from a variable.

Hello!

Would it be possible to make the androidx.core a variable that can be set similar to how it works in react-native-netinfo repo? If you follow the thread, the issue is very similar.

react-native-netinfo/react-native-netinfo#491 (comment)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > The minCompileSdk (31) specified in a
     dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
     is greater than this module's compileSdkVersion (android-30).
     Dependency: androidx.core:core:1.7.0-alpha02.

We specifically run into this problem while trying to build for SDKVersion 30, which seems incompatiable with the latest androidx.core.

AndroidX Support?

Looks like i'm being forced to upgrade to the AndroidX support library. This means I have to modify the imports to get it to compile. Is there an NPM version that can be used with AndroidX?

Task :react-native-screen-brightness:compileReleaseJavaWithJavac FAILED
210 actionable tasks: 209 executed, 1 up-to-date
/Users/vsts/agent/2.158.0/work/1/s/node_modules/react-native-screen-brightness/android/src/main/java/com/robinpowered/react/ScreenBrightness/ScreenBrightnessModule.java:10: error: package android.support.v4.content does not exist
import android.support.v4.content.ContextCompat;
^
1 error

Thanks a bunch!

Exception 'threading violation: expected the main thread' was thrown while invoking setBrightness on target ScreenBrightness with params ( "0.8", 4186, 4187 )

Xcode 11
MacOS 10.14.6 (18G95
Simulator iPhone X 13.0
iPhone 6s 13.1.2

Any attempt to setBrighntess to a higher value than 0.5 results in the following error

Exception 'threading violation: expected the main thread' was thrown while invoking setBrightness on target ScreenBrightness with params (
    "0.55",
    3706,
    3707
)
callstack: (
	0   CoreFoundation                      0x00007fff23b98bde __exceptionPreprocess + 350
	1   libobjc.A.dylib                     0x00007fff503b5b20 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff23b98958 +[NSException raise:format:arguments:] + 88
	3   Foundation                          0x00007fff255eb6f5 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
	4   FrontBoardServices                  0x00007fff363306d7 -[FBSSerialQueue assertOnQueue] + 236
	5   FrontBoardServices                  0x00007fff362e00d7 -[FBSSceneImpl updateClientSettings:withTransitionContext:] + 71
	6   FrontBoardServices                  0x00007fff362e03be -[FBSSceneImpl updateClientSettingsWithTransitionBlock:] + 154
	7   FrontBoardServices                  0x00007fff362e02e3 -[FBSSceneImpl updateClientSettingsWithBlock:] + 110
	8   UIKitCore                           0x00007fff46cbe390 -[FBSScene(UIApp) updateUIClientSettingsWithBlock:] + 160
	9   UIKitCore                           0x00007fff46db7f80 -[UIDevice _setBacklightLevel:] + 152
	10  UIKitCore                           0x00007fff46dc2bb4 -[UIScreen setBrightness:] + 396
	11  quancy                              0x00000001041dadb6 -[ScreenBrightness brightnessLevel:setSystemBrightnessResolver:setSystemBrightnessRejector:] + 134
	12  CoreFoundation                      0x00007fff23b9f95c __invoking___ + 140
	13  CoreFoundation                      0x00007fff23b9cd8f -[NSInvocation invoke] + 287
	14  CoreFoundation                      0x00007fff23b9d1f4 -[NSInvocation invokeWithTarget:] + 68
	15  quancy                              0x0000000103df63f2 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2658
	16  quancy                              0x0000000103e90317 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 791
	17  quancy                              0x0000000103e8fe23 _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 131
	18  quancy                              0x0000000103e8fd99 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 25
	19  libdispatch.dylib                   0x00007fff511fb888 _dispatch_call_block_and_release + 12
	20  libdispatch.dylib                   0x00007fff511fc7f9 _dispatch_client_callout + 8
	21  libdispatch.dylib                   0x00007fff51202566 _dispatch_lane_serial_drain + 707
	22  libdispatch.dylib                   0x00007fff51202f9c _dispatch_lane_invoke + 388
	23  libdispatch.dylib                   0x00007fff5120d06c _dispatch_workloop_worker_thread + 626
	24  libsystem_pthread.dylib             0x00007fff5141c611 _pthread_wqthread + 421
	25  libsystem_pthread.dylib             0x00007fff5141c3fd start_wqthread + 13
)

Android: setBrightness not working

Since migrating to 0.2.0 setBrightness is not working for me anymore, setAppBrightness does work. Probably related to issues with requesting the permission? I am using RN 0.31.0

Does this package need linking?

I'm confused. Why don't the docs say this anywhere. Very poor documentation.

I tried to link this package and it crashed, tried to do it manually but it fails at the build:

Task :react-native-screen-brightness:compileDebugJavaWithJavac
/Users/iuliuvisovan/Desktop/olly-react/node_modules/react-native-screen-brightness/android/src/main/java/com/robinpowered/react/ScreenBrightness/ScreenBrightnessModule.java:28: error: ScreenBrightnessModule is not abstract and does not override abstract method onNewIntent(Intent) in ActivityEventListener
public class ScreenBrightnessModule extends ReactContextBaseJavaModule
^
/Users/iuliuvisovan/Desktop/olly-react/node_modules/react-native-screen-brightness/android/src/main/java/com/robinpowered/react/ScreenBrightness/ScreenBrightnessModule.java:64: error: method does not override or implement a method from a supertype
@OverRide
^
/Users/iuliuvisovan/Desktop/olly-react/node_modules/react-native-screen-brightness/android/src/main/java/com/robinpowered/react/ScreenBrightness/ScreenBrightnessPackage.java:33: error: method does not override or implement a method from a supertype
@OverRide
^
3 errors

FAILURE: Build failed with an exception.

Different BRIGHTNESS_MAX

I am using this library on a MIMAX 3 and the BRIGHTNESS_MAX is 4095. The library has a hardcoded value of 255 which prevents me from setting the screen brightness to the max.

I think the value BRIGHTNESS_MAX should be based on the device instead of a hardcoded value.

【Solve】Build failed with an exception

Hello, I follow it .

LINK

But I can not build it successfully.

:react-native-screen-brightness:compileReleaseJavaWithJavac
D:\Racti Native\Anping_V002\node_modules\react-native-screen-brightness\android\src\main\java\com\robinpowered\react\ScreenBrightness\ScreenBrightnessModule.java:28: error: ScreenBrightnessModule is not abstract and does not override abstract method onNewIntent(Intent) in ActivityEventListener
public class ScreenBrightnessModule extends ReactContextBaseJavaModule
       ^
D:\Racti Native\Anping_V002\node_modules\react-native-screen-brightness\android\src\main\java\com\robinpowered\react\ScreenBrightness\ScreenBrightnessModule.java:64: error: method does not override or implement a method from a supertype
    @Override
    ^
2 errors
:react-native-screen-brightness:compileReleaseJavaWithJavac FAILED

FAILURE: Build failed with an exception.

How can I modify it?
Thanks

Trying to use this, can't get it to install and work

Hi -- I'd like to contribute to the installation guide.

I tried just adding the javascript code, and it didn't work, failing in the debugger with:

Cannot read property 'setBrightness' of undefined

So I'm guessing what to do here :-) based on various other react-native plugins.

So I've changed android/app/build.gradle to have:

--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -131,4 +131,5 @@ dependencies {
     compile fileTree(dir: "libs", include: ["*.jar"])
     compile "com.android.support:appcompat-v7:23.0.1"
     compile "com.facebook.react:react-native:0.20.+"
+    compile project(":react-native-screen-brightness")
 }

Added:

import com.robinpowered.react.ScreenBrightness.ScreenBrightnessPackage;

to my MainActivity.java file, which also has:

@@ -51,7 +53,8 @@ public class MainActivity extends ReactActivity {
     @Override
     protected List<ReactPackage> getPackages() {
       return Arrays.<ReactPackage>asList(
-        new MainReactPackage()
+        new MainReactPackage(),
+        new ScreenBrightnessPackage(this)
       );
     }
 }

Added to android/settings.gradle:

include ':react-native-screen-brightness'
project(':react-native-screen-brightness').projectDir = new File(settingsDir, '../node_modules/react-native-screen-brightness/android')

Finally, my index.android.js file has:

import { NativeModules } from "react-native";
const { SystemBrightness } = NativeModules;
//...
SystemBrightness.setBrightness(0.75);

This all compiles fine, but I still get the Cannot read property 'setBrightness' of undefined error.

Any help much appreciated!

[ERROR] Android: Unable to set system brightness

When trying to call:

ScreenBrightness.setBrightness(value) .then(() => {}, e => console.log('ERROR: ', e))
I receive this console log:

11-21 12:47:45.631 17605 17713 I ReactNativeJS: 'ERROR: ', { [Error: Unable to set system brightness]
11-21 12:47:45.631 17605 17713 I ReactNativeJS: framesToPop: 1,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: nativeStackAndroid:
11-21 12:47:45.631 17605 17713 I ReactNativeJS: [ { methodName: 'setSystemBrightness',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 192,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'ScreenBrightnessModule.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'setBrightness',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 271,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'ScreenBrightnessModule.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'invoke', lineNumber: -2, file: 'Method.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'invoke',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 372,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'JavaMethodWrapper.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'invoke',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 158,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'JavaModuleWrapper.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'run',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: -2,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'NativeRunnable.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'handleCallback',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 794,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'Handler.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'dispatchMessage',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 99,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'Handler.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'dispatchMessage',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 29,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'MessageQueueThreadHandler.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'loop', lineNumber: 176, file: 'Looper.java' } ],
11-21 12:47:45.631 17605 17713 I ReactNativeJS: userInfo: null

Happens on Android only. Works fine on iOS

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.