Skip to content

A wake locker bridge for react-native (Android only, temporarily)

License

Notifications You must be signed in to change notification settings

Vosie/react-native-device-locker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-device-locker

Getting started

$ npm install react-native-device-locker --save

Mostly automatic installation

$ react-native link react-native-device-locker

Manual installation

iOS (Not supported now)

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-device-locker and add DeviceLocker.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libDeviceLocker.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import org.vosie.reactnative.devicelocker.DeviceLockerPackage; to the imports at the top of the file
  • Add new DeviceLockerPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-device-locker'
    project(':react-native-device-locker').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-device-locker/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-device-locker')
    

Windows (Not supported now)

Read it! :D

  1. In Visual Studio add the DeviceLocker.sln in node_modules/react-native-device-locker/windows/DeviceLocker.sln folder to their solution, reference from their app.
  2. Open up your MainPage.cs app
  • Add using Device.Locker.DeviceLocker; to the usings at the top of the file
  • Add new DeviceLockerPackage() to the List<IReactPackage> returned by the Packages method

Usage

import DeviceLocker from 'react-native-device-locker';

// TODO: What to do with the module?
DeviceLocker.requestWakeLock(DeviceLocker.PARTIAL_WAKE_LOCK).then((lockerId) => {
  // save lockerId for releasing
});
DeviceLocker.releaseWakeLock(lockerId);

TODO

  • Since we don't really develop iOS app, we may need help to make the same feature with iOS.
  • Basically, we should remove the Windows phone support. The template is generated by a tool.
  • Add wifi locker
  • Add a function to lock screen programmably, if possible.

About

A wake locker bridge for react-native (Android only, temporarily)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published