Skip to content

Commit 548a054

Browse files
committed
Fixed discrepancies with function naming, please check the readme.
1 parent 99c31f1 commit 548a054

File tree

4 files changed

+61
-41
lines changed

4 files changed

+61
-41
lines changed

README.md

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,47 @@
66
A simple React-Native utils library with useful functions.
77
Currently only supporting Android 4.1+, iOS might come later.
88

9-
## Quick Start:
9+
## Quick Start
10+
1011
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.
1112

1213
**npm**: `npm install react-native-app-utils`
1314
**yarn**: `yarn add react-native-app-utils`
1415

15-
## Installation:
16+
## Installation
1617

1718
Inside `android/app/src/main/AndroidManifest.xml` add this permission if you intend to use the wake lock functions.
19+
1820
```xml
1921
<uses-permission android:name="android.permission.WAKE_LOCK" />
2022
```
23+
2124
### React Native 0.60+
25+
2226
You won't usually need to do anything past this point, everything should just link up using the new autolinking feature.
2327

24-
### Older React Native Versions:
28+
### Older React Native Versions
29+
2530
You should be able to run the following command to get everything linked up.
2631
`react-native link react-native-app-utils`
2732

2833
**If for some reason that doesn't work then you can follow the manual linking steps below.**
2934

30-
1) Inside `android/app/build.gradle` add this line `implementation project(':react-native-app-utils')` in the dependencies {} section.
35+
Inside `android/app/build.gradle` add the following line in the existing dependencies section.
3136

32-
2) Inside `android/settings.gradle` add these lines.
37+
```gradle
38+
implementation project(':react-native-app-utils')
3339
```
40+
41+
Inside `android/settings.gradle` add these lines to the bottom of the file.
42+
43+
```gradle
3444
include ':react-native-app-utils'
3545
project(':react-native-app-utils').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-app-utils/android')
3646
```
37-
3) Inside `MainApplication.java` import and add our package to the list.
47+
48+
Inside `MainApplication.java` import and add our package to the existing package list.
49+
3850
```java
3951
import com.stumbleapp.utils.UtilsPackage;
4052

@@ -45,46 +57,54 @@ private static List<ReactPackage> getPackages() {
4557

4658
);
4759
}
48-
```
49-
50-
## Usage:
51-
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+
5367
```javascript
5468
import Utils from 'react-native-app-utils';
55-
```
56-
69+
```
70+
5771
This will essentially move your app to the front if it's already running, otherwise it will get the app to start.
5872
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+
5974
```javascript
6075
Utils.startApp();
61-
```
62-
76+
```
77+
6378
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+
6480
```javascript
6581
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+
6986
```javascript
70-
Utils.acquireWakelock();
71-
Utils.releaseWakelock();
87+
Utils.acquireWakeLock();
88+
Utils.releaseWakeLock();
7289

73-
Utils.acquirePartialWakelock();
74-
Utils.releasePartialWakelock();
90+
Utils.acquirePartialWakeLock();
91+
Utils.releasePartialWakeLock();
7592

76-
Utils.aquireScreenLock();
93+
Utils.acquireScreenLock();
7794
Utils.releaseScreenLock();
78-
```
79-
95+
```
96+
8097
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+
8199
```javascript
82-
Utils.aquireWifiLock();
100+
Utils.acquireWifiLock();
83101
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+**
87106
We will be looking to add extra functionality to this soon.
107+
88108
```javascript
89109
Utils.enterPictureInPictureMode();
90110
```

android/src/main/java/com/stumbleapp/utils/UtilsModule.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void moveAppToBack() {
147147
}
148148

149149
@ReactMethod
150-
public void acquireWakelock() {
150+
public void acquireWakeLock() {
151151
if ( wakeLock.isHeld() ) {
152152
return;
153153
}
@@ -165,7 +165,7 @@ public void releaseWakeLock() {
165165
}
166166

167167
@ReactMethod
168-
public void acquirePartialWakelock() {
168+
public void acquirePartialWakeLock() {
169169
if ( partialWakeLock.isHeld() ) {
170170
return;
171171
}
@@ -174,7 +174,7 @@ public void acquirePartialWakelock() {
174174
}
175175

176176
@ReactMethod
177-
public void releasePartialWakelock() {
177+
public void releasePartialWakeLock() {
178178
if ( !partialWakeLock.isHeld() ) {
179179
return;
180180
}

index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const UtilsModule = NativeModules.UtilsModule;
66

77
function startApp() { return UtilsModule.startApp(); };
88
function moveAppToBack() { return UtilsModule.moveAppToBack(); };
9-
function acquireWakelock() { return UtilsModule.acquireWakelock(); };
10-
function releaseWakelock() { return UtilsModule.releaseWakelock(); };
11-
function acquirePartialWakelock() { return UtilsModule.acquirePartialWakelock(); };
12-
function releasePartialWakelock() { return UtilsModule.releasePartialWakelock(); };
9+
function acquireWakeLock() { return UtilsModule.acquireWakeLock(); };
10+
function releaseWakeLock() { return UtilsModule.releaseWakeLock(); };
11+
function acquirePartialWakeLock() { return UtilsModule.acquirePartialWakeLock(); };
12+
function releasePartialWakeLock() { return UtilsModule.releasePartialWakeLock(); };
1313
function acquireScreenLock() { return UtilsModule.acquireScreenLock(); };
1414
function releaseScreenLock() { return UtilsModule.releaseScreenLock(); };
1515
function acquireWifiLock() { return UtilsModule.acquireWifiLock(); };
@@ -19,10 +19,10 @@ function enterPictureInPictureMode() { return UtilsModule.enterPictureInPictureM
1919
export default {
2020
startApp: startApp,
2121
moveAppToBack: moveAppToBack,
22-
acquireWakelock: acquireWakelock,
23-
releaseWakelock: releaseWakelock,
24-
acquirePartialWakelock: acquirePartialWakelock,
25-
releasePartialWakelock: releasePartialWakelock,
22+
acquireWakeLock: acquireWakeLock,
23+
releaseWakeLock: releaseWakeLock,
24+
acquirePartialWakeLock: acquirePartialWakeLock,
25+
releasePartialWakeLock: releasePartialWakeLock,
2626
acquireScreenLock: acquireScreenLock,
2727
releaseScreenLock: releaseScreenLock,
2828
acquireWifiLock: acquireWifiLock,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-app-utils",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "A simple React-Native utils library with useful functions.",
55
"nativePackage": true,
66
"main": "index.js",

0 commit comments

Comments
 (0)