Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Use this file as a starting point for your project's .eslintrc.
// Copy this file, and add rule overrides as needed.
{
"parser": "babel-eslint",
"extends": "eslint-config-airbnb-es5",
"rules": {
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"react/prefer-stateless-function": [0, { "ignorePureComponents": true }],
"max-len": ["error", 120, { "ignoreTemplateLiterals": true, "ignoreComments": true }],
"comma-dangle": ["error", "always"]
}
}
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
]
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
lib

.DS_Store

Expand Down Expand Up @@ -45,4 +46,4 @@ DerivedData

.idea/vcs.xml

.idea/workspace.xml
.idea/workspace.xml
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.eslintignore
.eslintrc
.prettierrc
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
# Change Log

## 1.2.6

- Convert to Typescript
- Update gradle for React Native 0.68+ compatibility

## 1.2.5

- Update gradle for React Native 0.64+ compatibility
- Update devDependencies

## 1.2.4

- Chore: Update devDependencies

## 1.2.3

- Fix Android build warnings

## 1.2.2

- Fix Cocoapod build errors for scoped packages

## 1.2.1

- Rename package to use scopes
- iOS 13 support
- React Native 0.60+ autolinking support

## 1.2.0 (Set. 9, 2017)

- Android [#10](https://github.com/Calvin-Huang/react-native-device-brightness/pull/10) Remove unused registration of JS module to fix building version of 0.47+.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Calvin Huang
Copyright (c) 2020 Adrian So

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
151 changes: 26 additions & 125 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,145 +1,46 @@
react-native-device-brightness
===============
[![npm version](https://badge.fury.io/js/react-native-device-brightness.svg)](https://badge.fury.io/js/react-native-device-brightness)
# @adrianso/react-native-device-brightness

Screen brightness adjustment tool for ReactNative iOS and Android.
[![npm version](https://badge.fury.io/js/%40adrianso%2Freact-native-device-brightness.svg)](https://badge.fury.io/js/%40adrianso%2Freact-native-device-brightness)

## Installation
```
npm install --save react-native-device-brightness
```

*Recommended via yarn*
```
yarn add react-native-device-brightness
```

## Automatically link

### With React Native 0.27+
```
react-native link react-native-device-brightness
```


### With older versions of React Native
You need [rnpm](https://github.com/rnpm/rnpm) (npm install -g rnpm)
```
rnpm link react-native-device-brightness
```
*Hey, bro! react-native-device-brightness wasn't support older version of React Native yet.*

## Manually link

### iOS (without Cocoa Pods)
In XCode, in the project navigator:
- Right click _Libraries_
- Add Files to _[your project's name]_
- Go to `node_modules/react-native-device-brightness`
- Add the `.xcodeproj` file

In XCode, in the project navigator, select your project.
- Add the `libRNDeviceInfo.a` from the _deviceinfo_ project to your project's _Build Phases ➜ Link Binary With Libraries_
- Click `.xcodeproj` file you added before in the project navigator and go the _Build Settings_ tab. Make sure _All_ is toggled on (instead of _Basic_).
- Look for _Header Search Paths_ and make sure it contains both `$(SRCROOT)/../react-native/React` and `$(SRCROOT)/../../React`
- Mark both as recursive (should be OK by default).

Run your project (Cmd+R)
This is a native module for React Native to control the screen brightness.

(Thanks to @brysgo for writing the instructions)
It is a fork of https://github.com/Calvin-Huang/react-native-device-brightness, and has added the following features:

### Android
- React Native 0.60 compatibility
- iOS 13 compatibility

- in `android/app/build.gradle`:
## Installation

```diff
dependencies {
...
compile "com.facebook.react:react-native:+" // From node_modules
+ compile project(':react-native-device-brightness')
}
```

- in `android/settings.gradle`:

```diff
...
include ':app'
+ include ':react-native-device-brightness'
+ project(':react-native-device-brightness').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-brightness/android')
yarn add @adrianso/react-native-device-brightness
```

#### With React Native 0.29+

- in `MainApplication.java`:

```diff
+ import com.learnium.RNDeviceInfo.RNDeviceInfo;

public class MainApplication extends Application implements ReactApplication {
//......

@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
+ new RNDeviceInfo(),
new MainReactPackage()
);
}

......
}
```
## Linking

#### With older versions of React Native:
This module supports auto-linking for React Native version 0.60 and above. No additional steps are required.

- in `MainActivity.java`:
## Usage

```diff
+ import com.learnium.RNDeviceInfo.RNDeviceInfo;
**Important: Brightness Level only accept value 0 to 1.**

public class MainActivity extends ReactActivity {
......
- _Adjusting screen brightness will make iOS's Auto-Brightness function do nothing._
- _Adjusting screen brightness in Android only works in App and will reset to system setting exiting App._

@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
+ new RNDeviceInfo(),
new MainReactPackage()
);
}
}
```
```javascript
import DeviceBrightness from 'react-native-device-brightness';

(Thanks to @chirag04 for writing the instructions)
// Setting brightness
DeviceBrightness.setBrightnessLevel(brightness);

## Usage
**Important: Brightness Level only accept value 0 to 1.**
// Getting brightness
const brightness = await DeviceBrightness.getBrightnessLevel();
console.log(brightness);

- *Adjusting screen brightness will make iOS's Auto-Brightness function do nothing.*
- *Adjusting screen brightness in Android only works in App and will reset to system setting exiting App.*
```javascript
// ES5
var DeviceBrightness = require('react-native-device-brightness');
// or ES6
// import DeviceBrightness from 'react-native-device-brightness';

// It will throw a exception when value less than 0 or more than 1.
DeviceBrightness.setBrightnessLevel(luminous);
DeviceBrightness.getBrightnessLevel()
.then(function (luminous) {
// Get current brightness level
// 0 ~ 1
console.log(luminous);
});
// Android only
DeviceBrightness.getSystemBrightnessLevel()
.then(function (luminous) {
// Get current brightness level
// 0 ~ 1
console.log(luminous);
});
// Getting system brightness (Android only)
const brightness = await DeviceBrightness.getSystemBrightnessLevel();
console.log(brightness);
```

## License
Copyright (c) [Calvin Huang](https://github.com/Calvin-Huang). This software is licensed under the [MIT License](https://github.com/Calvin-Huang/react-native-device-brightness/blob/master/LICENSE).

This software is licensed under the [MIT License](https://github.com/adrianso/react-native-device-brightness/blob/master/LICENSE).
4 changes: 3 additions & 1 deletion RNDeviceBrightness/RNDeviceBrightness.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ @implementation RNDeviceBrightness

RCT_EXPORT_METHOD(setBrightnessLevel:(float)brightnessLevel)
{
[UIScreen mainScreen].brightness = brightnessLevel;
dispatch_async(dispatch_get_main_queue(), ^{
[UIScreen mainScreen].brightness = brightnessLevel;
});
}

RCT_REMAP_METHOD(getBrightnessLevel,
Expand Down
9 changes: 4 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
compileSdkVersion 31

defaultConfig {
minSdkVersion 16
targetSdkVersion 22
minSdkVersion 21
targetSdkVersion 31
versionCode 2
versionName "1.1"
ndk {
Expand All @@ -16,5 +15,5 @@ android {
}

dependencies {
compile 'com.facebook.react:react-native:+'
implementation 'com.facebook.react:react-native:+'
}
26 changes: 0 additions & 26 deletions index.js

This file was deleted.

32 changes: 32 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { NativeModules, Platform } from 'react-native';

const { RNDeviceBrightness } = NativeModules;

export const setBrightnessLevel = async (
brightnessLevel: number
): Promise<void> => {
if (brightnessLevel < 0 || brightnessLevel > 1) {
if (!(Platform.OS === 'android' && brightnessLevel === -1)) {
throw Error('⚠️ BrightnessLevel value must betweens 0 to 1 ⚠️');
}
}

await RNDeviceBrightness.setBrightnessLevel(brightnessLevel);
};

export const getBrightnessLevel = async (): Promise<number> => {
return RNDeviceBrightness.getBrightnessLevel();
};

export const getSystemBrightnessLevel = (): Promise<number> => {
if (Platform.OS !== 'android') {
throw Error('⚠️ Android only supported ⚠️');
}
return RNDeviceBrightness.getSystemBrightnessLevel();
};

export default {
setBrightnessLevel,
getBrightnessLevel,
getSystemBrightnessLevel,
};
31 changes: 17 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
{
"name": "react-native-device-brightness",
"version": "1.2.0",
"description": "Screen brightness adjustment tool for ReactNative iOS and Android. ",
"main": "index.js",
"name": "@adrianso/react-native-device-brightness",
"version": "1.2.7",
"description": "Screen brightness adjustment tool for React Native",
"homepage": "https://github.com/adrianso/react-native-device-brightness#readme",
"repository": {
"type": "git",
"url": "https://github.com/Calvin-Huang/react-native-device-brightness"
"url": "https://github.com/adrianso/react-native-device-brightness"
},
"keywords": [
"react-component",
"react-native",
"ios",
"android",
"screen-brightness",
"device-brightness",
"brightness"
],
"author": "Calvin Huang <[email protected]> (https://github.com/Calvin-Huang)",
"author": "Adrian So <[email protected]> (https://github.com/adrianso)",
"license": "MIT",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"prepublish": "tsc",
"lint": "eslint '**/*.{ts,tsx}'"
},
"devDependencies": {
"babel-eslint": "^7.2.3",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.0.1",
"eslint-config-airbnb-es5": "^1.1.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^5.0.1",
"eslint-plugin-react": "^7.0.1"
"@types/react-native": "^0.71.0",
"@typescript-eslint/eslint-plugin": "^5.48.2",
"@typescript-eslint/parser": "^5.48.2",
"eslint": "^8.32.0",
"typescript": "^4.9.4"
}
}
Loading