expo-keep-awake 9.1.2 → 10.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +1 -1
- package/android/build.gradle +28 -18
- package/android/src/main/java/expo/modules/keepawake/ExpoKeepAwakeManager.kt +62 -0
- package/android/src/main/java/expo/modules/keepawake/KeepAwakeModule.kt +54 -0
- package/android/src/main/java/expo/modules/keepawake/KeepAwakePackage.kt +17 -0
- package/build/ExpoKeepAwake.d.ts +1 -1
- package/build/ExpoKeepAwake.js +1 -1
- package/build/ExpoKeepAwake.js.map +1 -1
- package/build/index.d.ts +21 -0
- package/build/index.js +24 -0
- package/build/index.js.map +1 -1
- package/ios/EXKeepAwake/EXKeepAwake.h +3 -3
- package/ios/EXKeepAwake/EXKeepAwake.m +21 -21
- package/ios/EXKeepAwake.podspec +3 -2
- package/package.json +7 -3
- package/src/ExpoKeepAwake.ts +1 -1
- package/src/index.ts +25 -0
- package/android/src/main/java/expo/modules/keepawake/ExpoKeepAwakeManager.java +0 -69
- package/android/src/main/java/expo/modules/keepawake/KeepAwakeModule.java +0 -57
- package/android/src/main/java/expo/modules/keepawake/KeepAwakePackage.java +0 -23
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,34 @@
|
|
|
8
8
|
|
|
9
9
|
### 🐛 Bug fixes
|
|
10
10
|
|
|
11
|
+
### 💡 Others
|
|
12
|
+
|
|
13
|
+
## 10.0.1 — 2021-11-17
|
|
14
|
+
|
|
15
|
+
_This version does not introduce any user-facing changes._
|
|
16
|
+
|
|
17
|
+
## 10.0.0 — 2021-09-28
|
|
18
|
+
|
|
19
|
+
### 🛠 Breaking changes
|
|
20
|
+
|
|
21
|
+
- Dropped support for iOS 11.0 ([#14383](https://github.com/expo/expo/pull/14383) by [@cruzach](https://github.com/cruzach))
|
|
22
|
+
|
|
23
|
+
### 🐛 Bug fixes
|
|
24
|
+
|
|
25
|
+
- Fix building errors from use_frameworks! in Podfile. ([#14523](https://github.com/expo/expo/pull/14523) by [@kudo](https://github.com/kudo))
|
|
26
|
+
|
|
27
|
+
## 9.3.0 — 2021-09-08
|
|
28
|
+
|
|
29
|
+
### 💡 Others
|
|
30
|
+
|
|
31
|
+
- Rewrite android code to Kotlin. ([#13996](https://github.com/expo/expo/pull/13996) by [@kkafar](https://github.com/kkafar))
|
|
32
|
+
|
|
33
|
+
## 9.2.0 — 2021-06-16
|
|
34
|
+
|
|
35
|
+
### 🐛 Bug fixes
|
|
36
|
+
|
|
37
|
+
- Enable kotlin in all modules. ([#12716](https://github.com/expo/expo/pull/12716) by [@wschurman](https://github.com/wschurman))
|
|
38
|
+
|
|
11
39
|
## 9.1.2 — 2021-04-13
|
|
12
40
|
|
|
13
41
|
_This version does not introduce any user-facing changes._
|
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ For managed [managed](https://docs.expo.io/versions/latest/introduction/managed-
|
|
|
13
13
|
|
|
14
14
|
# Installation in bare React Native projects
|
|
15
15
|
|
|
16
|
-
For bare React Native projects, you must ensure that you have [installed and configured the `
|
|
16
|
+
For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
|
|
17
17
|
|
|
18
18
|
### Add the package to your npm dependencies
|
|
19
19
|
|
package/android/build.gradle
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
|
+
apply plugin: 'kotlin-android'
|
|
2
3
|
apply plugin: 'maven'
|
|
3
4
|
|
|
4
5
|
group = 'host.exp.exponent'
|
|
5
|
-
version = '
|
|
6
|
+
version = '10.0.1'
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
buildscript {
|
|
9
|
+
// Simple helper that allows the root project to override versions declared by this library.
|
|
10
|
+
ext.safeExtGet = { prop, fallback ->
|
|
11
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
repositories {
|
|
15
|
+
mavenCentral()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
dependencies {
|
|
19
|
+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', '1.4.21')}")
|
|
20
|
+
}
|
|
10
21
|
}
|
|
11
22
|
|
|
12
23
|
// Upload android library to maven with javadoc and android sources
|
|
@@ -37,29 +48,28 @@ uploadArchives {
|
|
|
37
48
|
android {
|
|
38
49
|
compileSdkVersion safeExtGet("compileSdkVersion", 30)
|
|
39
50
|
|
|
51
|
+
compileOptions {
|
|
52
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
53
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
kotlinOptions {
|
|
57
|
+
jvmTarget = "1.8"
|
|
58
|
+
}
|
|
59
|
+
|
|
40
60
|
defaultConfig {
|
|
41
61
|
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
42
62
|
targetSdkVersion safeExtGet("targetSdkVersion", 30)
|
|
43
63
|
versionCode 16
|
|
44
|
-
versionName "
|
|
64
|
+
versionName "10.0.1"
|
|
45
65
|
}
|
|
46
66
|
lintOptions {
|
|
47
67
|
abortOnError false
|
|
48
68
|
}
|
|
49
|
-
compileOptions {
|
|
50
|
-
sourceCompatibility = '1.8'
|
|
51
|
-
targetCompatibility = '1.8'
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (new File(rootProject.projectDir.parentFile, 'package.json').exists()) {
|
|
56
|
-
apply from: project(":unimodules-core").file("../unimodules-core.gradle")
|
|
57
|
-
} else {
|
|
58
|
-
throw new GradleException(
|
|
59
|
-
"'unimodules-core.gradle' was not found in the usual React Native dependency location. " +
|
|
60
|
-
"This package can only be used in such projects. Are you sure you've installed the dependencies properly?")
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
dependencies {
|
|
64
|
-
|
|
72
|
+
implementation project(':expo-modules-core')
|
|
73
|
+
|
|
74
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${safeExtGet('kotlinVersion', '1.4.21')}"
|
|
65
75
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
package expo.modules.keepawake
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.view.WindowManager
|
|
5
|
+
|
|
6
|
+
import expo.modules.core.interfaces.services.KeepAwakeManager
|
|
7
|
+
import expo.modules.core.interfaces.InternalModule
|
|
8
|
+
import expo.modules.core.ModuleRegistry
|
|
9
|
+
import expo.modules.core.ModuleRegistryDelegate
|
|
10
|
+
import expo.modules.core.errors.CurrentActivityNotFoundException
|
|
11
|
+
import expo.modules.core.interfaces.ActivityProvider
|
|
12
|
+
|
|
13
|
+
import java.util.HashSet
|
|
14
|
+
|
|
15
|
+
class ExpoKeepAwakeManager(private val moduleRegistryDelegate: ModuleRegistryDelegate = ModuleRegistryDelegate()) : KeepAwakeManager, InternalModule {
|
|
16
|
+
private val tags: MutableSet<String> = HashSet()
|
|
17
|
+
|
|
18
|
+
private inline fun <reified T> moduleRegistry() = moduleRegistryDelegate.getFromModuleRegistry<T>()
|
|
19
|
+
|
|
20
|
+
override fun onCreate(moduleRegistry: ModuleRegistry) {
|
|
21
|
+
moduleRegistryDelegate.onCreate(moduleRegistry)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@get:Throws(CurrentActivityNotFoundException::class)
|
|
25
|
+
private val currentActivity: Activity
|
|
26
|
+
get() {
|
|
27
|
+
val activityProvider: ActivityProvider by moduleRegistry()
|
|
28
|
+
return if (activityProvider.currentActivity != null) {
|
|
29
|
+
activityProvider.currentActivity
|
|
30
|
+
} else {
|
|
31
|
+
throw CurrentActivityNotFoundException()
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Throws(CurrentActivityNotFoundException::class)
|
|
36
|
+
override fun activate(tag: String, done: Runnable) {
|
|
37
|
+
val activity = currentActivity
|
|
38
|
+
if (!isActivated) {
|
|
39
|
+
activity.runOnUiThread { activity.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) }
|
|
40
|
+
}
|
|
41
|
+
tags.add(tag)
|
|
42
|
+
done.run()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Throws(CurrentActivityNotFoundException::class)
|
|
46
|
+
override fun deactivate(tag: String, done: Runnable) {
|
|
47
|
+
val activity = currentActivity
|
|
48
|
+
if (tags.size == 1 && tags.contains(tag)) {
|
|
49
|
+
activity.runOnUiThread { activity.window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) }
|
|
50
|
+
}
|
|
51
|
+
tags.remove(tag)
|
|
52
|
+
done.run()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override fun isActivated(): Boolean {
|
|
56
|
+
return tags.isNotEmpty()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
override fun getExportedInterfaces(): List<Class<*>?> {
|
|
60
|
+
return listOf(KeepAwakeManager::class.java)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Copyright 2015-present 650 Industries. All rights reserved.
|
|
2
|
+
package expo.modules.keepawake
|
|
3
|
+
|
|
4
|
+
import android.content.Context
|
|
5
|
+
|
|
6
|
+
import expo.modules.core.ExportedModule
|
|
7
|
+
import expo.modules.core.ModuleRegistry
|
|
8
|
+
import expo.modules.core.interfaces.services.KeepAwakeManager
|
|
9
|
+
import expo.modules.core.ModuleRegistryDelegate
|
|
10
|
+
import expo.modules.core.Promise
|
|
11
|
+
import expo.modules.core.interfaces.ExpoMethod
|
|
12
|
+
import expo.modules.core.errors.CurrentActivityNotFoundException
|
|
13
|
+
|
|
14
|
+
private const val NAME = "ExpoKeepAwake"
|
|
15
|
+
private const val NO_ACTIVITY_ERROR_CODE = "NO_CURRENT_ACTIVITY"
|
|
16
|
+
|
|
17
|
+
class KeepAwakeModule(
|
|
18
|
+
context: Context,
|
|
19
|
+
private val moduleRegistryDelegate: ModuleRegistryDelegate = ModuleRegistryDelegate()
|
|
20
|
+
) : ExportedModule(context) {
|
|
21
|
+
|
|
22
|
+
private val keepAwakeManager: KeepAwakeManager by moduleRegistry()
|
|
23
|
+
|
|
24
|
+
private inline fun <reified T> moduleRegistry() = moduleRegistryDelegate.getFromModuleRegistry<T>()
|
|
25
|
+
|
|
26
|
+
override fun onCreate(moduleRegistry: ModuleRegistry) {
|
|
27
|
+
moduleRegistryDelegate.onCreate(moduleRegistry)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override fun getName(): String {
|
|
31
|
+
return NAME
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@ExpoMethod
|
|
35
|
+
fun activate(tag: String, promise: Promise) {
|
|
36
|
+
try {
|
|
37
|
+
keepAwakeManager.activate(tag) { promise.resolve(true) }
|
|
38
|
+
} catch (ex: CurrentActivityNotFoundException) {
|
|
39
|
+
promise.reject(NO_ACTIVITY_ERROR_CODE, "Unable to activate keep awake")
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@ExpoMethod
|
|
44
|
+
fun deactivate(tag: String, promise: Promise) {
|
|
45
|
+
try {
|
|
46
|
+
keepAwakeManager.deactivate(tag) { promise.resolve(true) }
|
|
47
|
+
} catch (ex: CurrentActivityNotFoundException) {
|
|
48
|
+
promise.reject(NO_ACTIVITY_ERROR_CODE, "Unable to deactivate keep awake. However, it probably is deactivated already.")
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
val isActivated: Boolean
|
|
53
|
+
get() = keepAwakeManager.isActivated
|
|
54
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package expo.modules.keepawake
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
|
|
5
|
+
import expo.modules.core.ExportedModule
|
|
6
|
+
import expo.modules.core.interfaces.InternalModule
|
|
7
|
+
import expo.modules.core.interfaces.Package
|
|
8
|
+
|
|
9
|
+
class KeepAwakePackage : Package {
|
|
10
|
+
override fun createExportedModules(context: Context): List<ExportedModule> {
|
|
11
|
+
return listOf(KeepAwakeModule(context))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
override fun createInternalModules(context: Context): List<InternalModule> {
|
|
15
|
+
return listOf(ExpoKeepAwakeManager())
|
|
16
|
+
}
|
|
17
|
+
}
|
package/build/ExpoKeepAwake.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("
|
|
1
|
+
declare const _default: import("expo-modules-core").ProxyNativeModule;
|
|
2
2
|
export default _default;
|
package/build/ExpoKeepAwake.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoKeepAwake.js","sourceRoot":"","sources":["../src/ExpoKeepAwake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ExpoKeepAwake.js","sourceRoot":"","sources":["../src/ExpoKeepAwake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,eAAe,kBAAkB,CAAC,aAAa,CAAC","sourcesContent":["import { NativeModulesProxy } from 'expo-modules-core';\nexport default NativeModulesProxy.ExpoKeepAwake;\n"]}
|
package/build/index.d.ts
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A React hook to keep the screen awake for as long as the owner component is mounted.
|
|
3
|
+
* The optionally provided `tag` argument is used when activating and deactivating the keep-awake
|
|
4
|
+
* feature. If unspecified, the default `tag` is used. See the documentation for `activateKeepAwake`
|
|
5
|
+
* below to learn more about the `tag` argument.
|
|
6
|
+
* @param tag *Optional*
|
|
7
|
+
*/
|
|
1
8
|
export declare function useKeepAwake(tag?: string): void;
|
|
9
|
+
/**
|
|
10
|
+
* Prevents the screen from sleeping until `deactivateKeepAwake` is called with the same `tag` value.
|
|
11
|
+
*
|
|
12
|
+
* If the `tag` argument is specified, the screen will not sleep until you call `deactivateKeepAwake`
|
|
13
|
+
* with the same `tag` argument. When using multiple `tags` for activation you'll have to deactivate
|
|
14
|
+
* each one in order to re-enable screen sleep. If tag is unspecified, the default `tag` is used.
|
|
15
|
+
* @param tag *Optional* - Tag to lock screen sleep prevention. If not provided, the default tag is used.
|
|
16
|
+
*/
|
|
2
17
|
export declare function activateKeepAwake(tag?: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* Releases the lock on screen-sleep prevention associated with the given `tag` value. If `tag`
|
|
20
|
+
* is unspecified, it defaults to the same default tag that `activateKeepAwake` uses.
|
|
21
|
+
* @param tag *Optional* - Tag to release the lock on screen sleep prevention. If not provided,
|
|
22
|
+
* the default tag is used.
|
|
23
|
+
*/
|
|
3
24
|
export declare function deactivateKeepAwake(tag?: string): void;
|
package/build/index.js
CHANGED
|
@@ -1,16 +1,40 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import ExpoKeepAwake from './ExpoKeepAwake';
|
|
3
3
|
const ExpoKeepAwakeTag = 'ExpoKeepAwakeDefaultTag';
|
|
4
|
+
// @needsAudit
|
|
5
|
+
/**
|
|
6
|
+
* A React hook to keep the screen awake for as long as the owner component is mounted.
|
|
7
|
+
* The optionally provided `tag` argument is used when activating and deactivating the keep-awake
|
|
8
|
+
* feature. If unspecified, the default `tag` is used. See the documentation for `activateKeepAwake`
|
|
9
|
+
* below to learn more about the `tag` argument.
|
|
10
|
+
* @param tag *Optional*
|
|
11
|
+
*/
|
|
4
12
|
export function useKeepAwake(tag = ExpoKeepAwakeTag) {
|
|
5
13
|
useEffect(() => {
|
|
6
14
|
activateKeepAwake(tag);
|
|
7
15
|
return () => deactivateKeepAwake(tag);
|
|
8
16
|
}, [tag]);
|
|
9
17
|
}
|
|
18
|
+
// @needsAudit
|
|
19
|
+
/**
|
|
20
|
+
* Prevents the screen from sleeping until `deactivateKeepAwake` is called with the same `tag` value.
|
|
21
|
+
*
|
|
22
|
+
* If the `tag` argument is specified, the screen will not sleep until you call `deactivateKeepAwake`
|
|
23
|
+
* with the same `tag` argument. When using multiple `tags` for activation you'll have to deactivate
|
|
24
|
+
* each one in order to re-enable screen sleep. If tag is unspecified, the default `tag` is used.
|
|
25
|
+
* @param tag *Optional* - Tag to lock screen sleep prevention. If not provided, the default tag is used.
|
|
26
|
+
*/
|
|
10
27
|
export function activateKeepAwake(tag = ExpoKeepAwakeTag) {
|
|
11
28
|
if (ExpoKeepAwake.activate)
|
|
12
29
|
ExpoKeepAwake.activate(tag);
|
|
13
30
|
}
|
|
31
|
+
// @needsAudit
|
|
32
|
+
/**
|
|
33
|
+
* Releases the lock on screen-sleep prevention associated with the given `tag` value. If `tag`
|
|
34
|
+
* is unspecified, it defaults to the same default tag that `activateKeepAwake` uses.
|
|
35
|
+
* @param tag *Optional* - Tag to release the lock on screen sleep prevention. If not provided,
|
|
36
|
+
* the default tag is used.
|
|
37
|
+
*/
|
|
14
38
|
export function deactivateKeepAwake(tag = ExpoKeepAwakeTag) {
|
|
15
39
|
if (ExpoKeepAwake.deactivate)
|
|
16
40
|
ExpoKeepAwake.deactivate(tag);
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAEnD,MAAM,UAAU,YAAY,CAAC,MAAc,gBAAgB;IACzD,SAAS,CAAC,GAAG,EAAE;QACb,iBAAiB,CAAC,GAAG,CAAC,CAAC;QACvB,OAAO,GAAG,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IACxC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAc,gBAAgB;IAC9D,IAAI,aAAa,CAAC,QAAQ;QAAE,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAAc,gBAAgB;IAChE,IAAI,aAAa,CAAC,UAAU;QAAE,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["import { useEffect } from 'react';\n\nimport ExpoKeepAwake from './ExpoKeepAwake';\n\nconst ExpoKeepAwakeTag = 'ExpoKeepAwakeDefaultTag';\n\nexport function useKeepAwake(tag: string = ExpoKeepAwakeTag): void {\n useEffect(() => {\n activateKeepAwake(tag);\n return () => deactivateKeepAwake(tag);\n }, [tag]);\n}\n\nexport function activateKeepAwake(tag: string = ExpoKeepAwakeTag): void {\n if (ExpoKeepAwake.activate) ExpoKeepAwake.activate(tag);\n}\n\nexport function deactivateKeepAwake(tag: string = ExpoKeepAwakeTag): void {\n if (ExpoKeepAwake.deactivate) ExpoKeepAwake.deactivate(tag);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAEnD,cAAc;AACd;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc,gBAAgB;IACzD,SAAS,CAAC,GAAG,EAAE;QACb,iBAAiB,CAAC,GAAG,CAAC,CAAC;QACvB,OAAO,GAAG,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IACxC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;AACZ,CAAC;AAED,cAAc;AACd;;;;;;;GAOG;AAEH,MAAM,UAAU,iBAAiB,CAAC,MAAc,gBAAgB;IAC9D,IAAI,aAAa,CAAC,QAAQ;QAAE,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC;AAED,cAAc;AACd;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAc,gBAAgB;IAChE,IAAI,aAAa,CAAC,UAAU;QAAE,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["import { useEffect } from 'react';\n\nimport ExpoKeepAwake from './ExpoKeepAwake';\n\nconst ExpoKeepAwakeTag = 'ExpoKeepAwakeDefaultTag';\n\n// @needsAudit\n/**\n * A React hook to keep the screen awake for as long as the owner component is mounted.\n * The optionally provided `tag` argument is used when activating and deactivating the keep-awake\n * feature. If unspecified, the default `tag` is used. See the documentation for `activateKeepAwake`\n * below to learn more about the `tag` argument.\n * @param tag *Optional*\n */\nexport function useKeepAwake(tag: string = ExpoKeepAwakeTag): void {\n useEffect(() => {\n activateKeepAwake(tag);\n return () => deactivateKeepAwake(tag);\n }, [tag]);\n}\n\n// @needsAudit\n/**\n * Prevents the screen from sleeping until `deactivateKeepAwake` is called with the same `tag` value.\n *\n * If the `tag` argument is specified, the screen will not sleep until you call `deactivateKeepAwake`\n * with the same `tag` argument. When using multiple `tags` for activation you'll have to deactivate\n * each one in order to re-enable screen sleep. If tag is unspecified, the default `tag` is used.\n * @param tag *Optional* - Tag to lock screen sleep prevention. If not provided, the default tag is used.\n */\n\nexport function activateKeepAwake(tag: string = ExpoKeepAwakeTag): void {\n if (ExpoKeepAwake.activate) ExpoKeepAwake.activate(tag);\n}\n\n// @needsAudit\n/**\n * Releases the lock on screen-sleep prevention associated with the given `tag` value. If `tag`\n * is unspecified, it defaults to the same default tag that `activateKeepAwake` uses.\n * @param tag *Optional* - Tag to release the lock on screen sleep prevention. If not provided,\n * the default tag is used.\n */\nexport function deactivateKeepAwake(tag: string = ExpoKeepAwakeTag): void {\n if (ExpoKeepAwake.deactivate) ExpoKeepAwake.deactivate(tag);\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2018-present 650 Industries. All rights reserved.
|
|
2
2
|
|
|
3
|
-
#import <
|
|
4
|
-
#import <
|
|
3
|
+
#import <ExpoModulesCore/EXExportedModule.h>
|
|
4
|
+
#import <ExpoModulesCore/EXModuleRegistryConsumer.h>
|
|
5
5
|
|
|
6
|
-
@interface EXKeepAwake :
|
|
6
|
+
@interface EXKeepAwake : EXExportedModule <EXModuleRegistryConsumer>
|
|
7
7
|
@end
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// Copyright 2018-present 650 Industries. All rights reserved.
|
|
2
2
|
|
|
3
|
-
#import <
|
|
3
|
+
#import <ExpoModulesCore/EXModuleRegistry.h>
|
|
4
4
|
#import <EXKeepAwake/EXKeepAwake.h>
|
|
5
|
-
#import <
|
|
6
|
-
#import <
|
|
5
|
+
#import <ExpoModulesCore/EXAppLifecycleService.h>
|
|
6
|
+
#import <ExpoModulesCore/EXUtilities.h>
|
|
7
7
|
|
|
8
|
-
@interface EXKeepAwake () <
|
|
8
|
+
@interface EXKeepAwake () <EXAppLifecycleListener>
|
|
9
9
|
|
|
10
|
-
@property (nonatomic, weak) id<
|
|
11
|
-
@property (nonatomic, weak)
|
|
10
|
+
@property (nonatomic, weak) id<EXAppLifecycleService> lifecycleManager;
|
|
11
|
+
@property (nonatomic, weak) EXModuleRegistry *moduleRegistry;
|
|
12
12
|
|
|
13
13
|
@end
|
|
14
14
|
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
return self;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
EX_EXPORT_MODULE(ExpoKeepAwake);
|
|
26
26
|
|
|
27
|
-
# pragma mark -
|
|
27
|
+
# pragma mark - EXModuleRegistryConsumer
|
|
28
28
|
|
|
29
|
-
- (void)setModuleRegistry:(
|
|
29
|
+
- (void)setModuleRegistry:(EXModuleRegistry *)moduleRegistry
|
|
30
30
|
{
|
|
31
31
|
if (_moduleRegistry) {
|
|
32
32
|
[_lifecycleManager unregisterAppLifecycleListener:self];
|
|
@@ -35,7 +35,7 @@ UM_EXPORT_MODULE(ExpoKeepAwake);
|
|
|
35
35
|
_lifecycleManager = nil;
|
|
36
36
|
|
|
37
37
|
if (moduleRegistry) {
|
|
38
|
-
_lifecycleManager = [moduleRegistry getModuleImplementingProtocol:@protocol(
|
|
38
|
+
_lifecycleManager = [moduleRegistry getModuleImplementingProtocol:@protocol(EXAppLifecycleService)];
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
if (_lifecycleManager) {
|
|
@@ -43,12 +43,12 @@ UM_EXPORT_MODULE(ExpoKeepAwake);
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
resolve:(
|
|
48
|
-
reject:(
|
|
46
|
+
EX_EXPORT_METHOD_AS(activate, activate:(NSString *)tag
|
|
47
|
+
resolve:(EXPromiseResolveBlock)resolve
|
|
48
|
+
reject:(EXPromiseRejectBlock)reject)
|
|
49
49
|
{
|
|
50
50
|
if(![self shouldBeActive]) {
|
|
51
|
-
[
|
|
51
|
+
[EXUtilities performSynchronouslyOnMainThread:^{
|
|
52
52
|
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
|
|
53
53
|
}];
|
|
54
54
|
}
|
|
@@ -56,30 +56,30 @@ UM_EXPORT_METHOD_AS(activate, activate:(NSString *)tag
|
|
|
56
56
|
resolve(@YES);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
resolve:(
|
|
61
|
-
reject:(
|
|
59
|
+
EX_EXPORT_METHOD_AS(deactivate, deactivate:(NSString *)tag
|
|
60
|
+
resolve:(EXPromiseResolveBlock)resolve
|
|
61
|
+
reject:(EXPromiseRejectBlock)reject)
|
|
62
62
|
{
|
|
63
63
|
[_activeTags removeObject:tag];
|
|
64
64
|
if (![self shouldBeActive]) {
|
|
65
|
-
[
|
|
65
|
+
[EXUtilities performSynchronouslyOnMainThread:^{
|
|
66
66
|
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
|
|
67
67
|
}];
|
|
68
68
|
}
|
|
69
69
|
resolve(@YES);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
# pragma mark -
|
|
72
|
+
# pragma mark - EXAppLifecycleListener
|
|
73
73
|
|
|
74
74
|
- (void)onAppBackgrounded {
|
|
75
|
-
[
|
|
75
|
+
[EXUtilities performSynchronouslyOnMainThread:^{
|
|
76
76
|
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
|
|
77
77
|
}];
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
- (void)onAppForegrounded {
|
|
81
81
|
if ([self shouldBeActive]) {
|
|
82
|
-
[
|
|
82
|
+
[EXUtilities performSynchronouslyOnMainThread:^{
|
|
83
83
|
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
|
|
84
84
|
}];
|
|
85
85
|
}
|
package/ios/EXKeepAwake.podspec
CHANGED
|
@@ -10,10 +10,11 @@ Pod::Spec.new do |s|
|
|
|
10
10
|
s.license = package['license']
|
|
11
11
|
s.author = package['author']
|
|
12
12
|
s.homepage = package['homepage']
|
|
13
|
-
s.platform = :ios, '
|
|
13
|
+
s.platform = :ios, '12.0'
|
|
14
14
|
s.source = { git: 'https://github.com/expo/expo.git' }
|
|
15
|
+
s.static_framework = true
|
|
15
16
|
|
|
16
|
-
s.dependency '
|
|
17
|
+
s.dependency 'ExpoModulesCore'
|
|
17
18
|
|
|
18
19
|
if !$ExpoUseSources&.include?(package['name']) && ENV['EXPO_USE_SOURCE'].to_i == 0 && File.exist?("#{s.name}.xcframework") && Gem::Version.new(Pod::VERSION) >= Gem::Version.new('1.10.0')
|
|
19
20
|
s.source_files = "#{s.name}/**/*.h"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-keep-awake",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.1",
|
|
4
4
|
"description": "Provides a React component that prevents the screen sleeping when rendered. It also exposes static methods to control the behavior imperatively.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -30,9 +30,13 @@
|
|
|
30
30
|
},
|
|
31
31
|
"author": "650 Industries, Inc.",
|
|
32
32
|
"license": "MIT",
|
|
33
|
-
"homepage": "https://docs.expo.
|
|
33
|
+
"homepage": "https://docs.expo.dev/versions/latest/sdk/keep-awake/",
|
|
34
|
+
"dependencies": {},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"expo-module-scripts": "^2.0.0"
|
|
36
37
|
},
|
|
37
|
-
"
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"expo": "*"
|
|
40
|
+
},
|
|
41
|
+
"gitHead": "9faa58818454ba59dbff95077b9025a1c1cbd9fd"
|
|
38
42
|
}
|
package/src/ExpoKeepAwake.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { NativeModulesProxy } from '
|
|
1
|
+
import { NativeModulesProxy } from 'expo-modules-core';
|
|
2
2
|
export default NativeModulesProxy.ExpoKeepAwake;
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,14 @@ import ExpoKeepAwake from './ExpoKeepAwake';
|
|
|
4
4
|
|
|
5
5
|
const ExpoKeepAwakeTag = 'ExpoKeepAwakeDefaultTag';
|
|
6
6
|
|
|
7
|
+
// @needsAudit
|
|
8
|
+
/**
|
|
9
|
+
* A React hook to keep the screen awake for as long as the owner component is mounted.
|
|
10
|
+
* The optionally provided `tag` argument is used when activating and deactivating the keep-awake
|
|
11
|
+
* feature. If unspecified, the default `tag` is used. See the documentation for `activateKeepAwake`
|
|
12
|
+
* below to learn more about the `tag` argument.
|
|
13
|
+
* @param tag *Optional*
|
|
14
|
+
*/
|
|
7
15
|
export function useKeepAwake(tag: string = ExpoKeepAwakeTag): void {
|
|
8
16
|
useEffect(() => {
|
|
9
17
|
activateKeepAwake(tag);
|
|
@@ -11,10 +19,27 @@ export function useKeepAwake(tag: string = ExpoKeepAwakeTag): void {
|
|
|
11
19
|
}, [tag]);
|
|
12
20
|
}
|
|
13
21
|
|
|
22
|
+
// @needsAudit
|
|
23
|
+
/**
|
|
24
|
+
* Prevents the screen from sleeping until `deactivateKeepAwake` is called with the same `tag` value.
|
|
25
|
+
*
|
|
26
|
+
* If the `tag` argument is specified, the screen will not sleep until you call `deactivateKeepAwake`
|
|
27
|
+
* with the same `tag` argument. When using multiple `tags` for activation you'll have to deactivate
|
|
28
|
+
* each one in order to re-enable screen sleep. If tag is unspecified, the default `tag` is used.
|
|
29
|
+
* @param tag *Optional* - Tag to lock screen sleep prevention. If not provided, the default tag is used.
|
|
30
|
+
*/
|
|
31
|
+
|
|
14
32
|
export function activateKeepAwake(tag: string = ExpoKeepAwakeTag): void {
|
|
15
33
|
if (ExpoKeepAwake.activate) ExpoKeepAwake.activate(tag);
|
|
16
34
|
}
|
|
17
35
|
|
|
36
|
+
// @needsAudit
|
|
37
|
+
/**
|
|
38
|
+
* Releases the lock on screen-sleep prevention associated with the given `tag` value. If `tag`
|
|
39
|
+
* is unspecified, it defaults to the same default tag that `activateKeepAwake` uses.
|
|
40
|
+
* @param tag *Optional* - Tag to release the lock on screen sleep prevention. If not provided,
|
|
41
|
+
* the default tag is used.
|
|
42
|
+
*/
|
|
18
43
|
export function deactivateKeepAwake(tag: string = ExpoKeepAwakeTag): void {
|
|
19
44
|
if (ExpoKeepAwake.deactivate) ExpoKeepAwake.deactivate(tag);
|
|
20
45
|
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
package expo.modules.keepawake;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.view.WindowManager;
|
|
5
|
-
|
|
6
|
-
import org.unimodules.core.ModuleRegistry;
|
|
7
|
-
import org.unimodules.core.errors.CurrentActivityNotFoundException;
|
|
8
|
-
import org.unimodules.core.interfaces.ActivityProvider;
|
|
9
|
-
import org.unimodules.core.interfaces.InternalModule;
|
|
10
|
-
import org.unimodules.core.interfaces.services.KeepAwakeManager;
|
|
11
|
-
|
|
12
|
-
import java.util.Collections;
|
|
13
|
-
import java.util.HashSet;
|
|
14
|
-
import java.util.List;
|
|
15
|
-
import java.util.Set;
|
|
16
|
-
|
|
17
|
-
public class ExpoKeepAwakeManager implements KeepAwakeManager, InternalModule {
|
|
18
|
-
|
|
19
|
-
private ModuleRegistry mModuleRegistry;
|
|
20
|
-
private Set<String> mTags = new HashSet<>();
|
|
21
|
-
|
|
22
|
-
@Override
|
|
23
|
-
public void onCreate(ModuleRegistry moduleRegistry) {
|
|
24
|
-
mModuleRegistry = moduleRegistry;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
private Activity getCurrentActivity() throws CurrentActivityNotFoundException {
|
|
28
|
-
ActivityProvider activityProvider = mModuleRegistry.getModule(ActivityProvider.class);
|
|
29
|
-
if (activityProvider.getCurrentActivity() != null) {
|
|
30
|
-
return activityProvider.getCurrentActivity();
|
|
31
|
-
} else {
|
|
32
|
-
throw new CurrentActivityNotFoundException();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@Override
|
|
37
|
-
public void activate(final String tag, final Runnable done) throws CurrentActivityNotFoundException {
|
|
38
|
-
final Activity activity = getCurrentActivity();
|
|
39
|
-
|
|
40
|
-
if (!isActivated()) {
|
|
41
|
-
if (activity != null) {
|
|
42
|
-
activity.runOnUiThread(() -> activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
mTags.add(tag);
|
|
46
|
-
done.run();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@Override
|
|
50
|
-
public void deactivate(final String tag, final Runnable done) throws CurrentActivityNotFoundException {
|
|
51
|
-
final Activity activity = getCurrentActivity();
|
|
52
|
-
|
|
53
|
-
if (mTags.size() == 1 && mTags.contains(tag) && activity != null) {
|
|
54
|
-
activity.runOnUiThread(() -> activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON));
|
|
55
|
-
}
|
|
56
|
-
mTags.remove(tag);
|
|
57
|
-
done.run();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@Override
|
|
61
|
-
public boolean isActivated() {
|
|
62
|
-
return mTags.size() > 0;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
@Override
|
|
66
|
-
public List<? extends Class> getExportedInterfaces() {
|
|
67
|
-
return Collections.singletonList(KeepAwakeManager.class);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// Copyright 2015-present 650 Industries. All rights reserved.
|
|
2
|
-
|
|
3
|
-
package expo.modules.keepawake;
|
|
4
|
-
|
|
5
|
-
import android.content.Context;
|
|
6
|
-
|
|
7
|
-
import org.unimodules.core.ExportedModule;
|
|
8
|
-
import org.unimodules.core.ModuleRegistry;
|
|
9
|
-
import org.unimodules.core.Promise;
|
|
10
|
-
import org.unimodules.core.errors.CurrentActivityNotFoundException;
|
|
11
|
-
import org.unimodules.core.interfaces.ExpoMethod;
|
|
12
|
-
import org.unimodules.core.interfaces.services.KeepAwakeManager;
|
|
13
|
-
|
|
14
|
-
public class KeepAwakeModule extends ExportedModule {
|
|
15
|
-
private static final String NAME = "ExpoKeepAwake";
|
|
16
|
-
private final static String NO_ACTIVITY_ERROR_CODE = "NO_CURRENT_ACTIVITY";
|
|
17
|
-
|
|
18
|
-
private KeepAwakeManager mKeepAwakeManager;
|
|
19
|
-
|
|
20
|
-
public KeepAwakeModule(Context context) {
|
|
21
|
-
super(context);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
@Override
|
|
25
|
-
public String getName() {
|
|
26
|
-
return NAME;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@Override
|
|
30
|
-
public void onCreate(ModuleRegistry moduleRegistry) {
|
|
31
|
-
mKeepAwakeManager = moduleRegistry.getModule(KeepAwakeManager.class);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
@ExpoMethod
|
|
36
|
-
public void activate(String tag, final Promise promise) {
|
|
37
|
-
try {
|
|
38
|
-
mKeepAwakeManager.activate(tag, () -> promise.resolve(true));
|
|
39
|
-
} catch (CurrentActivityNotFoundException ex) {
|
|
40
|
-
promise.reject(NO_ACTIVITY_ERROR_CODE, "Unable to activate keep awake");
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
@ExpoMethod
|
|
45
|
-
public void deactivate(String tag, Promise promise) {
|
|
46
|
-
try {
|
|
47
|
-
mKeepAwakeManager.deactivate(tag, () -> promise.resolve(true));
|
|
48
|
-
} catch (CurrentActivityNotFoundException ex) {
|
|
49
|
-
promise.reject(NO_ACTIVITY_ERROR_CODE, "Unable to deactivate keep awake. However, it probably is deactivated already.");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public boolean isActivated() {
|
|
55
|
-
return mKeepAwakeManager.isActivated();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
package expo.modules.keepawake;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
|
|
5
|
-
import org.unimodules.core.ExportedModule;
|
|
6
|
-
import org.unimodules.core.interfaces.InternalModule;
|
|
7
|
-
import org.unimodules.core.interfaces.Package;
|
|
8
|
-
|
|
9
|
-
import java.util.Collections;
|
|
10
|
-
import java.util.List;
|
|
11
|
-
|
|
12
|
-
public class KeepAwakePackage implements Package {
|
|
13
|
-
|
|
14
|
-
@Override
|
|
15
|
-
public List<ExportedModule> createExportedModules(Context context) {
|
|
16
|
-
return Collections.<ExportedModule>singletonList(new KeepAwakeModule(context));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@Override
|
|
20
|
-
public List<? extends InternalModule> createInternalModules(Context context) {
|
|
21
|
-
return Collections.singletonList(new ExpoKeepAwakeManager());
|
|
22
|
-
}
|
|
23
|
-
}
|