You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+49-29Lines changed: 49 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,35 +6,47 @@
6
6
A simple React-Native utils library with useful functions.
7
7
Currently only supporting Android 4.1+, iOS might come later.
8
8
9
-
## Quick Start:
9
+
## Quick Start
10
+
10
11
In a lot of cases if you are using the latest version of React Native then you should be able to run one of the preferred package install methods and immediately get going.
11
12
12
13
**npm**: `npm install react-native-app-utils`
13
14
**yarn**: `yarn add react-native-app-utils`
14
15
15
-
## Installation:
16
+
## Installation
16
17
17
18
Inside `android/app/src/main/AndroidManifest.xml` add this permission if you intend to use the wake lock functions.
Here is a general rundown of the included functions and examples of their use.
52
-
Lets get our module imported.
60
+
```
61
+
62
+
## Usage
63
+
64
+
Here is a general rundown of the included functions and examples of their use.
65
+
Let's get the module imported so we can actually use it.
66
+
53
67
```javascript
54
68
importUtilsfrom'react-native-app-utils';
55
-
```
56
-
69
+
```
70
+
57
71
This will essentially move your app to the front if it's already running, otherwise it will get the app to start.
58
72
I'm not entirely sure how this would pan out on some devices, theres a chance it won't work on any that restrict starting apps from background services. The reason i wanted this kind of function though was to get our app to start when there was an incoming call notification triggered by Firebase.
73
+
59
74
```javascript
60
75
Utils.startApp();
61
-
```
62
-
76
+
```
77
+
63
78
This will make your app goto the background. Very useful if you use the above function to start your app but then want to put the app back to sleep in the background. Our use case for this was simply for when a call came in, the app would start but if the call went unanswered for a while then we would leave a missed call notification and hide the app.
79
+
64
80
```javascript
65
81
Utils.moveAppToBack();
66
-
```
67
-
68
-
If for any reason you want to keep the screen on while your app is running then you can use wake locks and screen locks. Make sure to release them if having the screen on isn't always a requirement of using your app, think about the battery usage! The first wake lock function should cause the screen to switch on, otherwise you can mix and match, try using a screen lock aswell. Last but not least you can use partial wake locks if you need the device to be alive while doing background work.
82
+
```
83
+
84
+
If for any reason you need to keep the screen on while your app is running then you can use wake locks and screen locks. Make sure to release them if having the screen on by force isn't always a requirement of using your app, think about the battery usage! The first wake lock function should cause the screen to switch on, otherwise you can mix and match, try using a screen lock aswell. Last but not least you can use partial wake locks if you need the device to be alive while doing background service work, not always a requirement as some modules will handle that themselvs.
85
+
69
86
```javascript
70
-
Utils.acquireWakelock();
71
-
Utils.releaseWakelock();
87
+
Utils.acquireWakeLock();
88
+
Utils.releaseWakeLock();
72
89
73
-
Utils.acquirePartialWakelock();
74
-
Utils.releasePartialWakelock();
90
+
Utils.acquirePartialWakeLock();
91
+
Utils.releasePartialWakeLock();
75
92
76
-
Utils.aquireScreenLock();
93
+
Utils.acquireScreenLock();
77
94
Utils.releaseScreenLock();
78
-
```
79
-
95
+
```
96
+
80
97
If for any reason you need to keep the wifi connection alive then you can use wifi locks. This does not prevent the user switching off their wifi connection manually. Best use case scenario would be if you need a connection for long periods due to background work or active interactions like a phone call.
98
+
81
99
```javascript
82
-
Utils.aquireWifiLock();
100
+
Utils.acquireWifiLock();
83
101
Utils.releaseWifiLock();
84
-
```
85
-
This is an experimental function that hasn't been fully implemented yet.
86
-
**Requires Android API 24+**
102
+
```
103
+
104
+
This is an experimental function that hasn't been fully implemented yet.
105
+
**Requires Android API 24+**
87
106
We will be looking to add extra functionality to this soon.
0 commit comments