@sdcx/overlay 0.3.0 → 0.5.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/RNOverlay.podspec +1 -1
- package/android/build.gradle +1 -0
- package/android/src/main/java/com/reactnative/overlay/OverlayModule.java +34 -7
- package/ios/Overlay/RNOverlayModule.m +24 -6
- package/lib/index.d.ts +7 -5
- package/lib/index.js +4 -4
- package/package.json +1 -1
- package/src/index.ts +12 -10
package/RNOverlay.podspec
CHANGED
|
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
|
|
|
10
10
|
s.homepage = package["homepage"]
|
|
11
11
|
s.license = package["license"]
|
|
12
12
|
s.authors = package["author"]
|
|
13
|
-
s.platforms = { :ios => "
|
|
13
|
+
s.platforms = { :ios => "11.0" }
|
|
14
14
|
s.source = { :git => "https://github.com/github-account/overlay.git", :tag => "#{s.version}" }
|
|
15
15
|
|
|
16
16
|
s.source_files = "ios/Overlay/**/*.{h,m,mm}"
|
package/android/build.gradle
CHANGED
|
@@ -3,15 +3,21 @@ package com.reactnative.overlay;
|
|
|
3
3
|
import android.app.Activity;
|
|
4
4
|
|
|
5
5
|
import androidx.annotation.NonNull;
|
|
6
|
+
import androidx.core.graphics.Insets;
|
|
7
|
+
import androidx.core.view.ViewCompat;
|
|
8
|
+
import androidx.core.view.WindowInsetsCompat;
|
|
6
9
|
|
|
7
10
|
import com.facebook.common.logging.FLog;
|
|
8
11
|
import com.facebook.react.ReactNativeHost;
|
|
12
|
+
import com.facebook.react.bridge.JavaOnlyMap;
|
|
9
13
|
import com.facebook.react.bridge.LifecycleEventListener;
|
|
10
14
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
11
15
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
12
16
|
import com.facebook.react.bridge.ReactMethod;
|
|
13
17
|
import com.facebook.react.bridge.ReadableMap;
|
|
14
18
|
import com.facebook.react.bridge.UiThreadUtil;
|
|
19
|
+
import com.facebook.react.bridge.WritableMap;
|
|
20
|
+
import com.facebook.react.uimanager.PixelUtil;
|
|
15
21
|
|
|
16
22
|
import java.util.HashMap;
|
|
17
23
|
public class OverlayModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
|
|
@@ -53,7 +59,7 @@ public class OverlayModule extends ReactContextBaseJavaModule implements Lifecyc
|
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
@ReactMethod
|
|
56
|
-
public void show(final String moduleName, final ReadableMap
|
|
62
|
+
public void show(final String moduleName, final ReadableMap options) {
|
|
57
63
|
UiThreadUtil.runOnUiThread(() -> {
|
|
58
64
|
final Activity activity = getCurrentActivity();
|
|
59
65
|
if (activity == null || activity.isFinishing()) {
|
|
@@ -65,21 +71,24 @@ public class OverlayModule extends ReactContextBaseJavaModule implements Lifecyc
|
|
|
65
71
|
overlay.update();
|
|
66
72
|
return;
|
|
67
73
|
}
|
|
68
|
-
|
|
74
|
+
|
|
75
|
+
int id = options.getInt("id");
|
|
76
|
+
WritableMap props = JavaOnlyMap.deepClone(options);
|
|
77
|
+
props.putMap("insets", getInsets(activity));
|
|
69
78
|
overlay = new Overlay(activity, moduleName, reactNativeHost.getReactInstanceManager());
|
|
70
79
|
overlay.show(props, options);
|
|
71
|
-
overlays.put(moduleName, overlay);
|
|
80
|
+
overlays.put(genOverlayKey(moduleName, id), overlay);
|
|
72
81
|
});
|
|
73
82
|
}
|
|
74
|
-
|
|
83
|
+
|
|
75
84
|
@ReactMethod
|
|
76
|
-
public void hide(String moduleName) {
|
|
85
|
+
public void hide(String moduleName, int id) {
|
|
77
86
|
UiThreadUtil.runOnUiThread(() -> {
|
|
78
|
-
Overlay overlay = overlays.get(moduleName);
|
|
87
|
+
Overlay overlay = overlays.get(genOverlayKey(moduleName, id));
|
|
79
88
|
if (overlay == null) {
|
|
80
89
|
return;
|
|
81
90
|
}
|
|
82
|
-
overlays.remove(moduleName);
|
|
91
|
+
overlays.remove(genOverlayKey(moduleName, id));
|
|
83
92
|
overlay.hide();
|
|
84
93
|
});
|
|
85
94
|
}
|
|
@@ -99,4 +108,22 @@ public class OverlayModule extends ReactContextBaseJavaModule implements Lifecyc
|
|
|
99
108
|
FLog.i("OverlayModule", "onHostDestroy");
|
|
100
109
|
handleDestroy();
|
|
101
110
|
}
|
|
111
|
+
|
|
112
|
+
private String genOverlayKey(String moduleName, int id) {
|
|
113
|
+
return moduleName + "-" + id;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private ReadableMap getInsets(Activity activity) {
|
|
117
|
+
WindowInsetsCompat windowInsets = ViewCompat.getRootWindowInsets(activity.getWindow().getDecorView());
|
|
118
|
+
assert windowInsets != null;
|
|
119
|
+
Insets navigationBarInsets = windowInsets.getInsetsIgnoringVisibility(WindowInsetsCompat.Type.navigationBars());
|
|
120
|
+
Insets statusBarInsets = windowInsets.getInsetsIgnoringVisibility(WindowInsetsCompat.Type.statusBars());
|
|
121
|
+
Insets displayCutoutInsets = windowInsets.getInsetsIgnoringVisibility(WindowInsetsCompat.Type.displayCutout());
|
|
122
|
+
WritableMap insets = new JavaOnlyMap();
|
|
123
|
+
insets.putDouble("left", PixelUtil.toDIPFromPixel(Math.max(navigationBarInsets.left, displayCutoutInsets.left)));
|
|
124
|
+
insets.putDouble("top", PixelUtil.toDIPFromPixel(statusBarInsets.top));
|
|
125
|
+
insets.putDouble("right", PixelUtil.toDIPFromPixel(Math.max(navigationBarInsets.right, displayCutoutInsets.right)));
|
|
126
|
+
insets.putDouble("bottom", PixelUtil.toDIPFromPixel(navigationBarInsets.bottom));
|
|
127
|
+
return insets;
|
|
128
|
+
}
|
|
102
129
|
}
|
|
@@ -5,6 +5,11 @@
|
|
|
5
5
|
#import <React/RCTBridge.h>
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
NSString* genKey(NSString* moduleName, NSNumber* id) {
|
|
9
|
+
return [NSString stringWithFormat:@"%@-%@", moduleName, id];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
8
13
|
@interface RNOverlayModule ()
|
|
9
14
|
|
|
10
15
|
@property(nonatomic, strong) NSMutableDictionary *overlays;
|
|
@@ -45,25 +50,38 @@
|
|
|
45
50
|
RCT_EXPORT_MODULE(OverlayHost)
|
|
46
51
|
|
|
47
52
|
|
|
48
|
-
RCT_EXPORT_METHOD(show:(NSString *)moduleName
|
|
49
|
-
|
|
53
|
+
RCT_EXPORT_METHOD(show:(NSString *)moduleName options:(NSDictionary *)options) {
|
|
54
|
+
NSString* key = genKey(moduleName, options[@"id"]);
|
|
55
|
+
RNOverlay *overlay = self.overlays[key];
|
|
50
56
|
if (overlay != nil) {
|
|
51
57
|
[overlay update];
|
|
52
58
|
return;
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
overlay = [[RNOverlay alloc] initWithModuleName:moduleName bridge:self.bridge];
|
|
56
|
-
self.overlays[
|
|
62
|
+
self.overlays[key] = overlay;
|
|
63
|
+
|
|
64
|
+
UIWindow *window = RCTKeyWindow();
|
|
65
|
+
UIEdgeInsets safeAreaInsets = window.safeAreaInsets;
|
|
66
|
+
NSDictionary* insets = @{
|
|
67
|
+
@"top" : @(safeAreaInsets.top),
|
|
68
|
+
@"right" : @(safeAreaInsets.right),
|
|
69
|
+
@"bottom" : @(safeAreaInsets.bottom),
|
|
70
|
+
@"left" : @(safeAreaInsets.left),
|
|
71
|
+
};
|
|
57
72
|
|
|
73
|
+
NSMutableDictionary *props = [options mutableCopy];
|
|
74
|
+
[props setObject:insets forKey:@"insets"];
|
|
58
75
|
[overlay show:props options:options];
|
|
59
76
|
}
|
|
60
77
|
|
|
61
|
-
RCT_EXPORT_METHOD(hide:(NSString *)moduleName) {
|
|
62
|
-
|
|
78
|
+
RCT_EXPORT_METHOD(hide:(NSString *)moduleName id:(nonnull NSNumber *)id) {
|
|
79
|
+
NSString* key = genKey(moduleName, id);
|
|
80
|
+
RNOverlay *overlay = self.overlays[key];
|
|
63
81
|
if (!overlay) {
|
|
64
82
|
return;
|
|
65
83
|
}
|
|
66
|
-
[self.overlays removeObjectForKey:
|
|
84
|
+
[self.overlays removeObjectForKey:key];
|
|
67
85
|
[overlay hide];
|
|
68
86
|
}
|
|
69
87
|
|
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { Insets } from 'react-native';
|
|
2
|
+
export interface OverlayOptions {
|
|
3
|
+
id: number;
|
|
2
4
|
passThroughTouches?: boolean;
|
|
3
5
|
}
|
|
4
|
-
interface
|
|
5
|
-
|
|
6
|
+
export interface OverlayProps extends OverlayOptions {
|
|
7
|
+
insets: Insets;
|
|
6
8
|
}
|
|
7
|
-
declare function show
|
|
8
|
-
declare function hide(moduleName: string): void;
|
|
9
|
+
declare function show(moduleName: string, options: OverlayOptions): void;
|
|
10
|
+
declare function hide(moduleName: string, id: number): void;
|
|
9
11
|
declare const Overlay: {
|
|
10
12
|
show: typeof show;
|
|
11
13
|
hide: typeof hide;
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { NativeModules } from 'react-native';
|
|
2
2
|
const OverlayHost = NativeModules.OverlayHost;
|
|
3
|
-
function show(moduleName,
|
|
4
|
-
OverlayHost.show(moduleName,
|
|
3
|
+
function show(moduleName, options) {
|
|
4
|
+
OverlayHost.show(moduleName, options);
|
|
5
5
|
}
|
|
6
|
-
function hide(moduleName) {
|
|
7
|
-
OverlayHost.hide(moduleName);
|
|
6
|
+
function hide(moduleName, id) {
|
|
7
|
+
OverlayHost.hide(moduleName, id);
|
|
8
8
|
}
|
|
9
9
|
const Overlay = { show, hide };
|
|
10
10
|
export { Overlay };
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import { NativeModule, NativeModules } from 'react-native'
|
|
1
|
+
import { Insets, NativeModule, NativeModules } from 'react-native'
|
|
2
2
|
|
|
3
|
-
interface OverlayOptions {
|
|
3
|
+
export interface OverlayOptions {
|
|
4
|
+
id: number
|
|
4
5
|
passThroughTouches?: boolean
|
|
5
6
|
}
|
|
6
7
|
|
|
7
|
-
interface
|
|
8
|
-
|
|
8
|
+
export interface OverlayProps extends OverlayOptions {
|
|
9
|
+
insets: Insets
|
|
9
10
|
}
|
|
11
|
+
|
|
10
12
|
interface OverlayInterface extends NativeModule {
|
|
11
|
-
show
|
|
12
|
-
hide(moduleName: string): void
|
|
13
|
+
show(moduleName: string, options: OverlayOptions): void
|
|
14
|
+
hide(moduleName: string, id: number): void
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
const OverlayHost: OverlayInterface = NativeModules.OverlayHost
|
|
16
18
|
|
|
17
|
-
function show
|
|
18
|
-
OverlayHost.show(moduleName,
|
|
19
|
+
function show(moduleName: string, options: OverlayOptions) {
|
|
20
|
+
OverlayHost.show(moduleName, options)
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
function hide(moduleName: string) {
|
|
22
|
-
OverlayHost.hide(moduleName)
|
|
23
|
+
function hide(moduleName: string, id: number) {
|
|
24
|
+
OverlayHost.hide(moduleName, id)
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
const Overlay = { show, hide }
|