A cross-platform bridge that allows you to enable and disable the screen idle timer in your React Native app

Overview

react-native-idle-timer

A cross-platform bridge that allows you to enable and disable the screen idle timer in your React Native app

Install

npm install [email protected] --save

Link

Automatically

react-native link react-native-idle-timer

Manually

iOS
  1. In the XCode's "Project navigator", right click on your project's Libraries folder ➜ Add Files to <...>
  2. Go to node_modulesreact-native-idle-timerios ➜ select RNIdleTimer.xcodeproj
  3. Add libRNIdleTimer.a to Build Phases -> Link Binary With Libraries
Android
  1. in android/settings.gradle
...
include ':react-native-idle-timer'
project(':react-native-idle-timer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-idle-timer/android')
  1. in android/app/build.gradle add:
dependencies {
  ...
  compile project(':react-native-idle-timer')
}
  1. and finally, in android/src/main/java/com/{YOUR_APP_NAME}/MainActivity.java add:
//...
import com.marcshilling.idletimer.IdleTimerPackage; // <--- This!

//...
@Override
protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
    new MainReactPackage(),
    new IdleTimerPackage() // <---- and This!
  );
}

Usage

  1. In your React Native javascript code, bring in the native module:
import IdleTimerManager from 'react-native-idle-timer';
  1. To disable the idle timer on a specific view component:
componentWillMount() {
  IdleTimerManager.setIdleTimerDisabled(true);
}

