@sdcx/overlay 0.4.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 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 => "10.0" }
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}"
@@ -32,4 +32,5 @@ android {
32
32
  dependencies {
33
33
  implementation fileTree(dir: 'libs', include: ['*.jar'])
34
34
  implementation 'com.facebook.react:react-native:+'
35
+ implementation "androidx.appcompat:appcompat:1.3.1"
35
36
  }
@@ -3,10 +3,13 @@ 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;
9
- import com.facebook.react.bridge.Arguments;
12
+ import com.facebook.react.bridge.JavaOnlyMap;
10
13
  import com.facebook.react.bridge.LifecycleEventListener;
11
14
  import com.facebook.react.bridge.ReactApplicationContext;
12
15
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
@@ -14,6 +17,7 @@ import com.facebook.react.bridge.ReactMethod;
14
17
  import com.facebook.react.bridge.ReadableMap;
15
18
  import com.facebook.react.bridge.UiThreadUtil;
16
19
  import com.facebook.react.bridge.WritableMap;
20
+ import com.facebook.react.uimanager.PixelUtil;
17
21
 
18
22
  import java.util.HashMap;
19
23
  public class OverlayModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
@@ -69,14 +73,14 @@ public class OverlayModule extends ReactContextBaseJavaModule implements Lifecyc
69
73
  }
70
74
 
71
75
  int id = options.getInt("id");
72
- WritableMap props = Arguments.createMap();
73
- props.putInt("id", id);
76
+ WritableMap props = JavaOnlyMap.deepClone(options);
77
+ props.putMap("insets", getInsets(activity));
74
78
  overlay = new Overlay(activity, moduleName, reactNativeHost.getReactInstanceManager());
75
79
  overlay.show(props, options);
76
80
  overlays.put(genOverlayKey(moduleName, id), overlay);
77
81
  });
78
82
  }
79
-
83
+
80
84
  @ReactMethod
81
85
  public void hide(String moduleName, int id) {
82
86
  UiThreadUtil.runOnUiThread(() -> {
@@ -108,4 +112,18 @@ public class OverlayModule extends ReactContextBaseJavaModule implements Lifecyc
108
112
  private String genOverlayKey(String moduleName, int id) {
109
113
  return moduleName + "-" + id;
110
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
+ }
111
129
  }
@@ -61,7 +61,18 @@ RCT_EXPORT_METHOD(show:(NSString *)moduleName options:(NSDictionary *)options) {
61
61
  overlay = [[RNOverlay alloc] initWithModuleName:moduleName bridge:self.bridge];
62
62
  self.overlays[key] = overlay;
63
63
 
64
- [overlay show:@{@"id": options[@"id"]} options:options];
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
+ };
72
+
73
+ NSMutableDictionary *props = [options mutableCopy];
74
+ [props setObject:insets forKey:@"insets"];
75
+ [overlay show:props options:options];
65
76
  }
66
77
 
67
78
  RCT_EXPORT_METHOD(hide:(NSString *)moduleName id:(nonnull NSNumber *)id) {
package/lib/index.d.ts CHANGED
@@ -1,7 +1,11 @@
1
+ import { Insets } from 'react-native';
1
2
  export interface OverlayOptions {
2
3
  id: number;
3
4
  passThroughTouches?: boolean;
4
5
  }
6
+ export interface OverlayProps extends OverlayOptions {
7
+ insets: Insets;
8
+ }
5
9
  declare function show(moduleName: string, options: OverlayOptions): void;
6
10
  declare function hide(moduleName: string, id: number): void;
7
11
  declare const Overlay: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sdcx/overlay",
3
3
  "description": "A react-native Overlay component.",
4
- "version": "0.4.0",
4
+ "version": "0.5.0",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "./lib/index.d.ts",
7
7
  "react-native": "src/index",
package/src/index.ts CHANGED
@@ -1,10 +1,14 @@
1
- import { NativeModule, NativeModules } from 'react-native'
1
+ import { Insets, NativeModule, NativeModules } from 'react-native'
2
2
 
3
3
  export interface OverlayOptions {
4
4
  id: number
5
5
  passThroughTouches?: boolean
6
6
  }
7
7
 
8
+ export interface OverlayProps extends OverlayOptions {
9
+ insets: Insets
10
+ }
11
+
8
12
  interface OverlayInterface extends NativeModule {
9
13
  show(moduleName: string, options: OverlayOptions): void
10
14
  hide(moduleName: string, id: number): void