expo-keep-awake 10.1.0 → 10.2.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 +16 -0
- package/android/build.gradle +2 -2
- package/build/index.d.ts +13 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +21 -10
- package/build/index.js.map +1 -1
- package/ios/KeepAwakeModule.swift +23 -26
- package/package.json +6 -2
- package/src/index.ts +25 -8
- package/tsconfig.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,22 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 10.2.1 — 2022-08-08
|
|
14
|
+
|
|
15
|
+
### 🐛 Bug fixes
|
|
16
|
+
|
|
17
|
+
- Attempt to fix `EXC_BAD_ACCESS` and `NSInvalidArgumentException` crashes by not referencing to the class instance function. ([#18553](https://github.com/expo/expo/pull/18553) by [@tsapeta](https://github.com/tsapeta))
|
|
18
|
+
|
|
19
|
+
## 10.2.0 — 2022-07-07
|
|
20
|
+
|
|
21
|
+
### 🐛 Bug fixes
|
|
22
|
+
|
|
23
|
+
- Fixed `Unable to deactivate keep awake. However, it probably is deactivated already` unhandled promise rejection warning when resuming apps on Android. ([#17319](https://github.com/expo/expo/pull/17319) by [@kudo](https://github.com/kudo))
|
|
24
|
+
|
|
25
|
+
### 💡 Others
|
|
26
|
+
|
|
27
|
+
- Migrated Expo modules definitions to the new naming convention. ([#17193](https://github.com/expo/expo/pull/17193) by [@tsapeta](https://github.com/tsapeta))
|
|
28
|
+
|
|
13
29
|
## 10.1.0 — 2022-04-18
|
|
14
30
|
|
|
15
31
|
### 🎉 New features
|
package/android/build.gradle
CHANGED
|
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
|
|
|
3
3
|
apply plugin: 'maven-publish'
|
|
4
4
|
|
|
5
5
|
group = 'host.exp.exponent'
|
|
6
|
-
version = '10.1
|
|
6
|
+
version = '10.2.1'
|
|
7
7
|
|
|
8
8
|
buildscript {
|
|
9
9
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
@@ -74,7 +74,7 @@ android {
|
|
|
74
74
|
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
75
75
|
targetSdkVersion safeExtGet("targetSdkVersion", 31)
|
|
76
76
|
versionCode 16
|
|
77
|
-
versionName "10.1
|
|
77
|
+
versionName "10.2.1"
|
|
78
78
|
}
|
|
79
79
|
lintOptions {
|
|
80
80
|
abortOnError false
|
package/build/index.d.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
+
export declare const ExpoKeepAwakeTag = "ExpoKeepAwakeDefaultTag";
|
|
1
2
|
/**
|
|
2
3
|
* A React hook to keep the screen awake for as long as the owner component is mounted.
|
|
3
4
|
* The optionally provided `tag` argument is used when activating and deactivating the keep-awake
|
|
4
5
|
* feature. If unspecified, the default `tag` is used. See the documentation for `activateKeepAwake`
|
|
5
6
|
* below to learn more about the `tag` argument.
|
|
6
|
-
*
|
|
7
|
+
*
|
|
8
|
+
* @param tag *Optional* - Tag to lock screen sleep prevention. If not provided, the default tag is used.
|
|
9
|
+
* @param options *Optional*
|
|
10
|
+
* - `suppressDeactivateWarnings` *Optional* -
|
|
11
|
+
* The call will throw an unhandled promise rejection on Android
|
|
12
|
+
* when the original Activity is dead or deactivated.
|
|
13
|
+
* Set the value to true for suppressing the uncaught exception.
|
|
7
14
|
*/
|
|
8
|
-
export declare function useKeepAwake(tag?: string
|
|
15
|
+
export declare function useKeepAwake(tag?: string, options?: {
|
|
16
|
+
suppressDeactivateWarnings: boolean;
|
|
17
|
+
}): void;
|
|
9
18
|
/**
|
|
10
19
|
* Prevents the screen from sleeping until `deactivateKeepAwake` is called with the same `tag` value.
|
|
11
20
|
*
|
|
@@ -14,12 +23,12 @@ export declare function useKeepAwake(tag?: string): void;
|
|
|
14
23
|
* each one in order to re-enable screen sleep. If tag is unspecified, the default `tag` is used.
|
|
15
24
|
* @param tag *Optional* - Tag to lock screen sleep prevention. If not provided, the default tag is used.
|
|
16
25
|
*/
|
|
17
|
-
export declare function activateKeepAwake(tag?: string): void
|
|
26
|
+
export declare function activateKeepAwake(tag?: string): Promise<void>;
|
|
18
27
|
/**
|
|
19
28
|
* Releases the lock on screen-sleep prevention associated with the given `tag` value. If `tag`
|
|
20
29
|
* is unspecified, it defaults to the same default tag that `activateKeepAwake` uses.
|
|
21
30
|
* @param tag *Optional* - Tag to release the lock on screen sleep prevention. If not provided,
|
|
22
31
|
* the default tag is used.
|
|
23
32
|
*/
|
|
24
|
-
export declare function deactivateKeepAwake(tag?: string): void
|
|
33
|
+
export declare function deactivateKeepAwake(tag?: string): Promise<void>;
|
|
25
34
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,gBAAgB,4BAA4B,CAAC;AAG1D;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAC1B,GAAG,GAAE,MAAyB,EAC9B,OAAO,CAAC,EAAE;IACR,0BAA0B,EAAE,OAAO,CAAC;CACrC,GACA,IAAI,CAWN;AAGD;;;;;;;GAOG;AAEH,wBAAsB,iBAAiB,CAAC,GAAG,GAAE,MAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CAErF;AAGD;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,GAAG,GAAE,MAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvF"}
|
package/build/index.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import ExpoKeepAwake from './ExpoKeepAwake';
|
|
3
|
-
const ExpoKeepAwakeTag = 'ExpoKeepAwakeDefaultTag';
|
|
3
|
+
export const ExpoKeepAwakeTag = 'ExpoKeepAwakeDefaultTag';
|
|
4
4
|
// @needsAudit
|
|
5
5
|
/**
|
|
6
6
|
* A React hook to keep the screen awake for as long as the owner component is mounted.
|
|
7
7
|
* The optionally provided `tag` argument is used when activating and deactivating the keep-awake
|
|
8
8
|
* feature. If unspecified, the default `tag` is used. See the documentation for `activateKeepAwake`
|
|
9
9
|
* below to learn more about the `tag` argument.
|
|
10
|
-
*
|
|
10
|
+
*
|
|
11
|
+
* @param tag *Optional* - Tag to lock screen sleep prevention. If not provided, the default tag is used.
|
|
12
|
+
* @param options *Optional*
|
|
13
|
+
* - `suppressDeactivateWarnings` *Optional* -
|
|
14
|
+
* The call will throw an unhandled promise rejection on Android
|
|
15
|
+
* when the original Activity is dead or deactivated.
|
|
16
|
+
* Set the value to true for suppressing the uncaught exception.
|
|
11
17
|
*/
|
|
12
|
-
export function useKeepAwake(tag = ExpoKeepAwakeTag) {
|
|
18
|
+
export function useKeepAwake(tag = ExpoKeepAwakeTag, options) {
|
|
13
19
|
useEffect(() => {
|
|
14
20
|
activateKeepAwake(tag);
|
|
15
|
-
return () =>
|
|
21
|
+
return () => {
|
|
22
|
+
if (options?.suppressDeactivateWarnings) {
|
|
23
|
+
deactivateKeepAwake(tag).catch(() => { });
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
deactivateKeepAwake(tag);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
16
29
|
}, [tag]);
|
|
17
30
|
}
|
|
18
31
|
// @needsAudit
|
|
@@ -24,9 +37,8 @@ export function useKeepAwake(tag = ExpoKeepAwakeTag) {
|
|
|
24
37
|
* each one in order to re-enable screen sleep. If tag is unspecified, the default `tag` is used.
|
|
25
38
|
* @param tag *Optional* - Tag to lock screen sleep prevention. If not provided, the default tag is used.
|
|
26
39
|
*/
|
|
27
|
-
export function activateKeepAwake(tag = ExpoKeepAwakeTag) {
|
|
28
|
-
|
|
29
|
-
ExpoKeepAwake.activate(tag);
|
|
40
|
+
export async function activateKeepAwake(tag = ExpoKeepAwakeTag) {
|
|
41
|
+
await ExpoKeepAwake.activate?.(tag);
|
|
30
42
|
}
|
|
31
43
|
// @needsAudit
|
|
32
44
|
/**
|
|
@@ -35,8 +47,7 @@ export function activateKeepAwake(tag = ExpoKeepAwakeTag) {
|
|
|
35
47
|
* @param tag *Optional* - Tag to release the lock on screen sleep prevention. If not provided,
|
|
36
48
|
* the default tag is used.
|
|
37
49
|
*/
|
|
38
|
-
export function deactivateKeepAwake(tag = ExpoKeepAwakeTag) {
|
|
39
|
-
|
|
40
|
-
ExpoKeepAwake.deactivate(tag);
|
|
50
|
+
export async function deactivateKeepAwake(tag = ExpoKeepAwakeTag) {
|
|
51
|
+
await ExpoKeepAwake.deactivate?.(tag);
|
|
41
52
|
}
|
|
42
53
|
//# sourceMappingURL=index.js.map
|
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;
|
|
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,CAAC,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAE1D,cAAc;AACd;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAc,gBAAgB,EAC9B,OAEC;IAED,SAAS,CAAC,GAAG,EAAE;QACb,iBAAiB,CAAC,GAAG,CAAC,CAAC;QACvB,OAAO,GAAG,EAAE;YACV,IAAI,OAAO,EAAE,0BAA0B,EAAE;gBACvC,mBAAmB,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;aAC1C;iBAAM;gBACL,mBAAmB,CAAC,GAAG,CAAC,CAAC;aAC1B;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;AACZ,CAAC;AAED,cAAc;AACd;;;;;;;GAOG;AAEH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,MAAc,gBAAgB;IACpE,MAAM,aAAa,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC;AAED,cAAc;AACd;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,MAAc,gBAAgB;IACtE,MAAM,aAAa,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import { useEffect } from 'react';\n\nimport ExpoKeepAwake from './ExpoKeepAwake';\n\nexport const 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 *\n * @param tag *Optional* - Tag to lock screen sleep prevention. If not provided, the default tag is used.\n * @param options *Optional*\n * - `suppressDeactivateWarnings` *Optional* -\n * The call will throw an unhandled promise rejection on Android\n * when the original Activity is dead or deactivated.\n * Set the value to true for suppressing the uncaught exception.\n */\nexport function useKeepAwake(\n tag: string = ExpoKeepAwakeTag,\n options?: {\n suppressDeactivateWarnings: boolean;\n }\n): void {\n useEffect(() => {\n activateKeepAwake(tag);\n return () => {\n if (options?.suppressDeactivateWarnings) {\n deactivateKeepAwake(tag).catch(() => {});\n } else {\n deactivateKeepAwake(tag);\n }\n };\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 async function activateKeepAwake(tag: string = ExpoKeepAwakeTag): Promise<void> {\n await 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 async function deactivateKeepAwake(tag: string = ExpoKeepAwakeTag): Promise<void> {\n await ExpoKeepAwake.deactivate?.(tag);\n}\n"]}
|
|
@@ -6,44 +6,41 @@ public final class KeepAwakeModule: Module {
|
|
|
6
6
|
private var activeTags = Set<String>()
|
|
7
7
|
|
|
8
8
|
public func definition() -> ModuleDefinition {
|
|
9
|
-
|
|
9
|
+
Name("ExpoKeepAwake")
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function("isActivated", isActivated)
|
|
14
|
-
|
|
15
|
-
onAppEntersForeground {
|
|
16
|
-
if !self.activeTags.isEmpty {
|
|
11
|
+
AsyncFunction("activate") { (tag: String) -> Bool in
|
|
12
|
+
if self.activeTags.isEmpty {
|
|
17
13
|
setActivated(true)
|
|
18
14
|
}
|
|
15
|
+
self.activeTags.insert(tag)
|
|
16
|
+
return true
|
|
19
17
|
}
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
|
|
19
|
+
AsyncFunction("deactivate") { (tag: String) -> Bool in
|
|
20
|
+
self.activeTags.remove(tag)
|
|
21
|
+
if self.activeTags.isEmpty {
|
|
22
22
|
setActivated(false)
|
|
23
23
|
}
|
|
24
|
+
return true
|
|
24
25
|
}
|
|
25
|
-
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
AsyncFunction("isActivated") { () -> Bool in
|
|
28
|
+
return DispatchQueue.main.sync {
|
|
29
|
+
return UIApplication.shared.isIdleTimerDisabled
|
|
30
|
+
}
|
|
30
31
|
}
|
|
31
|
-
activeTags.insert(tag)
|
|
32
|
-
return true
|
|
33
|
-
}
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
OnAppEntersForeground {
|
|
34
|
+
if !self.activeTags.isEmpty {
|
|
35
|
+
setActivated(true)
|
|
36
|
+
}
|
|
39
37
|
}
|
|
40
|
-
return true
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
38
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
OnAppEntersBackground {
|
|
40
|
+
if !self.activeTags.isEmpty {
|
|
41
|
+
setActivated(false)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
46
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-keep-awake",
|
|
3
|
-
"version": "10.1
|
|
3
|
+
"version": "10.2.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",
|
|
@@ -33,10 +33,14 @@
|
|
|
33
33
|
"homepage": "https://docs.expo.dev/versions/latest/sdk/keep-awake/",
|
|
34
34
|
"dependencies": {},
|
|
35
35
|
"devDependencies": {
|
|
36
|
+
"@testing-library/react-hooks": "^7.0.1",
|
|
36
37
|
"expo-module-scripts": "^2.0.0"
|
|
37
38
|
},
|
|
38
39
|
"peerDependencies": {
|
|
39
40
|
"expo": "*"
|
|
40
41
|
},
|
|
41
|
-
"
|
|
42
|
+
"jest": {
|
|
43
|
+
"preset": "expo-module-scripts"
|
|
44
|
+
},
|
|
45
|
+
"gitHead": "38e4349fbebadadffe28bd8e800f527a7a2a50fa"
|
|
42
46
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { useEffect } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import ExpoKeepAwake from './ExpoKeepAwake';
|
|
4
4
|
|
|
5
|
-
const ExpoKeepAwakeTag = 'ExpoKeepAwakeDefaultTag';
|
|
5
|
+
export const ExpoKeepAwakeTag = 'ExpoKeepAwakeDefaultTag';
|
|
6
6
|
|
|
7
7
|
// @needsAudit
|
|
8
8
|
/**
|
|
@@ -10,12 +10,29 @@ const ExpoKeepAwakeTag = 'ExpoKeepAwakeDefaultTag';
|
|
|
10
10
|
* The optionally provided `tag` argument is used when activating and deactivating the keep-awake
|
|
11
11
|
* feature. If unspecified, the default `tag` is used. See the documentation for `activateKeepAwake`
|
|
12
12
|
* below to learn more about the `tag` argument.
|
|
13
|
-
*
|
|
13
|
+
*
|
|
14
|
+
* @param tag *Optional* - Tag to lock screen sleep prevention. If not provided, the default tag is used.
|
|
15
|
+
* @param options *Optional*
|
|
16
|
+
* - `suppressDeactivateWarnings` *Optional* -
|
|
17
|
+
* The call will throw an unhandled promise rejection on Android
|
|
18
|
+
* when the original Activity is dead or deactivated.
|
|
19
|
+
* Set the value to true for suppressing the uncaught exception.
|
|
14
20
|
*/
|
|
15
|
-
export function useKeepAwake(
|
|
21
|
+
export function useKeepAwake(
|
|
22
|
+
tag: string = ExpoKeepAwakeTag,
|
|
23
|
+
options?: {
|
|
24
|
+
suppressDeactivateWarnings: boolean;
|
|
25
|
+
}
|
|
26
|
+
): void {
|
|
16
27
|
useEffect(() => {
|
|
17
28
|
activateKeepAwake(tag);
|
|
18
|
-
return () =>
|
|
29
|
+
return () => {
|
|
30
|
+
if (options?.suppressDeactivateWarnings) {
|
|
31
|
+
deactivateKeepAwake(tag).catch(() => {});
|
|
32
|
+
} else {
|
|
33
|
+
deactivateKeepAwake(tag);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
19
36
|
}, [tag]);
|
|
20
37
|
}
|
|
21
38
|
|
|
@@ -29,8 +46,8 @@ export function useKeepAwake(tag: string = ExpoKeepAwakeTag): void {
|
|
|
29
46
|
* @param tag *Optional* - Tag to lock screen sleep prevention. If not provided, the default tag is used.
|
|
30
47
|
*/
|
|
31
48
|
|
|
32
|
-
export function activateKeepAwake(tag: string = ExpoKeepAwakeTag): void {
|
|
33
|
-
|
|
49
|
+
export async function activateKeepAwake(tag: string = ExpoKeepAwakeTag): Promise<void> {
|
|
50
|
+
await ExpoKeepAwake.activate?.(tag);
|
|
34
51
|
}
|
|
35
52
|
|
|
36
53
|
// @needsAudit
|
|
@@ -40,6 +57,6 @@ export function activateKeepAwake(tag: string = ExpoKeepAwakeTag): void {
|
|
|
40
57
|
* @param tag *Optional* - Tag to release the lock on screen sleep prevention. If not provided,
|
|
41
58
|
* the default tag is used.
|
|
42
59
|
*/
|
|
43
|
-
export function deactivateKeepAwake(tag: string = ExpoKeepAwakeTag): void {
|
|
44
|
-
|
|
60
|
+
export async function deactivateKeepAwake(tag: string = ExpoKeepAwakeTag): Promise<void> {
|
|
61
|
+
await ExpoKeepAwake.deactivate?.(tag);
|
|
45
62
|
}
|
package/tsconfig.json
CHANGED