├── .gitignore ├── LICENSE.md ├── README.md ├── android ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── marcshilling │ └── idletimer │ ├── IdleTimerManager.java │ └── IdleTimerPackage.java ├── index.d.ts ├── index.js ├── ios ├── RNIdleTimer.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcuserdata │ │ └── marcshilling.xcuserdatad │ │ └── xcschemes │ │ ├── RNIdleTimer.xcscheme │ │ └── xcschememanagement.plist └── RNIdleTimer │ ├── IdleTimerManager.h │ └── IdleTimerManager.m ├── package.json └── react-native-idle-timer.podspec /.gitignore: -------------------------------------------------------------------------------- 1 | # macOS 2 | .DS_Store 3 | 4 | # Android 5 | .idea 6 | .gradle 7 | local.properties 8 | *.iml 9 | *.iws 10 | *.ipr 11 | 12 | # Xcode 13 | build/ 14 | *.pbxuser 15 | !default.pbxuser 16 | *.mode1v3 17 | !default.mode1v3 18 | *.mode2v3 19 | !default.mode2v3 20 | *.perspectivev3 21 | !default.perspectivev3 22 | xcuserdata 23 | *.xccheckout 24 | *.moved-aside 25 | DerivedData 26 | *.hmap 27 | *.ipa 28 | *.xcuserstate 29 | project.xcworkspace 30 | 31 | # Cocoapods 32 | Pods/ 33 | 34 | # JS 35 | node_modules/ 36 | npm-debug.log 37 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Marc Shilling 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-idle-timer 2 | 3 | A cross-platform bridge that allows you to enable and disable the screen idle timer in your React Native app 4 | 5 | ## Install 6 | 7 | `yarn add react-native-idle-timer` 8 | 9 | ## Link 10 | 11 | #### Automatically 12 | 13 | `react-native link react-native-idle-timer` 14 | 15 | #### Manually 16 | 17 | ##### iOS 18 | 1. In the XCode's "Project navigator", right click on your project's Libraries folder ➜ `Add Files to <...>` 19 | 2. Go to `node_modules` ➜ `react-native-idle-timer` ➜ `ios` ➜ select `RNIdleTimer.xcodeproj` 20 | 3. Add `libRNIdleTimer.a` to `Build Phases -> Link Binary With Libraries` 21 | 22 | ##### Android 23 | 24 | 1. in `android/settings.gradle` 25 | 26 | ```gradle 27 | ... 28 | include ':react-native-idle-timer' 29 | project(':react-native-idle-timer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-idle-timer/android') 30 | ``` 31 | 32 | 2. in `android/app/build.gradle` add: 33 | 34 | ```gradle 35 | dependencies { 36 | ... 37 | compile project(':react-native-idle-timer') 38 | } 39 | ``` 40 | 41 | 3. and finally, in `android/src/main/java/com/{YOUR_APP_NAME}/MainActivity.java` add: 42 | 43 | ```java 44 | //... 45 | import com.marcshilling.idletimer.IdleTimerPackage; // <--- This! 46 | 47 | //... 48 | @Override 49 | protected List getPackages() { 50 | return Arrays.asList( 51 | new MainReactPackage(), 52 | new IdleTimerPackage() // <---- and This! 53 | ); 54 | } 55 | ``` 56 | 57 | ## Usage 58 | 59 | ### In your React Native javascript code, bring in the native module: 60 | 61 | ```javascript 62 | import IdleTimerManager from 'react-native-idle-timer'; 63 | ``` 64 |
65 | 66 | ### To disable the idle timer while a certain component is mounted: 67 | 68 | Class component 69 | ```javascript 70 | componentWillMount() { 71 | IdleTimerManager.setIdleTimerDisabled(true); 72 | } 73 | 74 | componentWillUnmount() { 75 | IdleTimerManager.setIdleTimerDisabled(false); 76 | } 77 | ``` 78 | 79 | 80 | Function component 81 | 82 | ```javascript 83 | useEffect(() => { 84 | IdleTimerManager.setIdleTimerDisabled(true); 85 | 86 | return () => IdleTimerManager.setIdleTimerDisabled(false); 87 | }, []) 88 | ``` 89 |
90 | 91 | ### If you have multiple components that are responsible for interacting with the idle timer, you can pass a tag as the second parameter: 92 | 93 | ```javascript 94 | useEffect(() => { 95 | IdleTimerManager.setIdleTimerDisabled(true, "video"); 96 | 97 | return () => IdleTimerManager.setIdleTimerDisabled(false, "video"); 98 | }, []) 99 | ``` 100 |
101 | 102 | ### If you need to interact from the native Android or iOS side: 103 | 104 | Android 105 | ```java 106 | IdleTimerManager.activate(activity, "video"); 107 | IdleTimerManager.deactivate(activity, "video"); 108 | ``` 109 | 110 | iOS 111 | ```objectivec 112 | [IdleTimerManager activate:@"video"]; 113 | [IdleTimerManager deactivate:@"video"]; 114 | ``` 115 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | if (project == rootProject) { 3 | repositories { 4 | google() 5 | jcenter() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.5.4' 10 | } 11 | } 12 | } 13 | 14 | apply plugin: 'com.android.library' 15 | 16 | import groovy.json.JsonSlurper 17 | def computeVersionName() { 18 | // dynamically retrieve version from package.json 19 | def slurper = new JsonSlurper() 20 | def json = slurper.parse(file('../package.json'), "utf-8") 21 | return json.version 22 | } 23 | 24 | def safeExtGet(prop, fallback) { 25 | rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback 26 | } 27 | 28 | android { 29 | compileSdkVersion safeExtGet('compileSdkVersion', 28) 30 | buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3') 31 | defaultConfig { 32 | minSdkVersion safeExtGet('minSdkVersion', 16) 33 | targetSdkVersion safeExtGet('targetSdkVersion', 28) 34 | versionCode 1 35 | versionName computeVersionName() 36 | } 37 | 38 | buildTypes { 39 | release { 40 | minifyEnabled false 41 | } 42 | } 43 | lintOptions { 44 | disable 'GradleCompatible' 45 | } 46 | compileOptions { 47 | sourceCompatibility JavaVersion.VERSION_1_8 48 | targetCompatibility JavaVersion.VERSION_1_8 49 | } 50 | } 51 | 52 | repositories { 53 | mavenLocal() 54 | maven { 55 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 56 | url("$rootDir/../node_modules/react-native/android") 57 | } 58 | google() 59 | jcenter() 60 | } 61 | 62 | dependencies { 63 | //noinspection GradleDynamicVersion 64 | implementation "com.facebook.react:react-native:+" // From node_modules 65 | } 66 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcshilling/react-native-idle-timer/7300b637c465c86e8db874c442e687950111da40/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /android/src/main/java/com/marcshilling/idletimer/IdleTimerManager.java: -------------------------------------------------------------------------------- 1 | package com.marcshilling.idletimer; 2 | 3 | import com.facebook.react.bridge.ReactApplicationContext; 4 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 5 | import com.facebook.react.bridge.ReactMethod; 6 | 7 | import java.util.HashSet; 8 | 9 | import android.app.Activity; 10 | import android.view.WindowManager; 11 | 12 | import org.jetbrains.annotations.NotNull; 13 | 14 | public class IdleTimerManager extends ReactContextBaseJavaModule 15 | { 16 | static final String MODULE_NAME = "IdleTimerManager"; 17 | 18 | static final HashSet tags = new HashSet(); 19 | 20 | public IdleTimerManager(ReactApplicationContext reactContext) { 21 | super(reactContext); 22 | } 23 | 24 | @Override 25 | public String getName() { 26 | return this.MODULE_NAME; 27 | } 28 | 29 | @ReactMethod 30 | public void setIdleTimerDisabled(final boolean disabled, final String tag) { 31 | final Activity activity = this.getCurrentActivity(); 32 | if (activity != null) { 33 | if (disabled) { 34 | activate(activity, tag); 35 | } else { 36 | deactivate(activity, tag); 37 | } 38 | } 39 | } 40 | 41 | public static void activate(@NotNull final Activity activity, final String tag) { 42 | if (tags.isEmpty()) { 43 | activity.runOnUiThread(() -> { 44 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 45 | }); 46 | } 47 | tags.add(tag == null ? "" : tag); 48 | } 49 | 50 | public static void deactivate(@NotNull final Activity activity, final String tag) { 51 | if (tags.size() == 1 && tags.contains(tag == null ? "" : tag)) { 52 | activity.runOnUiThread(() -> { 53 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 54 | }); 55 | } 56 | tags.remove(tag == null ? "" : tag); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /android/src/main/java/com/marcshilling/idletimer/IdleTimerPackage.java: -------------------------------------------------------------------------------- 1 | package com.marcshilling.idletimer; 2 | 3 | import com.facebook.react.ReactPackage; 4 | import com.facebook.react.bridge.JavaScriptModule; 5 | import com.facebook.react.bridge.NativeModule; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.react.uimanager.ViewManager; 8 | 9 | import java.util.Arrays; 10 | import java.util.Collections; 11 | import java.util.List; 12 | 13 | public class IdleTimerPackage implements ReactPackage { 14 | 15 | @Override 16 | public List createNativeModules(ReactApplicationContext reactContext) { 17 | return Arrays.asList( 18 | new IdleTimerManager(reactContext) 19 | ); 20 | } 21 | 22 | // Deprecated in React Native 0.47.0 23 | // @Override 24 | public List> createJSModules() { 25 | return Collections.emptyList(); 26 | } 27 | 28 | @Override 29 | public List createViewManagers(ReactApplicationContext reactContext) { 30 | return Collections.emptyList(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace RNIdleTimer { 2 | function setIdleTimerDisabled(disabled: boolean, tag?: string): void; 3 | } 4 | export = RNIdleTimer; 5 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var { NativeModules } = require('react-native') 4 | 5 | module.exports.setIdleTimerDisabled = (disabled, tag = "") => { 6 | NativeModules.IdleTimerManager.setIdleTimerDisabled(disabled, tag); 7 | } 8 | -------------------------------------------------------------------------------- /ios/RNIdleTimer.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 01D749681CC963E9007E93FA /* IdleTimerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 01D749671CC963E9007E93FA /* IdleTimerManager.m */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXCopyFilesBuildPhase section */ 14 | 01D749581CC96385007E93FA /* CopyFiles */ = { 15 | isa = PBXCopyFilesBuildPhase; 16 | buildActionMask = 2147483647; 17 | dstPath = "include/$(PRODUCT_NAME)"; 18 | dstSubfolderSpec = 16; 19 | files = ( 20 | ); 21 | runOnlyForDeploymentPostprocessing = 0; 22 | }; 23 | /* End PBXCopyFilesBuildPhase section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | 01D7495A1CC96385007E93FA /* libRNIdleTimer.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNIdleTimer.a; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | 01D749661CC963E9007E93FA /* IdleTimerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IdleTimerManager.h; sourceTree = ""; }; 28 | 01D749671CC963E9007E93FA /* IdleTimerManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IdleTimerManager.m; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 01D749571CC96385007E93FA /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 01D749511CC96385007E93FA = { 43 | isa = PBXGroup; 44 | children = ( 45 | 01D7495C1CC96385007E93FA /* RNIdleTimer */, 46 | 01D7495B1CC96385007E93FA /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 01D7495B1CC96385007E93FA /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 01D7495A1CC96385007E93FA /* libRNIdleTimer.a */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 01D7495C1CC96385007E93FA /* RNIdleTimer */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 01D749661CC963E9007E93FA /* IdleTimerManager.h */, 62 | 01D749671CC963E9007E93FA /* IdleTimerManager.m */, 63 | ); 64 | path = RNIdleTimer; 65 | sourceTree = ""; 66 | }; 67 | /* End PBXGroup section */ 68 | 69 | /* Begin PBXNativeTarget section */ 70 | 01D749591CC96385007E93FA /* RNIdleTimer */ = { 71 | isa = PBXNativeTarget; 72 | buildConfigurationList = 01D749631CC96385007E93FA /* Build configuration list for PBXNativeTarget "RNIdleTimer" */; 73 | buildPhases = ( 74 | 01D749561CC96385007E93FA /* Sources */, 75 | 01D749571CC96385007E93FA /* Frameworks */, 76 | 01D749581CC96385007E93FA /* CopyFiles */, 77 | ); 78 | buildRules = ( 79 | ); 80 | dependencies = ( 81 | ); 82 | name = RNIdleTimer; 83 | productName = RNIdleTimer; 84 | productReference = 01D7495A1CC96385007E93FA /* libRNIdleTimer.a */; 85 | productType = "com.apple.product-type.library.static"; 86 | }; 87 | /* End PBXNativeTarget section */ 88 | 89 | /* Begin PBXProject section */ 90 | 01D749521CC96385007E93FA /* Project object */ = { 91 | isa = PBXProject; 92 | attributes = { 93 | LastUpgradeCheck = 0730; 94 | ORGANIZATIONNAME = marcshilling; 95 | TargetAttributes = { 96 | 01D749591CC96385007E93FA = { 97 | CreatedOnToolsVersion = 7.3; 98 | }; 99 | }; 100 | }; 101 | buildConfigurationList = 01D749551CC96385007E93FA /* Build configuration list for PBXProject "RNIdleTimer" */; 102 | compatibilityVersion = "Xcode 3.2"; 103 | developmentRegion = English; 104 | hasScannedForEncodings = 0; 105 | knownRegions = ( 106 | en, 107 | ); 108 | mainGroup = 01D749511CC96385007E93FA; 109 | productRefGroup = 01D7495B1CC96385007E93FA /* Products */; 110 | projectDirPath = ""; 111 | projectRoot = ""; 112 | targets = ( 113 | 01D749591CC96385007E93FA /* RNIdleTimer */, 114 | ); 115 | }; 116 | /* End PBXProject section */ 117 | 118 | /* Begin PBXSourcesBuildPhase section */ 119 | 01D749561CC96385007E93FA /* Sources */ = { 120 | isa = PBXSourcesBuildPhase; 121 | buildActionMask = 2147483647; 122 | files = ( 123 | 01D749681CC963E9007E93FA /* IdleTimerManager.m in Sources */, 124 | ); 125 | runOnlyForDeploymentPostprocessing = 0; 126 | }; 127 | /* End PBXSourcesBuildPhase section */ 128 | 129 | /* Begin XCBuildConfiguration section */ 130 | 01D749611CC96385007E93FA /* Debug */ = { 131 | isa = XCBuildConfiguration; 132 | buildSettings = { 133 | ALWAYS_SEARCH_USER_PATHS = NO; 134 | CLANG_ANALYZER_NONNULL = YES; 135 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 136 | CLANG_CXX_LIBRARY = "libc++"; 137 | CLANG_ENABLE_MODULES = YES; 138 | CLANG_ENABLE_OBJC_ARC = YES; 139 | CLANG_WARN_BOOL_CONVERSION = YES; 140 | CLANG_WARN_CONSTANT_CONVERSION = YES; 141 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 142 | CLANG_WARN_EMPTY_BODY = YES; 143 | CLANG_WARN_ENUM_CONVERSION = YES; 144 | CLANG_WARN_INT_CONVERSION = YES; 145 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 146 | CLANG_WARN_UNREACHABLE_CODE = YES; 147 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 148 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 149 | COPY_PHASE_STRIP = NO; 150 | DEBUG_INFORMATION_FORMAT = dwarf; 151 | ENABLE_STRICT_OBJC_MSGSEND = YES; 152 | ENABLE_TESTABILITY = YES; 153 | GCC_C_LANGUAGE_STANDARD = gnu99; 154 | GCC_DYNAMIC_NO_PIC = NO; 155 | GCC_NO_COMMON_BLOCKS = YES; 156 | GCC_OPTIMIZATION_LEVEL = 0; 157 | GCC_PREPROCESSOR_DEFINITIONS = ( 158 | "DEBUG=1", 159 | "$(inherited)", 160 | ); 161 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 162 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 163 | GCC_WARN_UNDECLARED_SELECTOR = YES; 164 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 165 | GCC_WARN_UNUSED_FUNCTION = YES; 166 | GCC_WARN_UNUSED_VARIABLE = YES; 167 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 168 | MTL_ENABLE_DEBUG_INFO = YES; 169 | ONLY_ACTIVE_ARCH = YES; 170 | SDKROOT = iphoneos; 171 | }; 172 | name = Debug; 173 | }; 174 | 01D749621CC96385007E93FA /* Release */ = { 175 | isa = XCBuildConfiguration; 176 | buildSettings = { 177 | ALWAYS_SEARCH_USER_PATHS = NO; 178 | CLANG_ANALYZER_NONNULL = YES; 179 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 180 | CLANG_CXX_LIBRARY = "libc++"; 181 | CLANG_ENABLE_MODULES = YES; 182 | CLANG_ENABLE_OBJC_ARC = YES; 183 | CLANG_WARN_BOOL_CONVERSION = YES; 184 | CLANG_WARN_CONSTANT_CONVERSION = YES; 185 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 186 | CLANG_WARN_EMPTY_BODY = YES; 187 | CLANG_WARN_ENUM_CONVERSION = YES; 188 | CLANG_WARN_INT_CONVERSION = YES; 189 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 190 | CLANG_WARN_UNREACHABLE_CODE = YES; 191 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 192 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 193 | COPY_PHASE_STRIP = NO; 194 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 195 | ENABLE_NS_ASSERTIONS = NO; 196 | ENABLE_STRICT_OBJC_MSGSEND = YES; 197 | GCC_C_LANGUAGE_STANDARD = gnu99; 198 | GCC_NO_COMMON_BLOCKS = YES; 199 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 200 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 201 | GCC_WARN_UNDECLARED_SELECTOR = YES; 202 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 203 | GCC_WARN_UNUSED_FUNCTION = YES; 204 | GCC_WARN_UNUSED_VARIABLE = YES; 205 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 206 | MTL_ENABLE_DEBUG_INFO = NO; 207 | SDKROOT = iphoneos; 208 | VALIDATE_PRODUCT = YES; 209 | }; 210 | name = Release; 211 | }; 212 | 01D749641CC96385007E93FA /* Debug */ = { 213 | isa = XCBuildConfiguration; 214 | buildSettings = { 215 | HEADER_SEARCH_PATHS = ( 216 | "$(SRCROOT)/../node_modules/react-native/React/**", 217 | "$(SRCROOT)/../../react-native/React/**", 218 | ); 219 | OTHER_LDFLAGS = "-ObjC"; 220 | PRODUCT_NAME = "$(TARGET_NAME)"; 221 | SKIP_INSTALL = YES; 222 | }; 223 | name = Debug; 224 | }; 225 | 01D749651CC96385007E93FA /* Release */ = { 226 | isa = XCBuildConfiguration; 227 | buildSettings = { 228 | HEADER_SEARCH_PATHS = ( 229 | "$(SRCROOT)/../node_modules/react-native/React/**", 230 | "$(SRCROOT)/../../react-native/React/**", 231 | ); 232 | OTHER_LDFLAGS = "-ObjC"; 233 | PRODUCT_NAME = "$(TARGET_NAME)"; 234 | SKIP_INSTALL = YES; 235 | }; 236 | name = Release; 237 | }; 238 | /* End XCBuildConfiguration section */ 239 | 240 | /* Begin XCConfigurationList section */ 241 | 01D749551CC96385007E93FA /* Build configuration list for PBXProject "RNIdleTimer" */ = { 242 | isa = XCConfigurationList; 243 | buildConfigurations = ( 244 | 01D749611CC96385007E93FA /* Debug */, 245 | 01D749621CC96385007E93FA /* Release */, 246 | ); 247 | defaultConfigurationIsVisible = 0; 248 | defaultConfigurationName = Release; 249 | }; 250 | 01D749631CC96385007E93FA /* Build configuration list for PBXNativeTarget "RNIdleTimer" */ = { 251 | isa = XCConfigurationList; 252 | buildConfigurations = ( 253 | 01D749641CC96385007E93FA /* Debug */, 254 | 01D749651CC96385007E93FA /* Release */, 255 | ); 256 | defaultConfigurationIsVisible = 0; 257 | defaultConfigurationName = Release; 258 | }; 259 | /* End XCConfigurationList section */ 260 | }; 261 | rootObject = 01D749521CC96385007E93FA /* Project object */; 262 | } 263 | -------------------------------------------------------------------------------- /ios/RNIdleTimer.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ios/RNIdleTimer.xcodeproj/xcuserdata/marcshilling.xcuserdatad/xcschemes/RNIdleTimer.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /ios/RNIdleTimer.xcodeproj/xcuserdata/marcshilling.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | RNIdleTimer.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 01D749591CC96385007E93FA 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ios/RNIdleTimer/IdleTimerManager.h: -------------------------------------------------------------------------------- 1 | #import 2 | #if __has_include("RCTBridgeModule.h") 3 | #import "RCTBridgeModule.h" 4 | #else 5 | #import 6 | #endif 7 | 8 | @interface IdleTimerManager : NSObject 9 | 10 | + (void)activate:(NSString*)tag; 11 | + (void)deactivate:(NSString*)tag; 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /ios/RNIdleTimer/IdleTimerManager.m: -------------------------------------------------------------------------------- 1 | #import "IdleTimerManager.h" 2 | 3 | const static NSMutableSet *tags; 4 | 5 | @implementation IdleTimerManager 6 | 7 | + (void) initialize { 8 | static dispatch_once_t onceToken; 9 | dispatch_once(&onceToken, ^{ 10 | tags = [NSMutableSet set]; 11 | }); 12 | } 13 | 14 | RCT_EXPORT_MODULE(); 15 | 16 | RCT_EXPORT_METHOD(setIdleTimerDisabled:(BOOL)disabled tag:(NSString *)tag) { 17 | if (disabled) { 18 | [IdleTimerManager activate:tag]; 19 | } else { 20 | [IdleTimerManager deactivate:tag]; 21 | } 22 | } 23 | 24 | + (void)activate:(NSString*)tag { 25 | if ([tags count] == 0) { 26 | dispatch_async(dispatch_get_main_queue(), ^{ 27 | [UIApplication sharedApplication].idleTimerDisabled = YES; 28 | }); 29 | } 30 | 31 | [tags addObject:tag ?: @""]; 32 | } 33 | 34 | + (void)deactivate:(NSString*)tag { 35 | if ([tags count] == 1 && [tags containsObject:tag ?: @""]) { 36 | dispatch_async(dispatch_get_main_queue(), ^{ 37 | [UIApplication sharedApplication].idleTimerDisabled = NO; 38 | }); 39 | } 40 | 41 | [tags removeObject:tag ?: @""]; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-idle-timer", 3 | "repository": { 4 | "type": "git", 5 | "url": "https://github.com/marcshilling/react-native-idle-timer" 6 | }, 7 | "version": "2.2.2", 8 | "author": "Marc Shilling (marcshilling)", 9 | "license": "MIT", 10 | "description": "A cross-platform bridge that allows you to enable and disable the screen idle timer in your React Native app", 11 | "keywords": [ 12 | "react-native", 13 | "react-native-idle-timer", 14 | "react", 15 | "native", 16 | "screen", 17 | "lock", 18 | "sleep", 19 | "idle", 20 | "timer", 21 | "dim" 22 | ], 23 | "nativePackage": true, 24 | "main": "index.js", 25 | "types": "index.d.ts" 26 | } 27 | -------------------------------------------------------------------------------- /react-native-idle-timer.podspec: -------------------------------------------------------------------------------- 1 | require 'json' 2 | 3 | package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) 4 | 5 | Pod::Spec.new do |s| 6 | s.name = package['name'] 7 | s.version = package['version'] 8 | s.summary = package['description'] 9 | s.description = package['description'] 10 | s.license = package['license'] 11 | s.author = package['author'] 12 | s.homepage = package['repository']['url'] 13 | s.source = { :git => 'https://github.com/marcshilling/react-native-idle-timer.git', :tag => s.version } 14 | 15 | s.requires_arc = true 16 | s.platforms = { ios: '7.0', tvos: '9.0' } 17 | 18 | s.preserve_paths = 'README.md', 'package.json', 'index.js' 19 | s.source_files = 'ios/RNIdleTimer/*.{h,m}' 20 | 21 | s.dependency 'React-Core' 22 | end 23 | --------------------------------------------------------------------------------