expo-keep-awake 12.8.2 → 13.0.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,11 +10,17 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
- ## 12.8.2 — 2024-01-18
13
+ ## 13.0.0 — 2024-04-18
14
+
15
+ ### 💡 Others
16
+
17
+ - Removed deprecated backward compatible Gradle settings. ([#28083](https://github.com/expo/expo/pull/28083) by [@kudo](https://github.com/kudo))
18
+
19
+ ## 12.8.2 - 2024-01-18
14
20
 
15
21
  _This version does not introduce any user-facing changes._
16
22
 
17
- ## 12.8.1 2024-01-10
23
+ ## 12.8.1 - 2024-01-10
18
24
 
19
25
  ### 🎉 New features
20
26
 
@@ -1,107 +1,19 @@
1
1
  apply plugin: 'com.android.library'
2
- apply plugin: 'kotlin-android'
3
- apply plugin: 'maven-publish'
4
2
 
5
3
  group = 'host.exp.exponent'
6
- version = '12.8.2'
4
+ version = '13.0.0'
7
5
 
8
6
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
9
- if (expoModulesCorePlugin.exists()) {
10
- apply from: expoModulesCorePlugin
11
- applyKotlinExpoModulesCorePlugin()
12
- // Remove this check, but keep the contents after SDK49 support is dropped
13
- if (safeExtGet("expoProvidesDefaultConfig", false)) {
14
- useExpoPublishing()
15
- useCoreDependencies()
16
- }
17
- }
18
-
19
- buildscript {
20
- // Simple helper that allows the root project to override versions declared by this library.
21
- ext.safeExtGet = { prop, fallback ->
22
- rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
23
- }
24
-
25
- // Ensures backward compatibility
26
- ext.getKotlinVersion = {
27
- if (ext.has("kotlinVersion")) {
28
- ext.kotlinVersion()
29
- } else {
30
- ext.safeExtGet("kotlinVersion", "1.8.10")
31
- }
32
- }
33
-
34
- repositories {
35
- mavenCentral()
36
- }
37
-
38
- dependencies {
39
- classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
40
- }
41
- }
42
-
43
- // Remove this if and it's contents, when support for SDK49 is dropped
44
- if (!safeExtGet("expoProvidesDefaultConfig", false)) {
45
- afterEvaluate {
46
- publishing {
47
- publications {
48
- release(MavenPublication) {
49
- from components.release
50
- }
51
- }
52
- repositories {
53
- maven {
54
- url = mavenLocal().url
55
- }
56
- }
57
- }
58
- }
59
- }
7
+ apply from: expoModulesCorePlugin
8
+ applyKotlinExpoModulesCorePlugin()
9
+ useCoreDependencies()
10
+ useDefaultAndroidSdkVersions()
11
+ useExpoPublishing()
60
12
 
61
13
  android {
62
- // Remove this if and it's contents, when support for SDK49 is dropped
63
- if (!safeExtGet("expoProvidesDefaultConfig", false)) {
64
- compileSdkVersion safeExtGet("compileSdkVersion", 34)
65
-
66
- defaultConfig {
67
- minSdkVersion safeExtGet("minSdkVersion", 23)
68
- targetSdkVersion safeExtGet("targetSdkVersion", 34)
69
- }
70
-
71
- publishing {
72
- singleVariant("release") {
73
- withSourcesJar()
74
- }
75
- }
76
-
77
- lintOptions {
78
- abortOnError false
79
- }
80
- }
81
-
82
- def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
83
- if (agpVersion.tokenize('.')[0].toInteger() < 8) {
84
- compileOptions {
85
- sourceCompatibility JavaVersion.VERSION_11
86
- targetCompatibility JavaVersion.VERSION_11
87
- }
88
-
89
- kotlinOptions {
90
- jvmTarget = JavaVersion.VERSION_11.majorVersion
91
- }
92
- }
93
-
94
14
  namespace "expo.modules.keepawake"
95
15
  defaultConfig {
96
16
  versionCode 16
97
- versionName "12.8.2"
98
- }
99
- }
100
-
101
- dependencies {
102
- // Remove this if and it's contents, when support for SDK49 is dropped
103
- if (!safeExtGet("expoProvidesDefaultConfig", false)) {
104
- implementation project(':expo-modules-core')
105
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
17
+ versionName "13.0.0"
106
18
  }
107
19
  }
@@ -2,29 +2,26 @@ package expo.modules.keepawake
2
2
 
3
3
  import android.app.Activity
4
4
  import android.view.WindowManager
5
-
6
- import expo.modules.core.interfaces.services.KeepAwakeManager
7
- import expo.modules.core.interfaces.InternalModule
8
5
  import expo.modules.core.ModuleRegistry
9
- import expo.modules.core.ModuleRegistryDelegate
10
6
  import expo.modules.core.errors.CurrentActivityNotFoundException
11
7
  import expo.modules.core.interfaces.ActivityProvider
8
+ import expo.modules.core.interfaces.InternalModule
9
+ import expo.modules.core.interfaces.services.KeepAwakeManager
12
10
 
13
- import java.util.HashSet
14
-
15
- class ExpoKeepAwakeManager(private val moduleRegistryDelegate: ModuleRegistryDelegate = ModuleRegistryDelegate()) : KeepAwakeManager, InternalModule {
11
+ class ExpoKeepAwakeManager : KeepAwakeManager, InternalModule {
16
12
  private val tags: MutableSet<String> = HashSet()
17
13
 
18
- private inline fun <reified T> moduleRegistry() = moduleRegistryDelegate.getFromModuleRegistry<T>()
14
+ private lateinit var moduleRegistry: ModuleRegistry
19
15
 
20
16
  override fun onCreate(moduleRegistry: ModuleRegistry) {
21
- moduleRegistryDelegate.onCreate(moduleRegistry)
17
+ this.moduleRegistry = moduleRegistry
22
18
  }
23
19
 
24
20
  @get:Throws(CurrentActivityNotFoundException::class)
25
21
  private val currentActivity: Activity
26
22
  get() {
27
- val activityProvider: ActivityProvider by moduleRegistry()
23
+ val activityProvider = moduleRegistry.getModule(ActivityProvider::class.java)
24
+ ?: throw CurrentActivityNotFoundException()
28
25
  return if (activityProvider.currentActivity != null) {
29
26
  activityProvider.currentActivity
30
27
  } else {
@@ -30,7 +30,7 @@ class KeepAwakeModule : Module() {
30
30
  }
31
31
  }
32
32
 
33
- AsyncFunction("isActivated") {
33
+ AsyncFunction<Boolean>("isActivated") {
34
34
  return@AsyncFunction keepAwakeManager.isActivated
35
35
  }
36
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoKeepAwake.web.js","sourceRoot":"","sources":["../src/ExpoKe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EAAE;gBAClC,QAAQ,CAAC,gBAAgB,EAAE,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;aACvD;iBAAM;gBACL,QAAQ,CAAC,SAAS,GAAG,aAAa,CAAC;aACpC;SACF;QACD,OAAO;YACL,MAAM,EAAE,GAAG,EAAE;gBACX,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;gBAClC,IAAI,QAAQ,EAAE;oBACZ,IAAI,QAAQ,CAAC,mBAAmB,EAAE;wBAChC,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;qBACxD;yBAAM;wBACL,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC;qBAC3B;iBACF;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import { CodedError, Platform, Subscription } from 'expo-modules-core';\n\nimport { KeepAwakeEventState, KeepAwakeListener } from './KeepAwake.types';\n\nconst wakeLockMap: Record<string, WakeLockSentinel> = {};\n\ntype WakeLockSentinel = {\n onrelease: null | ((event: any) => void);\n released: boolean;\n type: 'screen';\n release?: Function;\n\n addEventListener?: (event: string, listener: (event: any) => void) => void;\n removeEventListener?: (event: string, listener: (event: any) => void) => void;\n};\n\ndeclare const navigator: {\n wakeLock: {\n request(type: 'screen'): Promise<WakeLockSentinel>;\n };\n};\n\n/** Wraps the webWakeLock API https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API */\nexport default {\n async isAvailableAsync() {\n if (Platform.isDOMAvailable) {\n return 'wakeLock' in navigator;\n }\n return false;\n },\n async activate(tag: string) {\n if (!Platform.isDOMAvailable) {\n return;\n }\n const wakeLock = await navigator.wakeLock.request('screen');\n wakeLockMap[tag] = wakeLock;\n },\n async deactivate(tag: string) {\n if (!Platform.isDOMAvailable) {\n return;\n }\n if (wakeLockMap[tag]) {\n wakeLockMap[tag].release?.();\n delete wakeLockMap[tag];\n } else {\n throw new CodedError(\n 'ERR_KEEP_AWAKE_TAG_INVALID',\n `The wake lock with tag ${tag} has not activated yet`\n );\n }\n },\n addListenerForTag(tag: string, listener: KeepAwakeListener): Subscription {\n const eventListener = () => {\n listener({ state: KeepAwakeEventState.RELEASE });\n };\n const sentinel = wakeLockMap[tag];\n if (sentinel) {\n if ('addEventListener' in sentinel) {\n sentinel.addEventListener?.('release', eventListener);\n } else {\n sentinel.onrelease = eventListener;\n }\n }\n return {\n remove: () => {\n const sentinel = wakeLockMap[tag];\n if (sentinel) {\n if (sentinel.removeEventListener) {\n sentinel.removeEventListener('release', eventListener);\n } else {\n sentinel.onrelease = null;\n }\n }\n },\n };\n },\n};\n"]}
1
+ {"version":3,"file":"ExpoKeepAwake.web.js","sourceRoot":"","sources":["../src/ExpoKeepAwake.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAgB,MAAM,mBAAmB,CAAC;AAEvE,OAAO,EAAE,mBAAmB,EAAqB,MAAM,mBAAmB,CAAC;AAE3E,MAAM,WAAW,GAAqC,EAAE,CAAC;AAkBzD,sGAAsG;AACtG,eAAe;IACb,KAAK,CAAC,gBAAgB;QACpB,IAAI,QAAQ,CAAC,cAAc,EAAE,CAAC;YAC5B,OAAO,UAAU,IAAI,SAAS,CAAC;QACjC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,KAAK,CAAC,QAAQ,CAAC,GAAW;QACxB,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;YAC7B,OAAO;QACT,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC5D,WAAW,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;IAC9B,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,GAAW;QAC1B,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;YAC7B,OAAO;QACT,CAAC;QACD,IAAI,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;YACrB,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;YAC7B,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,UAAU,CAClB,4BAA4B,EAC5B,0BAA0B,GAAG,wBAAwB,CACtD,CAAC;QACJ,CAAC;IACH,CAAC;IACD,iBAAiB,CAAC,GAAW,EAAE,QAA2B;QACxD,MAAM,aAAa,GAAG,GAAG,EAAE;YACzB,QAAQ,CAAC,EAAE,KAAK,EAAE,mBAAmB,CAAC,OAAO,EAAE,CAAC,CAAC;QACnD,CAAC,CAAC;QACF,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,kBAAkB,IAAI,QAAQ,EAAE,CAAC;gBACnC,QAAQ,CAAC,gBAAgB,EAAE,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;YACxD,CAAC;iBAAM,CAAC;gBACN,QAAQ,CAAC,SAAS,GAAG,aAAa,CAAC;YACrC,CAAC;QACH,CAAC;QACD,OAAO;YACL,MAAM,EAAE,GAAG,EAAE;gBACX,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;gBAClC,IAAI,QAAQ,EAAE,CAAC;oBACb,IAAI,QAAQ,CAAC,mBAAmB,EAAE,CAAC;wBACjC,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;oBACzD,CAAC;yBAAM,CAAC;wBACN,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC;oBAC5B,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import { CodedError, Platform, Subscription } from 'expo-modules-core';\n\nimport { KeepAwakeEventState, KeepAwakeListener } from './KeepAwake.types';\n\nconst wakeLockMap: Record<string, WakeLockSentinel> = {};\n\ntype WakeLockSentinel = {\n onrelease: null | ((event: any) => void);\n released: boolean;\n type: 'screen';\n release?: Function;\n\n addEventListener?: (event: string, listener: (event: any) => void) => void;\n removeEventListener?: (event: string, listener: (event: any) => void) => void;\n};\n\ndeclare const navigator: {\n wakeLock: {\n request(type: 'screen'): Promise<WakeLockSentinel>;\n };\n};\n\n/** Wraps the webWakeLock API https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API */\nexport default {\n async isAvailableAsync() {\n if (Platform.isDOMAvailable) {\n return 'wakeLock' in navigator;\n }\n return false;\n },\n async activate(tag: string) {\n if (!Platform.isDOMAvailable) {\n return;\n }\n const wakeLock = await navigator.wakeLock.request('screen');\n wakeLockMap[tag] = wakeLock;\n },\n async deactivate(tag: string) {\n if (!Platform.isDOMAvailable) {\n return;\n }\n if (wakeLockMap[tag]) {\n wakeLockMap[tag].release?.();\n delete wakeLockMap[tag];\n } else {\n throw new CodedError(\n 'ERR_KEEP_AWAKE_TAG_INVALID',\n `The wake lock with tag ${tag} has not activated yet`\n );\n }\n },\n addListenerForTag(tag: string, listener: KeepAwakeListener): Subscription {\n const eventListener = () => {\n listener({ state: KeepAwakeEventState.RELEASE });\n };\n const sentinel = wakeLockMap[tag];\n if (sentinel) {\n if ('addEventListener' in sentinel) {\n sentinel.addEventListener?.('release', eventListener);\n } else {\n sentinel.onrelease = eventListener;\n }\n }\n return {\n remove: () => {\n const sentinel = wakeLockMap[tag];\n if (sentinel) {\n if (sentinel.removeEventListener) {\n sentinel.removeEventListener('release', eventListener);\n } else {\n sentinel.onrelease = null;\n }\n }\n },\n };\n },\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAG5C,mFAAmF;AACnF,MAAM,CAAC,MA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AC,CAAC;AACtC,CAAC;AAED,cAAc;AACd;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,MAAc,gBAAgB;IACtE,MAAM,aAAa,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CACzB,aAAyC,EACzC,QAA4B;IAE5B,sCAAsC;IACtC,IAAI,CAAC,aAAa,CAAC,iBAAiB,EAAE;QACpC,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAAC;KACrE;IAED,MAAM,GAAG,GAAG,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,gBAAgB,CAAC;IACjF,MAAM,SAAS,GAAG,OAAO,aAAa,KAAK,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC;IAEjF,OAAO,aAAa,CAAC,iBAAiB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;AACzD,CAAC;AAED,cAAc,mBAAmB,CAAC","sourcesContent":["import { Subscription, UnavailabilityError } from 'expo-modules-core';\nimport { useEffect } from 'react';\n\nimport ExpoKeepAwake from './ExpoKeepAwake';\nimport { KeepAwakeListener, KeepAwakeOptions } from './KeepAwake.types';\n\n/** Default tag, used when no tag has been specified in keep awake method calls. */\nexport const ExpoKeepAwakeTag = 'ExpoKeepAwakeDefaultTag';\n\n/** @returns `true` on all platforms except [unsupported web browsers](https://caniuse.com/wake-lock). */\nexport async function isAvailableAsync(): Promise<boolean> {\n if (ExpoKeepAwake.isAvailableAsync) {\n return await ExpoKeepAwake.isAvailableAsync();\n }\n return true;\n}\n\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 `activateKeepAwakeAsync`\n * below to learn more about the `tag` argument.\n *\n * @param tag Tag to lock screen sleep prevention. If not provided, the default tag is used.\n * @param options Additional options for the keep awake hook.\n */\nexport function useKeepAwake(tag: string = ExpoKeepAwakeTag, options?: KeepAwakeOptions): void {\n useEffect(() => {\n let isMounted = true;\n activateKeepAwakeAsync(tag).then(() => {\n if (isMounted && ExpoKeepAwake.addListenerForTag && options?.listener) {\n addListener(tag, options.listener);\n }\n });\n return () => {\n isMounted = false;\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 *\n * Web support [is limited](https://caniuse.com/wake-lock).\n *\n * @param tag Tag to lock screen sleep prevention. If not provided, the default tag is used.\n * @deprecated use `activateKeepAwakeAsync` instead.\n */\nexport function activateKeepAwake(tag: string = ExpoKeepAwakeTag): Promise<void> {\n console.warn('`activateKeepAwake` is deprecated. Use `activateKeepAwakeAsync` instead.');\n return activateKeepAwakeAsync(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 *\n * Web support [is limited](https://caniuse.com/wake-lock).\n *\n * @param tag Tag to lock screen sleep prevention. If not provided, the default tag is used.\n */\nexport async function activateKeepAwakeAsync(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 *\n * @param tag 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\n/**\n * Observe changes to the keep awake timer.\n * On web, this changes when navigating away from the active window/tab. No-op on native.\n * @platform web\n *\n * @example\n * ```ts\n * KeepAwake.addListener(({ state }) => {\n * // ...\n * });\n * ```\n */\nexport function addListener(\n tagOrListener: string | KeepAwakeListener,\n listener?: KeepAwakeListener\n): Subscription {\n // Assert so the type is non-nullable.\n if (!ExpoKeepAwake.addListenerForTag) {\n throw new UnavailabilityError('ExpoKeepAwake', 'addListenerForTag');\n }\n\n const tag = typeof tagOrListener === 'string' ? tagOrListener : ExpoKeepAwakeTag;\n const _listener = typeof tagOrListener === 'function' ? tagOrListener : listener;\n\n return ExpoKeepAwake.addListenerForTag(tag, _listener);\n}\n\nexport * from './KeepAwake.types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAG5C,mFAAmF;AACnF,MAAM,CAAC,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAE1D,yGAAyG;AACzG,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,aAAa,CAAC,gBAAgB,EAAE,CAAC;QACnC,OAAO,MAAM,aAAa,CAAC,gBAAgB,EAAE,CAAC;IAChD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc,gBAAgB,EAAE,OAA0B;IACrF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,GAAG,IAAI,CAAC;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C,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAAC;IACtE,CAAC;IAED,MAAM,GAAG,GAAG,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,gBAAgB,CAAC;IACjF,MAAM,SAAS,GAAG,OAAO,aAAa,KAAK,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC;IAEjF,OAAO,aAAa,CAAC,iBAAiB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;AACzD,CAAC;AAED,cAAc,mBAAmB,CAAC","sourcesContent":["import { Subscription, UnavailabilityError } from 'expo-modules-core';\nimport { useEffect } from 'react';\n\nimport ExpoKeepAwake from './ExpoKeepAwake';\nimport { KeepAwakeListener, KeepAwakeOptions } from './KeepAwake.types';\n\n/** Default tag, used when no tag has been specified in keep awake method calls. */\nexport const ExpoKeepAwakeTag = 'ExpoKeepAwakeDefaultTag';\n\n/** @returns `true` on all platforms except [unsupported web browsers](https://caniuse.com/wake-lock). */\nexport async function isAvailableAsync(): Promise<boolean> {\n if (ExpoKeepAwake.isAvailableAsync) {\n return await ExpoKeepAwake.isAvailableAsync();\n }\n return true;\n}\n\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 `activateKeepAwakeAsync`\n * below to learn more about the `tag` argument.\n *\n * @param tag Tag to lock screen sleep prevention. If not provided, the default tag is used.\n * @param options Additional options for the keep awake hook.\n */\nexport function useKeepAwake(tag: string = ExpoKeepAwakeTag, options?: KeepAwakeOptions): void {\n useEffect(() => {\n let isMounted = true;\n activateKeepAwakeAsync(tag).then(() => {\n if (isMounted && ExpoKeepAwake.addListenerForTag && options?.listener) {\n addListener(tag, options.listener);\n }\n });\n return () => {\n isMounted = false;\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 *\n * Web support [is limited](https://caniuse.com/wake-lock).\n *\n * @param tag Tag to lock screen sleep prevention. If not provided, the default tag is used.\n * @deprecated use `activateKeepAwakeAsync` instead.\n */\nexport function activateKeepAwake(tag: string = ExpoKeepAwakeTag): Promise<void> {\n console.warn('`activateKeepAwake` is deprecated. Use `activateKeepAwakeAsync` instead.');\n return activateKeepAwakeAsync(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 *\n * Web support [is limited](https://caniuse.com/wake-lock).\n *\n * @param tag Tag to lock screen sleep prevention. If not provided, the default tag is used.\n */\nexport async function activateKeepAwakeAsync(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 *\n * @param tag 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\n/**\n * Observe changes to the keep awake timer.\n * On web, this changes when navigating away from the active window/tab. No-op on native.\n * @platform web\n *\n * @example\n * ```ts\n * KeepAwake.addListener(({ state }) => {\n * // ...\n * });\n * ```\n */\nexport function addListener(\n tagOrListener: string | KeepAwakeListener,\n listener?: KeepAwakeListener\n): Subscription {\n // Assert so the type is non-nullable.\n if (!ExpoKeepAwake.addListenerForTag) {\n throw new UnavailabilityError('ExpoKeepAwake', 'addListenerForTag');\n }\n\n const tag = typeof tagOrListener === 'string' ? tagOrListener : ExpoKeepAwakeTag;\n const _listener = typeof tagOrListener === 'function' ? tagOrListener : listener;\n\n return ExpoKeepAwake.addListenerForTag(tag, _listener);\n}\n\nexport * from './KeepAwake.types';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-keep-awake",
3
- "version": "12.8.2",
3
+ "version": "13.0.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",
@@ -42,5 +42,5 @@
42
42
  "jest": {
43
43
  "preset": "expo-module-scripts"
44
44
  },
45
- "gitHead": "102899632731658eecba006c0d1c79b98ba8f5f7"
45
+ "gitHead": "4165b8d72e1b9a1889c2767534cc619e21468110"
46
46
  }