expo-keep-awake 13.0.0 → 13.0.2

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,6 +10,16 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 13.0.2 — 2024-05-15
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - Stop useKeepAwake calls deactivating each other by default. ([#28884](https://github.com/expo/expo/pull/28884) by [@macksal](https://github.com/macksal))
18
+
19
+ ## 13.0.1 — 2024-04-23
20
+
21
+ _This version does not introduce any user-facing changes._
22
+
13
23
  ## 13.0.0 — 2024-04-18
14
24
 
15
25
  ### 💡 Others
@@ -1,7 +1,7 @@
1
1
  apply plugin: 'com.android.library'
2
2
 
3
3
  group = 'host.exp.exponent'
4
- version = '13.0.0'
4
+ version = '13.0.2'
5
5
 
6
6
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
7
7
  apply from: expoModulesCorePlugin
@@ -14,6 +14,6 @@ android {
14
14
  namespace "expo.modules.keepawake"
15
15
  defaultConfig {
16
16
  versionCode 16
17
- versionName "13.0.0"
17
+ versionName "13.0.2"
18
18
  }
19
19
  }
@@ -1 +1 @@
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,KAA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,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
+ {"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;YAC3B,OAAO,UAAU,IAAI,SAAS,CAAC;SAChC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,KAAK,CAAC,QAAQ,CAAC,GAAW;QACxB,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE;YAC5B,OAAO;SACR;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;YAC5B,OAAO;SACR;QACD,IAAI,WAAW,CAAC,GAAG,CAAC,EAAE;YACpB,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;YAC7B,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;SACzB;aAAM;YACL,MAAM,IAAI,UAAU,CAClB,4BAA4B,EAC5B,0BAA0B,GAAG,wBAAwB,CACtD,CAAC;SACH;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;YACZ,IAAI,kBAAkB,IAAI,QAAQ,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"]}
package/build/index.d.ts CHANGED
@@ -7,10 +7,10 @@ export declare function isAvailableAsync(): Promise<boolean>;
7
7
  /**
8
8
  * A React hook to keep the screen awake for as long as the owner component is mounted.
9
9
  * The optionally provided `tag` argument is used when activating and deactivating the keep-awake
10
- * feature. If unspecified, the default `tag` is used. See the documentation for `activateKeepAwakeAsync`
11
- * below to learn more about the `tag` argument.
10
+ * feature. If unspecified, an ID unique to the owner component is used. See the documentation for
11
+ * `activateKeepAwakeAsync` below to learn more about the `tag` argument.
12
12
  *
13
- * @param tag Tag to lock screen sleep prevention. If not provided, the default tag is used.
13
+ * @param tag Tag to lock screen sleep prevention. If not provided, an ID unique to the owner component is used.
14
14
  * @param options Additional options for the keep awake hook.
15
15
  */
16
16
  export declare function useKeepAwake(tag?: string, options?: KeepAwakeOptions): void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAuB,MAAM,mBAAmB,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B3E;AAGD;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,GAAE,MAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CAG/E;AAGD;;;;;;;;;;GAUG;AACH,wBAAsB,sBAAsB,CAAC,GAAG,GAAE,MAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1F;AAGD;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CAAC,GAAG,GAAE,MAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CACzB,aAAa,EAAE,MAAM,GAAG,iBAAiB,EACzC,QAAQ,CAAC,EAAE,iBAAiB,GAC3B,YAAY,CAUd;AAED,cAAc,mBAAmB,CAAC"}
package/build/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { UnavailabilityError } from 'expo-modules-core';
2
- import { useEffect } from 'react';
2
+ import { useEffect, useId } from 'react';
3
3
  import ExpoKeepAwake from './ExpoKeepAwake';
4
4
  /** Default tag, used when no tag has been specified in keep awake method calls. */
5
5
  export const ExpoKeepAwakeTag = 'ExpoKeepAwakeDefaultTag';
@@ -13,30 +13,32 @@ export async function isAvailableAsync() {
13
13
  /**
14
14
  * A React hook to keep the screen awake for as long as the owner component is mounted.
15
15
  * The optionally provided `tag` argument is used when activating and deactivating the keep-awake
16
- * feature. If unspecified, the default `tag` is used. See the documentation for `activateKeepAwakeAsync`
17
- * below to learn more about the `tag` argument.
16
+ * feature. If unspecified, an ID unique to the owner component is used. See the documentation for
17
+ * `activateKeepAwakeAsync` below to learn more about the `tag` argument.
18
18
  *
19
- * @param tag Tag to lock screen sleep prevention. If not provided, the default tag is used.
19
+ * @param tag Tag to lock screen sleep prevention. If not provided, an ID unique to the owner component is used.
20
20
  * @param options Additional options for the keep awake hook.
21
21
  */
22
- export function useKeepAwake(tag = ExpoKeepAwakeTag, options) {
22
+ export function useKeepAwake(tag, options) {
23
+ const defaultTag = useId();
24
+ const tagOrDefault = tag ?? defaultTag;
23
25
  useEffect(() => {
24
26
  let isMounted = true;
25
- activateKeepAwakeAsync(tag).then(() => {
27
+ activateKeepAwakeAsync(tagOrDefault).then(() => {
26
28
  if (isMounted && ExpoKeepAwake.addListenerForTag && options?.listener) {
27
- addListener(tag, options.listener);
29
+ addListener(tagOrDefault, options.listener);
28
30
  }
29
31
  });
30
32
  return () => {
31
33
  isMounted = false;
32
34
  if (options?.suppressDeactivateWarnings) {
33
- deactivateKeepAwake(tag).catch(() => { });
35
+ deactivateKeepAwake(tagOrDefault).catch(() => { });
34
36
  }
35
37
  else {
36
- deactivateKeepAwake(tag);
38
+ deactivateKeepAwake(tagOrDefault);
37
39
  }
38
40
  };
39
- }, [tag]);
41
+ }, [tagOrDefault]);
40
42
  }
41
43
  // @needsAudit
42
44
  /**
@@ -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,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;QACrB,sBAAsB,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;YACpC,IAAI,SAAS,IAAI,aAAa,CAAC,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AO,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,KAAK,EAAE,MAAM,OAAO,CAAC;AAEzC,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;QAClC,OAAO,MAAM,aAAa,CAAC,gBAAgB,EAAE,CAAC;KAC/C;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,GAAY,EAAE,OAA0B;IACnE,MAAM,UAAU,GAAG,KAAK,EAAE,CAAC;IAC3B,MAAM,YAAY,GAAG,GAAG,IAAI,UAAU,CAAC;IAEvC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,GAAG,IAAI,CAAC;QACrB,sBAAsB,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;YAC7C,IAAI,SAAS,IAAI,aAAa,CAAC,iBAAiB,IAAI,OAAO,EAAE,QAAQ,EAAE;gBACrE,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;aAC7C;QACH,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,KAAK,CAAC;YAClB,IAAI,OAAO,EAAE,0BAA0B,EAAE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AAc,mBAAmB,CAAC","sourcesContent":["import { Subscription, UnavailabilityError } from 'expo-modules-core';\nimport { useEffect, useId } 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, an ID unique to the owner component is used. See the documentation for\n * `activateKeepAwakeAsync` below to learn more about the `tag` argument.\n *\n * @param tag Tag to lock screen sleep prevention. If not provided, an ID unique to the owner component is used.\n * @param options Additional options for the keep awake hook.\n */\nexport function useKeepAwake(tag?: string, options?: KeepAwakeOptions): void {\n const defaultTag = useId();\n const tagOrDefault = tag ?? defaultTag;\n\n useEffect(() => {\n let isMounted = true;\n activateKeepAwakeAsync(tagOrDefault).then(() => {\n if (isMounted && ExpoKeepAwake.addListenerForTag && options?.listener) {\n addListener(tagOrDefault, options.listener);\n }\n });\n return () => {\n isMounted = false;\n if (options?.suppressDeactivateWarnings) {\n deactivateKeepAwake(tagOrDefault).catch(() => {});\n } else {\n deactivateKeepAwake(tagOrDefault);\n }\n };\n }, [tagOrDefault]);\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": "13.0.0",
3
+ "version": "13.0.2",
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": "4165b8d72e1b9a1889c2767534cc619e21468110"
45
+ "gitHead": "82b5a4a7ada98ca26cd99d097400b01240cbcf99"
46
46
  }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Subscription, UnavailabilityError } from 'expo-modules-core';
2
- import { useEffect } from 'react';
2
+ import { useEffect, useId } from 'react';
3
3
 
4
4
  import ExpoKeepAwake from './ExpoKeepAwake';
5
5
  import { KeepAwakeListener, KeepAwakeOptions } from './KeepAwake.types';
@@ -18,29 +18,32 @@ export async function isAvailableAsync(): Promise<boolean> {
18
18
  /**
19
19
  * A React hook to keep the screen awake for as long as the owner component is mounted.
20
20
  * The optionally provided `tag` argument is used when activating and deactivating the keep-awake
21
- * feature. If unspecified, the default `tag` is used. See the documentation for `activateKeepAwakeAsync`
22
- * below to learn more about the `tag` argument.
21
+ * feature. If unspecified, an ID unique to the owner component is used. See the documentation for
22
+ * `activateKeepAwakeAsync` below to learn more about the `tag` argument.
23
23
  *
24
- * @param tag Tag to lock screen sleep prevention. If not provided, the default tag is used.
24
+ * @param tag Tag to lock screen sleep prevention. If not provided, an ID unique to the owner component is used.
25
25
  * @param options Additional options for the keep awake hook.
26
26
  */
27
- export function useKeepAwake(tag: string = ExpoKeepAwakeTag, options?: KeepAwakeOptions): void {
27
+ export function useKeepAwake(tag?: string, options?: KeepAwakeOptions): void {
28
+ const defaultTag = useId();
29
+ const tagOrDefault = tag ?? defaultTag;
30
+
28
31
  useEffect(() => {
29
32
  let isMounted = true;
30
- activateKeepAwakeAsync(tag).then(() => {
33
+ activateKeepAwakeAsync(tagOrDefault).then(() => {
31
34
  if (isMounted && ExpoKeepAwake.addListenerForTag && options?.listener) {
32
- addListener(tag, options.listener);
35
+ addListener(tagOrDefault, options.listener);
33
36
  }
34
37
  });
35
38
  return () => {
36
39
  isMounted = false;
37
40
  if (options?.suppressDeactivateWarnings) {
38
- deactivateKeepAwake(tag).catch(() => {});
41
+ deactivateKeepAwake(tagOrDefault).catch(() => {});
39
42
  } else {
40
- deactivateKeepAwake(tag);
43
+ deactivateKeepAwake(tagOrDefault);
41
44
  }
42
45
  };
43
- }, [tag]);
46
+ }, [tagOrDefault]);
44
47
  }
45
48
 
46
49
  // @needsAudit