componentWillUnmount() {
  IdleTimerManager.setIdleTimerDisabled(false);
}
Comments
  • Gradle Version Requirements

    Gradle Version Requirements

    I am building a project in Android studio and am running into a circular dependency.

    Every time I set my Gradle Plugin and AGP versions to 7.0.2, the build fails because react-native-idle-timer requires v7.0.1. When I downgrade to v7.0.1 in both plugins, the buid fails because the Minimum supported Gradle version is 7.0.2.

    I'm pretty new to Android studio and not sure if it's a straightforward adjustment in this project to allow support for the latest Gradle/Android Gradle plugins. Any ideas?

    Thanks!

    opened by copiri-six 9
  • Autolinking not working?

    Autolinking not working?

    Just installed from npm and tried to compile straight away. Got an error that the method doesn't exist. It seems the native code isn't linked on iOS. Is autolinking broken with this project?

    opened by shamilovtim 7
  • Cannot read property 'setIdleTimerDisabled' of undefined on tvOS

    Cannot read property 'setIdleTimerDisabled' of undefined on tvOS

    Hi @marcshilling, I got your library to work on iOS but I wonder if you have any suggestions for getting it to work on tvOS? I am getting, "Unhandled JS Exception: Cannot read property 'setIdleTimerDisabled' of undefined". I've tried adding the project to my project, manually. I've added the (tvOS compiled) .a to my linked libraries. In that view, if I right click the .a and Show in Finder, it does show me the file in the finder. Any ideas of what else I might be missing? Here's the commit I made. If we can get it working I'll issue a pull request: https://github.com/abcd-ca/react-native-idle-timer/commit/677541b9cd5a65f61c5333e713dd50a949221c31 Thanks!

    opened by abcd-ca 2
  • [iOS] Set deployment target to iOS 8.0 + add gitignore

    [iOS] Set deployment target to iOS 8.0 + add gitignore

    Hi there, thanks for building this!

    This is a super minor issue but our app supports iOS 8.0 (react-native supports it as well). We were receiving this warning so I bumped the iOS deployment target from 9.3 to 8.0.

    image

    Also added a gitignore to ignore all the tmp files from iOS / android / js.

    Cheers!

    opened by negativetwelve 2
  • Android app crashes after installing the package

    Android app crashes after installing the package

    Hi I've installed the package on 0.62.2 and app crashes before connecting to packager.

    and here is the latest line of the adb -d logcat | grep MYAPP:

    04-01 16:41:27.935  3427  4566 W SurfaceFlinger: Attempting to destroy on removed layer: Splash Screen com.MYAPP[508]#0
    04-01 16:41:27.936  3898  4836 I WindowManager: Cancelling animation restarting=false, leash=null, surface=Surface(name=AppWindowToken{516860d token=Token{cd78a4 ActivityRecord{1cacb37 u0 com.MYAPP/.MainActivity t11313}}})/@0x6d252d4, parent=Surface(name=Task=11313)/@0xc20c7d, caller=com.android.server.wm.SurfaceAnimator.cancelAnimation:183 com.android.server.wm.WindowContainer.cancelAnimation:1179 com.android.server.wm.AppWindowToken.cancelAnimation:2431 com.android.server.wm.AppWindowToken.onRemovedFromDisplay:815 com.android.server.wm.DisplayContent.removeAppToken:1075 
    04-01 16:41:27.939  3427  3556 I SurfaceFlinger: id=13654 Removed AppWindowToken{516860d token=Token{cd78a4 ActivityRecord{1cacb37 u0 com.MYAPP/.MainActivity t11313}}}#0 (0/61)
    04-01 16:41:27.944  3427  3427 I Layer   : id=13654 onRemoved AppWindowToken{516860d token=Token{cd78a4 ActivityRecord{1cacb37 u0 com.MYAPP/.MainActivity t11313}}}#0 
    04-01 16:41:27.944  3427  3427 I Layer   : id=13655 onRemoved b8cfa4b Splash Screen com.MYAPP#0 
    04-01 16:41:27.945  3427  3427 I Layer   : id=13656 onRemoved Splash Screen com.MYAPP[508]#0 
    04-01 16:41:28.137   639   671 D AppErrorNotification: errorType : 24, process : com.MYAPP , uid : 0
    04-01 16:41:34.466   639   671 V FasUtils: There is com.MYAPP [10545] in FAS table
    04-01 16:41:34.559   639   671 W AppErrorNotification: Skip. com.MYAPP is not notiable item
    04-01 16:41:37.134  3898  3905 D SurfaceControl: finalize(protected), animation-leash is released by finalize, sc=Surface(name=Surface(name=AppWindowToken{516860d token=Token{cd78a4 ActivityRecord{1cacb37 u0 com.MYAPP/.MainActivity t11313}}})/@0x6d252d4 - animation-leash)/@0x387bd1f, nativeObject=491918915328, caller=java.lang.Daemons$FinalizerDaemon.doFinalize:250 java.lang.Daemons$FinalizerDaemon.runInternal:237 java.lang.Daemons$Daemon.run:103 java.lang.Thread.run:764 <bottom of call stack> <bottom of call stack> <bottom of call stack> 
    
    
    
    opened by ph98 1
  • Always on iOS

    Always on iOS

    I'm having an issue with this library on iOS. I tested this with iphone X 12.3.1

    When i include the library and link it the phone always stays on. Even without calling a function in this library.

    Infact, the screen even remains on when I only call

    IdleTimerManager.setIdleTimerDisabled(false);

    Has anyone else experienced this?

    opened by CaptainJeff 1
  • fix: xcode 12 compatibility

    fix: xcode 12 compatibility

    Xcode 12 fails to build if a module depends on React instead of React-Core. This change is necessary for all native modules on iOS. 
