rn-draw-overlay-permission 1.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/.gitattributes +1 -0
- package/README.md +47 -0
- package/android/build.gradle +36 -0
- package/android/src/main/AndroidManifest.xml +6 -0
- package/android/src/main/java/com/toyberman/drawOverlay/RNDrawOverlayModule.java +70 -0
- package/android/src/main/java/com/toyberman/drawOverlay/RNDrawOverlayPackage.java +28 -0
- package/index.js +6 -0
- package/package.json +17 -0
package/.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*.pbxproj -text
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
|
|
2
|
+
# react-native-draw-overlay
|
|
3
|
+
Ask for draw over other apps permission.
|
|
4
|
+
|
|
5
|
+
## Getting started
|
|
6
|
+
|
|
7
|
+
`$ npm install react-native-draw-overlay --save`
|
|
8
|
+
|
|
9
|
+
### Mostly automatic installation
|
|
10
|
+
|
|
11
|
+
`$ react-native link react-native-draw-overlay`
|
|
12
|
+
|
|
13
|
+
### Manual installation
|
|
14
|
+
|
|
15
|
+
#### Android
|
|
16
|
+
|
|
17
|
+
1. Open up `android/app/src/main/java/[...]/MainActivity.java`
|
|
18
|
+
- Add `import com.reactlibrary.RNDrawOverlayPackage;` to the imports at the top of the file
|
|
19
|
+
- Add `new RNDrawOverlayPackage()` to the list returned by the `getPackages()` method
|
|
20
|
+
2. Append the following lines to `android/settings.gradle`:
|
|
21
|
+
```
|
|
22
|
+
include ':react-native-draw-overlay'
|
|
23
|
+
project(':react-native-draw-overlay').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-draw-overlay/android')
|
|
24
|
+
```
|
|
25
|
+
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
|
|
26
|
+
```
|
|
27
|
+
implementation project(':react-native-draw-overlay')
|
|
28
|
+
```
|
|
29
|
+
## Usage
|
|
30
|
+
add
|
|
31
|
+
```xml
|
|
32
|
+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
|
33
|
+
to AndroidManifest.xml
|
|
34
|
+
```
|
|
35
|
+
```javascript
|
|
36
|
+
import RNDrawOverlay from 'react-native-draw-overlay';
|
|
37
|
+
|
|
38
|
+
// TODO: What to do with the module?
|
|
39
|
+
RNDrawOverlay.askForDispalayOverOtherAppsPermission()
|
|
40
|
+
.then(res => {
|
|
41
|
+
// res will be true if permission was granted
|
|
42
|
+
})
|
|
43
|
+
.catch(e => {
|
|
44
|
+
// permission was declined
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
|
|
2
|
+
buildscript {
|
|
3
|
+
repositories {
|
|
4
|
+
jcenter()
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
dependencies {
|
|
8
|
+
classpath 'com.android.tools.build:gradle:1.3.1'
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
apply plugin: 'com.android.library'
|
|
13
|
+
|
|
14
|
+
android {
|
|
15
|
+
compileSdkVersion 23
|
|
16
|
+
buildToolsVersion "23.0.1"
|
|
17
|
+
|
|
18
|
+
defaultConfig {
|
|
19
|
+
minSdkVersion 16
|
|
20
|
+
targetSdkVersion 22
|
|
21
|
+
versionCode 1
|
|
22
|
+
versionName "1.0"
|
|
23
|
+
}
|
|
24
|
+
lintOptions {
|
|
25
|
+
abortOnError false
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
repositories {
|
|
30
|
+
mavenCentral()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
dependencies {
|
|
34
|
+
implementation 'com.facebook.react:react-native:+'
|
|
35
|
+
}
|
|
36
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
package com.toyberman.drawOverlay;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.content.Intent;
|
|
5
|
+
import android.net.Uri;
|
|
6
|
+
import android.os.Build;
|
|
7
|
+
import android.provider.Settings;
|
|
8
|
+
|
|
9
|
+
import com.facebook.react.bridge.ActivityEventListener;
|
|
10
|
+
import com.facebook.react.bridge.BaseActivityEventListener;
|
|
11
|
+
import com.facebook.react.bridge.Promise;
|
|
12
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
13
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
14
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
15
|
+
|
|
16
|
+
public class RNDrawOverlayModule extends ReactContextBaseJavaModule {
|
|
17
|
+
|
|
18
|
+
private final ReactApplicationContext reactContext;
|
|
19
|
+
private final int DRAW_OVER_OTHER_APP_PERMISSION_REQUEST_CODE = 1222;
|
|
20
|
+
private Promise mPromise;
|
|
21
|
+
private final String error = "Permission was not granted";
|
|
22
|
+
|
|
23
|
+
private final ActivityEventListener mActivityEventListener = new BaseActivityEventListener() {
|
|
24
|
+
@Override
|
|
25
|
+
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
|
|
26
|
+
super.onActivityResult(activity, requestCode, resultCode, data);
|
|
27
|
+
if (requestCode == DRAW_OVER_OTHER_APP_PERMISSION_REQUEST_CODE) {
|
|
28
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
29
|
+
if (Settings.canDrawOverlays(activity.getApplicationContext())) {
|
|
30
|
+
// Permission Granted by Overlay
|
|
31
|
+
mPromise.resolve(true);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
mPromise.reject(new Throwable(error));
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
mPromise.resolve(true);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
public RNDrawOverlayModule(ReactApplicationContext reactContext) {
|
|
48
|
+
super(reactContext);
|
|
49
|
+
this.reactContext = reactContext;
|
|
50
|
+
|
|
51
|
+
this.reactContext.addActivityEventListener(mActivityEventListener);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@Override
|
|
55
|
+
public String getName() {
|
|
56
|
+
return "RNDrawOverlay";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@ReactMethod
|
|
61
|
+
public void askForDispalayOverOtherAppsPermission(Promise promise) {
|
|
62
|
+
mPromise = promise;
|
|
63
|
+
if (!Settings.canDrawOverlays(this.reactContext)) {
|
|
64
|
+
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + this.reactContext.getPackageName()));
|
|
65
|
+
this.reactContext.startActivityForResult(intent, DRAW_OVER_OTHER_APP_PERMISSION_REQUEST_CODE, null);
|
|
66
|
+
} else {
|
|
67
|
+
promise.resolve(true);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
package com.toyberman.drawOverlay;
|
|
3
|
+
|
|
4
|
+
import java.util.Arrays;
|
|
5
|
+
import java.util.Collections;
|
|
6
|
+
import java.util.List;
|
|
7
|
+
|
|
8
|
+
import com.facebook.react.ReactPackage;
|
|
9
|
+
import com.facebook.react.bridge.NativeModule;
|
|
10
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
11
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
12
|
+
import com.facebook.react.bridge.JavaScriptModule;
|
|
13
|
+
public class RNDrawOverlayPackage implements ReactPackage {
|
|
14
|
+
@Override
|
|
15
|
+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
16
|
+
return Arrays.<NativeModule>asList(new RNDrawOverlayModule(reactContext));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Deprecated from RN 0.47
|
|
20
|
+
public List<Class<? extends JavaScriptModule>> createJSModules() {
|
|
21
|
+
return Collections.emptyList();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Override
|
|
25
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
26
|
+
return Collections.emptyList();
|
|
27
|
+
}
|
|
28
|
+
}
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
{
|
|
3
|
+
"name": "rn-draw-overlay-permission",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"react-native"
|
|
12
|
+
],
|
|
13
|
+
"license": "",
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"react-native": ">=0.41.2 <=0.75.2"
|
|
16
|
+
}
|
|
17
|
+
}
|