@sdcx/overlay 0.5.0 → 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/package.json CHANGED
@@ -1,66 +1,52 @@
1
1
  {
2
- "name": "@sdcx/overlay",
3
- "description": "A react-native Overlay component.",
4
- "version": "0.5.0",
5
- "main": "./lib/index.js",
6
- "typings": "./lib/index.d.ts",
7
- "react-native": "src/index",
8
- "nativePackage": true,
9
- "files": [
10
- "src",
11
- "lib",
12
- "android",
13
- "ios",
14
- "RNOverlay.podspec",
15
- "!android/build",
16
- "!ios/build",
17
- "!**/__tests__"
18
- ],
19
- "repository": "https://github.com/sdcxtech/react-native-troika",
20
- "homepage": "https://github.com/sdcxtech/react-native-troika/tree/master/packages/overlay#readme",
21
- "author": "sdcx",
22
- "license": "MIT",
23
- "keywords": [
24
- "react-native",
25
- "overlay"
26
- ],
27
- "scripts": {
28
- "build": "rm -rf ./lib && tsc -p tsconfig.build.json",
29
- "prepare": "npm run build",
30
- "tsc": "tsc",
31
- "test": "jest",
32
- "lint": "eslint . --fix --ext .js,.jsx,.ts,.tsx"
33
- },
34
- "peerDependencies": {
35
- "react": ">=16.8",
36
- "react-native": ">=0.60"
37
- },
38
- "devDependencies": {
39
- "@babel/core": "^7.13.10",
40
- "@babel/runtime": "^7.13.10",
41
- "@react-native-community/eslint-config": "^3.0.0",
42
- "@types/jest": "^27.0.1",
43
- "@types/react": "^17.0.2",
44
- "@types/react-native": "^0.67.0",
45
- "@types/react-test-renderer": "17.0.2",
46
- "babel-jest": "^27.0.6",
47
- "jest": "^27.0.6",
48
- "metro-react-native-babel-preset": "^0.66.2",
49
- "react": "17.0.2",
50
- "react-native": "^0.67.4",
51
- "react-test-renderer": "17.0.2",
52
- "eslint": "^7.32.0",
53
- "typescript": "^4.6.4"
54
- },
55
- "jest": {
56
- "preset": "react-native",
57
- "moduleFileExtensions": [
58
- "ts",
59
- "tsx",
60
- "js",
61
- "jsx",
62
- "json",
63
- "node"
64
- ]
65
- }
2
+ "name": "@sdcx/overlay",
3
+ "description": "A react-native Overlay component.",
4
+ "version": "1.0.0",
5
+ "main": "./dist/index.js",
6
+ "typings": "./dist/index.d.ts",
7
+ "react-native": "src/index",
8
+ "nativePackage": true,
9
+ "files": [
10
+ "src",
11
+ "dist",
12
+ "android",
13
+ "ios",
14
+ "RNOverlay.podspec",
15
+ "!android/build",
16
+ "!ios/build",
17
+ "!**/__tests__"
18
+ ],
19
+ "repository": "https://github.com/sdcxtech/react-native-troika",
20
+ "homepage": "https://github.com/sdcxtech/react-native-troika/tree/master/packages/overlay#readme",
21
+ "author": "sdcx",
22
+ "license": "MIT",
23
+ "keywords": [
24
+ "react-native",
25
+ "overlay"
26
+ ],
27
+ "scripts": {
28
+ "build": "rm -rf ./dist && tsc -p tsconfig.json",
29
+ "prepare": "npm run build",
30
+ "tsc": "tsc",
31
+ "test": "jest",
32
+ "lint": "eslint . --fix --ext .js,.jsx,.ts,.tsx"
33
+ },
34
+ "codegenConfig": {
35
+ "name": "overlay",
36
+ "type": "modules",
37
+ "jsSrcsDir": "src",
38
+ "android": {
39
+ "javaPackageName": "com.reactnative.overlay"
40
+ },
41
+ "ios": {
42
+ "modulesProvider": {
43
+ "OverlayHost": "RNOverlayModule"
44
+ }
45
+ }
46
+ },
47
+ "peerDependencies": {
48
+ "react": ">=16.8",
49
+ "react-native": ">=0.60"
50
+ },
51
+ "devDependencies": {}
66
52
  }
@@ -0,0 +1,14 @@
1
+ import type { TurboModule, CodegenTypes } from 'react-native';
2
+ import { TurboModuleRegistry } from 'react-native';
3
+
4
+ export interface OverlayOptions {
5
+ overlayId: CodegenTypes.Int32;
6
+ passThroughTouches?: boolean;
7
+ }
8
+
9
+ export interface Spec extends TurboModule {
10
+ show(moduleName: string, options: OverlayOptions): void;
11
+ hide(moduleName: string, overlayId: CodegenTypes.Int32): void;
12
+ }
13
+
14
+ export default TurboModuleRegistry.getEnforcing<Spec>('OverlayHost');
package/src/index.ts CHANGED
@@ -1,29 +1,18 @@
1
- import { Insets, NativeModule, NativeModules } from 'react-native'
2
-
3
- export interface OverlayOptions {
4
- id: number
5
- passThroughTouches?: boolean
6
- }
1
+ import { type Insets } from 'react-native';
2
+ import NativeOverlay, { type OverlayOptions } from './NativeOverlay';
7
3
 
8
4
  export interface OverlayProps extends OverlayOptions {
9
- insets: Insets
5
+ insets: Insets;
10
6
  }
11
7
 
