expo-keep-awake 10.0.2 → 10.2.0

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 CHANGED
@@ -10,7 +10,27 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
- ## 10.0.2 — 2022-02-01
13
+ ## 10.2.0 — 2022-07-07
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - 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))
18
+
19
+ ### 💡 Others
20
+
21
+ - Migrated Expo modules definitions to the new naming convention. ([#17193](https://github.com/expo/expo/pull/17193) by [@tsapeta](https://github.com/tsapeta))
22
+
23
+ ## 10.1.0 — 2022-04-18
24
+
25
+ ### 🎉 New features
26
+
27
+ - Native module on iOS is now written in Swift using the new API. ([#15705](https://github.com/expo/expo/pull/15705) by [@tsapeta](https://github.com/tsapeta))
28
+
29
+ ### ⚠️ Notices
30
+
31
+ - On Android bump `compileSdkVersion` to `31`, `targetSdkVersion` to `31` and `Java` version to `11`. ([#16941](https://github.com/expo/expo/pull/16941) by [@bbarthec](https://github.com/bbarthec))
32
+
33
+ ## 10.0.2 - 2022-02-01
14
34
 
15
35
  ### 🐛 Bug fixes
16
36
 
package/README.md CHANGED
@@ -4,12 +4,12 @@ Provides a React component that prevents the screen sleeping when rendered. It a
4
4
 
5
5
  # API documentation
6
6
 
7
- - [Documentation for the master branch](https://github.com/expo/expo/blob/master/docs/pages/versions/unversioned/sdk/keep-awake.md)
8
- - [Documentation for the latest stable release](https://docs.expo.io/versions/latest/sdk/keep-awake/)
7
+ - [Documentation for the main branch](https://github.com/expo/expo/blob/main/docs/pages/versions/unversioned/sdk/keep-awake.md)
8
+ - [Documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/keep-awake/)
9
9
 
10
10
  # Installation in managed Expo projects
11
11
 
12
- For managed [managed](https://docs.expo.io/versions/latest/introduction/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.io/versions/latest/sdk/keep-awake/).
12
+ For [managed](https://docs.expo.dev/versions/latest/introduction/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/keep-awake/).
13
13
 
14
14
  # Installation in bare React Native projects
15
15
 
@@ -3,20 +3,35 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '10.0.2'
6
+ version = '10.2.0'
7
7
 
8
8
  buildscript {
9
+ def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
10
+ if (expoModulesCorePlugin.exists()) {
11
+ apply from: expoModulesCorePlugin
12
+ applyKotlinExpoModulesCorePlugin()
13
+ }
14
+
9
15
  // Simple helper that allows the root project to override versions declared by this library.
10
16
  ext.safeExtGet = { prop, fallback ->
11
17
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
12
18
  }
13
19
 
20
+ // Ensures backward compatibility
21
+ ext.getKotlinVersion = {
22
+ if (ext.has("kotlinVersion")) {
23
+ ext.kotlinVersion()
24
+ } else {
25
+ ext.safeExtGet("kotlinVersion", "1.6.10")
26
+ }
27
+ }
28
+
14
29
  repositories {
15
30
  mavenCentral()
16
31
  }
17
32
 
18
33
  dependencies {
19
- classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', '1.4.21')}")
34
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
20
35
  }
21
36
  }
22
37
 
@@ -44,22 +59,22 @@ afterEvaluate {
44
59
  }
45
60
 
46
61
  android {
47
- compileSdkVersion safeExtGet("compileSdkVersion", 30)
62
+ compileSdkVersion safeExtGet("compileSdkVersion", 31)
48
63
 
49
64
  compileOptions {
50
- sourceCompatibility JavaVersion.VERSION_1_8
51
- targetCompatibility JavaVersion.VERSION_1_8
65
+ sourceCompatibility JavaVersion.VERSION_11
66
+ targetCompatibility JavaVersion.VERSION_11
52
67
  }
53
68
 
54
69
  kotlinOptions {
55
- jvmTarget = "1.8"
70
+ jvmTarget = JavaVersion.VERSION_11.majorVersion
56
71
  }
57
72
 
58
73
  defaultConfig {
59
74
  minSdkVersion safeExtGet("minSdkVersion", 21)
60
- targetSdkVersion safeExtGet("targetSdkVersion", 30)
75
+ targetSdkVersion safeExtGet("targetSdkVersion", 31)
61
76
  versionCode 16
62
- versionName "10.0.2"
77
+ versionName "10.2.0"
63
78
  }
64
79
  lintOptions {
65
80
  abortOnError false
@@ -69,5 +84,5 @@ android {
69
84
  dependencies {
70
85
  implementation project(':expo-modules-core')
71
86
 
72
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${safeExtGet('kotlinVersion', '1.4.21')}"
87
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
73
88
  }
@@ -1,2 +1,3 @@
1
1
  declare const _default: import("expo-modules-core").ProxyNativeModule;
2
2
  export default _default;
3
+ //# sourceMappingURL=ExpoKeepAwake.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoKeepAwake.d.ts","sourceRoot":"","sources":["../src/ExpoKeepAwake.ts"],"names":[],"mappings":";AACA,wBAAgD"}
@@ -1,2 +1,3 @@
1
1
  declare const _default: {};
2
2
  export default _default;
3
+ //# sourceMappingURL=ExpoKeepAwake.web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoKeepAwake.web.d.ts","sourceRoot":"","sources":["../src/ExpoKeepAwake.web.ts"],"names":[],"mappings":";AAAA,wBAAkB"}
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
- * @param tag *Optional*
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): void;
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,11 +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>;
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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
- * @param tag *Optional*
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 () => deactivateKeepAwake(tag);
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
- if (ExpoKeepAwake.activate)
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
- if (ExpoKeepAwake.deactivate)
40
- ExpoKeepAwake.deactivate(tag);
50
+ export async function deactivateKeepAwake(tag = ExpoKeepAwakeTag) {
51
+ await ExpoKeepAwake.deactivate?.(tag);
41
52
  }
42
53
  //# sourceMappingURL=index.js.map
@@ -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,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
+ {"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"]}
@@ -0,0 +1,6 @@
1
+ {
2
+ "platforms": ["ios", "android"],
3
+ "ios": {
4
+ "modulesClassNames": ["KeepAwakeModule"]
5
+ }
6
+ }
@@ -3,7 +3,7 @@ require 'json'
3
3
  package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
4
4
 
5
5
  Pod::Spec.new do |s|
6
- s.name = 'EXKeepAwake'
6
+ s.name = 'ExpoKeepAwake'
7
7
  s.version = package['version']
8
8
  s.summary = package['description']
9
9
  s.description = package['description']
@@ -11,15 +11,22 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.homepage = package['homepage']
13
13
  s.platform = :ios, '12.0'
14
+ s.swift_version = '5.4'
14
15
  s.source = { git: 'https://github.com/expo/expo.git' }
15
16
  s.static_framework = true
16
17
 
17
18
  s.dependency 'ExpoModulesCore'
18
19
 
20
+ # Swift/Objective-C compatibility
21
+ s.pod_target_xcconfig = {
22
+ 'DEFINES_MODULE' => 'YES',
23
+ 'SWIFT_COMPILATION_MODE' => 'wholemodule'
24
+ }
25
+
19
26
  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')
20
- s.source_files = "#{s.name}/**/*.h"
27
+ s.source_files = "**/*.h"
21
28
  s.vendored_frameworks = "#{s.name}.xcframework"
22
29
  else
23
- s.source_files = "#{s.name}/**/*.{h,m}"
30
+ s.source_files = "**/*.{h,m,swift}"
24
31
  end
25
32
  end
@@ -0,0 +1,54 @@
1
+ // Copyright 2021-present 650 Industries. All rights reserved.
2
+
3
+ import ExpoModulesCore
4
+
5
+ public final class KeepAwakeModule: Module {
6
+ private var activeTags = Set<String>()
7
+
8
+ public func definition() -> ModuleDefinition {
9
+ Name("ExpoKeepAwake")
10
+
11
+ AsyncFunction("activate", activate)
12
+ AsyncFunction("deactivate", deactivate)
13
+ AsyncFunction("isActivated", isActivated)
14
+
15
+ OnAppEntersForeground {
16
+ if !self.activeTags.isEmpty {
17
+ setActivated(true)
18
+ }
19
+ }
20
+ OnAppEntersBackground {
21
+ if !self.activeTags.isEmpty {
22
+ setActivated(false)
23
+ }
24
+ }
25
+ }
26
+
27
+ private func activate(tag: String) -> Bool {
28
+ if activeTags.isEmpty {
29
+ setActivated(true)
30
+ }
31
+ activeTags.insert(tag)
32
+ return true
33
+ }
34
+
35
+ private func deactivate(tag: String) -> Bool {
36
+ activeTags.remove(tag)
37
+ if activeTags.isEmpty {
38
+ setActivated(false)
39
+ }
40
+ return true
41
+ }
42
+ }
43
+
44
+ private func isActivated() -> Bool {
45
+ return DispatchQueue.main.sync {
46
+ return UIApplication.shared.isIdleTimerDisabled
47
+ }
48
+ }
49
+
50
+ private func setActivated(_ activated: Bool) {
51
+ DispatchQueue.main.async {
52
+ UIApplication.shared.isIdleTimerDisabled = activated
53
+ }
54
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-keep-awake",
3
- "version": "10.0.2",
3
+ "version": "10.2.0",
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
- "gitHead": "ba24eba18bf4f4d4b0d54828992d81a2bb18246a"
42
+ "jest": {
43
+ "preset": "expo-module-scripts"
44
+ },
45
+ "gitHead": "e893ff2b01e108cf246cec02318c0df9d6bc603c"
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
- * @param tag *Optional*
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(tag: string = ExpoKeepAwakeTag): void {
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 () => deactivateKeepAwake(tag);
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
- if (ExpoKeepAwake.activate) ExpoKeepAwake.activate(tag);
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
- if (ExpoKeepAwake.deactivate) ExpoKeepAwake.deactivate(tag);
60
+ export async function deactivateKeepAwake(tag: string = ExpoKeepAwakeTag): Promise<void> {
61
+ await ExpoKeepAwake.deactivate?.(tag);
45
62
  }
package/tsconfig.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "outDir": "./build"
6
6
  },
7
7
  "include": ["./src"],
8
- "exclude": ["**/__mocks__/*", "**/__tests__/*"]
8
+ "exclude": ["**/__mocks__/*", "**/__tests__/*", "**/__stories__/*"]
9
9
  }
@@ -1,7 +0,0 @@
1
- // Copyright 2018-present 650 Industries. All rights reserved.
2
-
3
- #import <ExpoModulesCore/EXExportedModule.h>
4
- #import <ExpoModulesCore/EXModuleRegistryConsumer.h>
5
-
6
- @interface EXKeepAwake : EXExportedModule <EXModuleRegistryConsumer>
7
- @end
@@ -1,92 +0,0 @@
1
- // Copyright 2018-present 650 Industries. All rights reserved.
2
-
3
- #import <ExpoModulesCore/EXModuleRegistry.h>
4
- #import <EXKeepAwake/EXKeepAwake.h>
5
- #import <ExpoModulesCore/EXAppLifecycleService.h>
6
- #import <ExpoModulesCore/EXUtilities.h>
7
-
8
- @interface EXKeepAwake () <EXAppLifecycleListener>
9
-
10
- @property (nonatomic, weak) id<EXAppLifecycleService> lifecycleManager;
11
- @property (nonatomic, weak) EXModuleRegistry *moduleRegistry;
12
-
13
- @end
14
-
15
- @implementation EXKeepAwake {
16
- NSMutableSet *_activeTags;
17
- }
18
-
19
- - (instancetype)init {
20
- self = [super init];
21
- _activeTags = [NSMutableSet set];
22
- return self;
23
- }
24
-
25
- EX_EXPORT_MODULE(ExpoKeepAwake);
26
-
27
- # pragma mark - EXModuleRegistryConsumer
28
-
29
- - (void)setModuleRegistry:(EXModuleRegistry *)moduleRegistry
30
- {
31
- if (_moduleRegistry) {
32
- [_lifecycleManager unregisterAppLifecycleListener:self];
33
- }
34
-
35
- _lifecycleManager = nil;
36
-
37
- if (moduleRegistry) {
38
- _lifecycleManager = [moduleRegistry getModuleImplementingProtocol:@protocol(EXAppLifecycleService)];
39
- }
40
-
41
- if (_lifecycleManager) {
42
- [_lifecycleManager registerAppLifecycleListener:self];
43
- }
44
- }
45
-
46
- EX_EXPORT_METHOD_AS(activate, activate:(NSString *)tag
47
- resolve:(EXPromiseResolveBlock)resolve
48
- reject:(EXPromiseRejectBlock)reject)
49
- {
50
- if(![self shouldBeActive]) {
51
- [EXUtilities performSynchronouslyOnMainThread:^{
52
- [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
53
- }];
54
- }
55
- [_activeTags addObject:tag];
56
- resolve(@YES);
57
- }
58
-
59
- EX_EXPORT_METHOD_AS(deactivate, deactivate:(NSString *)tag
60
- resolve:(EXPromiseResolveBlock)resolve
61
- reject:(EXPromiseRejectBlock)reject)
62
- {
63
- [_activeTags removeObject:tag];
64
- if (![self shouldBeActive]) {
65
- [EXUtilities performSynchronouslyOnMainThread:^{
66
- [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
67
- }];
68
- }
69
- resolve(@YES);
70
- }
71
-
72
- # pragma mark - EXAppLifecycleListener
73
-
74
- - (void)onAppBackgrounded {
75
- [EXUtilities performSynchronouslyOnMainThread:^{
76
- [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
77
- }];
78
- }
79
-
80
- - (void)onAppForegrounded {
81
- if ([self shouldBeActive]) {
82
- [EXUtilities performSynchronouslyOnMainThread:^{
83
- [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
84
- }];
85
- }
86
- }
87
-
88
- - (BOOL)shouldBeActive {
89
- return [_activeTags count] > 0;
90
- }
91
-
92
- @end
package/unimodule.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "name": "expo-keep-awake",
3
- "platforms": ["ios", "android"]
4
- }