Reference: https://github.com/facebook/react-native/issues/29633#issuecomment-694187116

    opened by kasinskas 0
  •  the component is not work In part of Android Devices

    the component is not work In part of Android Devices

    when i play video componentDidMount(){ IdleTimerManager.setIdleTimerDisabled(true); } componentWillUnmount(){ IdleTimerManager.setIdleTimerDisabled(false); }

    opened by HanJiangShuiKevin 0
  • Update README.md

    Update README.md

    I suggest narrowing down the link to just react-native-idle-timer so it doesn't perform the link on all of the dependencies. There are scenarios where it will add duplicate references to the android project which will cause it to crash

    opened by CaptainJeff 0
  • Updated build.gradle

    Updated build.gradle

    • Updated compileSdkVersion, targetSdkVersion and buildToolsVersion default values to the latest available
    • Replaced compile with implementation, as compile is now obsolete.
    opened by Kouznetsov 0
  • Change react-native headers for 0.40 compatibility

    Change react-native headers for 0.40 compatibility

    This pull request adds compatibility with react-native 0.40 while keeping backwards compatibility with older versions.
    The breaking changes were announced here https://github.com/facebook/react-native/releases/tag/v0.40.0
    Backwards compatibilty solution was founded here https://medium.com/@thisismissem/how-to-upgrade-react-native-modules-in-a-backwards-compatible-manner-a5b5c48d590c#.u4m6ktkex

    opened by alfonsodev 0
  • Not working on iOS 15.2

    Not working on iOS 15.2

    The plugin was not working on an old iPhone 6s with iOS 15.2. The screen get locked after the default 1 Minute set on the iOS settings. I updated the iOS Version to 15.6.1 and the problem is fixed. Can someone confirm that the plugin is not working on older iOS Versions? Unfortunately I do not have any device with an old iOS version.

    opened by bfmehdi 0
  • null is not an object

    null is not an object

    I downloaded the package and pod installed. i reran my metro server and when i navigate to my camera screen, the code is fired and BOOM...

    null is not an object (evaluating '_reactNative.NativeModules.KCKeepAwake.activate')

    "react-native": "0.69.3", "react-native-idle-timer": "^2.1.7",

    import IdleTimerManager from 'react-native-idle-timer';

    within my component useEffect(()=>{ if(isRecording){ IdleTimerManager.setIdleTimerDisabled(true); } else{ IdleTimerManager.setIdleTimerDisabled(false); } },[isRecording])

    opened by guthriet1230 1
  • IdleTimerManager.setIdleTimerDisabled is not working on android.

    IdleTimerManager.setIdleTimerDisabled is not working on android.

    I will use in our app but this is not working in android. IdleTimerManager.setIdleTimerDisabled(true); IdleTimerManager.setIdleTimerDisabled(false);

    @kasinskas @flacito @CaptainJeff

    opened by codal-mpawar 2
  • [RFC] Add react-native-package to protect against bad installations

    [RFC] Add react-native-package to protect against bad installations

    Hi @marcshilling, thanks again for this library. I have a quick proposal. Recently I've found that many packages, when not installed correctly, raise somewhat cryptic errors. To mitigate this issue, I've created react-native-package which is a quick, declarative way to check if a nativeModule is installed correctly.

    If someone does not follow the native instructions or something went wrong, they will see this warning when starting the app:

    image

    Warning: react-native-idle-timer was not installed correctly. Please follow the instructions in the README: https://github.com/marcshilling/react-native-idle-timer#readme.

    This is more favorable than a runtime error when they first use IdleTimerManager.setIdleTimerDisabled.

    I realize that this is a somewhat small package so adding this dependency might be overkill, but I'm trying to see if this style of package writing can catch on in the community so consumers of the packages will have a better debugging experience, especially for people who might be new and not know what to do when they receive a native error.

    Would love to hear your thoughts on whether or not you think this is useful for your react-native package. thanks!

    opened by negativetwelve 0
Owner
Marc Shilling
Senior iOS and React Native Developer
Marc Shilling
Listen to device orientation changes in react-native and set preferred orientation on screen to screen basis.

React Native Orientation Listen to device orientation changes in React Native applications and programmatically set preferred orientation on a per scr

Yamill Vallecillo 1.7k Dec 17, 2022
A Cross Platform(Android & iOS) ActionSheet with a flexible api, native performance and zero dependency code for react native. Create anything you want inside ActionSheet.

react-native-actions-sheet A highly customizable cross platform ActionSheet for react native. Screenshots Features Cross Platform (iOS and Android) Na

Ammar Ahmed 1000 Jan 9, 2023
Tailwindcss-react-native: Use Tailwindcss in your cross platform React Native applications

tailwindcss-react-native Use Tailwindcss in your cross platform React Native applications. This library is currently stabilising for a v1 release. Fol