12
- interface OverlayInterface extends NativeModule {
13
- show(moduleName: string, options: OverlayOptions): void
14
- hide(moduleName: string, id: number): void
15
- }
16
-
17
- const OverlayHost: OverlayInterface = NativeModules.OverlayHost
18
-
19
8
  function show(moduleName: string, options: OverlayOptions) {
20
- OverlayHost.show(moduleName, options)
9
+ NativeOverlay.show(moduleName, options);
21
10
  }
22
11
 
23
12
  function hide(moduleName: string, id: number) {
24
- OverlayHost.hide(moduleName, id)
13
+ NativeOverlay.hide(moduleName, id);
25
14
  }
26
15
 
27
- const Overlay = { show, hide }
16
+ const Overlay = { show, hide };
28
17
 
29
- export { Overlay }
18
+ export { Overlay };
@@ -1,60 +0,0 @@
1
- #import "RNOverlay.h"
2
-
3
- #import <React/RCTRootView.h>
4
-
5
- @interface RNOverlay ()
6
-
7
- @property(nonatomic, weak) UIWindow *keyWindow;
8
- @property(nonatomic, strong) RCTRootView *rootView;
9
- @property(nonatomic, copy) NSString *moduleName;
10
- @property(nonatomic, weak) RCTBridge *bridge;
11
-
12
- @end
13
-
14
- @implementation RNOverlay
15
-
16
- - (instancetype)initWithModuleName:(NSString *)moduleName bridge:(RCTBridge *)bridge {
17
- if (self = [super init]) {
18
- _moduleName = moduleName;
19
- _bridge = bridge;
20
- }
21
- return self;
22
- }
23
-
24
- - (void)show:(NSDictionary *)props options:(NSDictionary *)options {
25
- BOOL passThroughTouches = [options[@"passThroughTouches"] boolValue];
26
-
27
- RCTRootView *rctView = [self createReactRootView:props];
28
- rctView.passThroughTouches = passThroughTouches;
29
- rctView.frame = [UIScreen mainScreen].bounds;
30
-
31
- self.rootView = rctView;
32
-
33
- UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
34
- [keyWindow addSubview:rctView];
35
- }
36
-
37
- - (void)hide {
38
- if (self.rootView) {
39
- [self.rootView removeFromSuperview];
40
- self.rootView = nil;
41
- }
42
- }
43
-
44
- - (void)update {
45
- UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
46
- if (keyWindow != self.keyWindow) {
47
- [self.rootView removeFromSuperview];
48
- [keyWindow addSubview:self.rootView];
49
- self.keyWindow = keyWindow;
50
- }
51
- }
52
-
53
- - (RCTRootView *)createReactRootView:(NSDictionary *)props {
54
- RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:self.bridge moduleName:self.moduleName initialProperties:props];
55
- reactView.backgroundColor = UIColor.clearColor;
56
-
57
- return reactView;
58
- }
59
-
60
- @end
@@ -1,89 +0,0 @@
1
- #import "RNOverlayModule.h"
2
- #import "RNOverlay.h"
3
-
4
- #import <React/RCTLog.h>
5
- #import <React/RCTBridge.h>
6
-
7
-
8
- NSString* genKey(NSString* moduleName, NSNumber* id) {
9
- return [NSString stringWithFormat:@"%@-%@", moduleName, id];
10
- }
11
-
12
-
13
- @interface RNOverlayModule ()
14
-
15
- @property(nonatomic, strong) NSMutableDictionary *overlays;
16
-
17
- @end
18
-
19
- @implementation RNOverlayModule
20
-
21
- @synthesize bridge;
22
-
23
- - (instancetype)init {
24
- if (self = [super init]) {
25
- _overlays = [[NSMutableDictionary alloc] init];
26
- }
27
- return self;
28
- }
29
-
30
- - (void)handleReload {
31
- for (NSString *key in self.overlays) {
32
- RNOverlay *overlay = self.overlays[key];
33
- [overlay hide];
34
- }
35
- [self.overlays removeAllObjects];
36
- }
37
-
38
- - (void)invalidate {
39
- [self handleReload];
40
- }
41
-
42
- + (BOOL)requiresMainQueueSetup {
43
- return YES;
44
- }
45
-
46
- - (dispatch_queue_t)methodQueue {
47
- return dispatch_get_main_queue();
48
- }
49
-
50
- RCT_EXPORT_MODULE(OverlayHost)
51
-
52
-
53
- RCT_EXPORT_METHOD(show:(NSString *)moduleName options:(NSDictionary *)options) {
54
- NSString* key = genKey(moduleName, options[@"id"]);
55
- RNOverlay *overlay = self.overlays[key];
56
- if (overlay != nil) {
57
- [overlay update];
58
- return;
59
- }
60
-
61
- overlay = [[RNOverlay alloc] initWithModuleName:moduleName bridge:self.bridge];
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
- };
72
-
73
- NSMutableDictionary *props = [options mutableCopy];
74
- [props setObject:insets forKey:@"insets"];
75
- [overlay show:props options:options];
76
- }
77
-
78
- RCT_EXPORT_METHOD(hide:(NSString *)moduleName id:(nonnull NSNumber *)id) {
79
- NSString* key = genKey(moduleName, id);
80
- RNOverlay *overlay = self.overlays[key];
81
- if (!overlay) {
82
- return;
83
- }
84
- [self.overlays removeObjectForKey:key];
85
- [overlay hide];
86
- }
87
-
88
-
89
- @end
package/lib/index.js DELETED
@@ -1,10 +0,0 @@
1
- import { NativeModules } from 'react-native';
2
- const OverlayHost = NativeModules.OverlayHost;
3
- function show(moduleName, options) {
4
- OverlayHost.show(moduleName, options);
5
- }
6
- function hide(moduleName, id) {
7
- OverlayHost.hide(moduleName, id);
8
- }
9
- const Overlay = { show, hide };
10
- export { Overlay };