forked from sayem314/react-native-keep-awake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.native.js
More file actions
37 lines (30 loc) · 773 Bytes
/
index.native.js
File metadata and controls
37 lines (30 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React, { useEffect, useId } from "react";
import ReactNativeKCKeepAwake from "./NativeKCKeepAwake";
let tags = [];
export const activateKeepAwake = (tagId) => {
if (tags.length <= 0) {
ReactNativeKCKeepAwake.activate();
}
tags.push(tagId);
};
export const deactivateKeepAwake = (tagId) => {
tags = tags.filter((id) => id !== tagId);
if (tags.length <= 0) {
ReactNativeKCKeepAwake.deactivate();
}
};
export const useKeepAwake = () => {
const tagId = useId();
useEffect(() => {
activateKeepAwake(tagId);
return () => deactivateKeepAwake(tagId);
}, []);
};
export default () => {
const tagId = useId();
useEffect(() => {
activateKeepAwake(tagId);
return () => deactivateKeepAwake(tagId);
}, []);
return null;
};