Mark Lawlor 1.5k Jan 2, 2023
react-native-wheel-picker ★190 - React native cross platform picker.

react-native-wheel-picker Introduction Cross platform Picker component based on React-native. Since picker is originally supported by ios while Androi

Yu Zheng (Sam) 308 Jan 1, 2023
Simple, performant & type-safe cross platform navigation in React Native / React Native Web

Simple and performant cross platform navigation on iOS, Android and the web with simple and type-safe api for React 18 (alpha)

webRidge 34 Nov 21, 2022
An awesome and cross-platform React Native date picker and calendar component for iOS and Android

react-native-common-date-picker An awesome and cross-platform React Native date picker and calendar component for iOS and Android. This package is des

chenlong 96 Jan 2, 2023
React Native template for a quick start with React Navigation5 and TypeScript. It's cross-platform runs on Android, iOS, and the web.

对此项目的规划 出于兴趣把自己做 android、ios 开发过程中经验积累沉淀一下,此工程架构会定期更新升级依赖到最新版本,并不断的积累 App 中常用组件和基础页面功能,也会不断优化代码组织架构 此项目对以下情形会有帮助 想用前端技术做 app 开发却无从下手 想在项目中运用 typescrip

Benson 6 Dec 4, 2022
Smooth and fast cross platform Material Design date and time picker for React Native Paper

Smooth and fast cross platform Material Design date and time picker for React Native Paper

webRidge 432 Dec 27, 2022
A cross-platform (iOS / Android), selector/picker component for React Native that is highly customizable and supports sections.

react-native-modal-picker A cross-platform (iOS / Android), selector/picker component for React Native that is highly customizable and supports sectio

Dan 398 Nov 11, 2022
A cross-platform (iOS / Android), selector/picker component for React Native that is highly customizable and supports sections.

react-native-modal-selector A cross-platform (iOS / Android), selector/picker component for React Native that is highly customizable and supports sect

Peace 354 Dec 26, 2022
A cross-platform (iOS / Android) single and multiple-choice React Native component.

react-native-multiple-choice A cross-platform (iOS / Android) single and multiple-choice React Native component. Install npm i react-native-multiple-c

Dan 67 Sep 24, 2022
Cross Platform Material Alert and Prompt Dialogs for React Native. Imperative API, Android, IOS, Web

React Native Paper Alerts Cross Platform Material Alert and Prompt for React Native. It tries to follow the API and function signature of React Native

Arafat Zahan 13 Nov 21, 2022
🎉 toastify-react-native allows you to add notifications to your react-native app (ios, android) with ease. No more nonsense!

toastify-react-native ?? toastify-react-native allows you to add notifications to your react-native app (ios, android) with ease. No more nonsense! De

Zahid Ali 30 Jan 2, 2023
A cross-platform (iOS / Android), full-featured, highly customizable web browser module for React Native apps.

react-native-webbrowser A cross-platform (iOS / Android), full-featured in-app web browser component for React Native that is highly customizable. Cur

Dan 196 Nov 23, 2022
⚛ Cross-platform React Native dialogs based on the Modal component

React Native Simple Dialogs ⚛ Cross-platform React Native dialogs based on the Modal component. Features Custom Dialog Confirm Dialog Progress Dialog

Douglas Nassif Roma Junior 264 Dec 20, 2022
🗺 A simple react-native library to perform cross-platform map actions (Google or Apple Maps)

react-native-open-maps ?? A simple cross-platform library to help perform map actions to the corresponding device's map (Google or Apple Maps) react-n

Brandon Him 287 Dec 22, 2022
React-Native cross-platform, calendar component.

React Native Calendar Datepicker Description This project aims at providing developers with a cross-platform, highly customizable, calendar date picke

Vlad-Doru Ion 84 Dec 30, 2022
📜 Cross platform custom ActionSheet

react-native-custom-actionsheet Cross platform ActionSheet. This component implements a custom ActionSheet and provides the same way of drawing it on

Valery Bugakov 47 Oct 21, 2021