@teardown/react-native 1.0.12 → 1.1.0-beta-04
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/dist/components/debugger-ui.d.ts +7 -0
- package/dist/components/debugger-ui.js +147 -0
- package/dist/components/index.js +17 -0
- package/dist/components/teardown-logo.d.ts +4 -0
- package/dist/components/teardown-logo.js +33 -0
- package/dist/containers/index.js +17 -0
- package/dist/containers/teardown.container.d.ts +11 -0
- package/dist/containers/teardown.container.js +13 -0
- package/dist/debugger.d.ts +13 -0
- package/dist/debugger.js +75 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +21 -0
- package/dist/metro/index.d.ts +2 -0
- package/dist/metro/index.js +5 -0
- package/dist/metro-plugin.d.ts +1 -0
- package/dist/metro-plugin.js +45 -0
- package/dist/plugins/http.plugin.d.ts +23 -0
- package/dist/plugins/http.plugin.js +144 -0
- package/{src/plugins/index.ts → dist/plugins/index.d.ts} +0 -1
- package/dist/plugins/index.js +19 -0
- package/dist/plugins/logging.plugin.d.ts +9 -0
- package/dist/plugins/logging.plugin.js +35 -0
- package/dist/plugins/websocket.plugin.d.ts +17 -0
- package/dist/plugins/websocket.plugin.js +102 -0
- package/dist/services/index.js +17 -0
- package/dist/services/teardown.service.d.ts +10 -0
- package/dist/services/teardown.service.js +21 -0
- package/dist/teardown.client.d.ts +44 -0
- package/dist/teardown.client.js +65 -0
- package/package.json +23 -14
- package/src/components/debugger-ui.tsx +0 -237
- package/src/components/teardown-logo.tsx +0 -16
- package/src/containers/teardown.container.tsx +0 -40
- package/src/debugger.ts +0 -72
- package/src/index.ts +0 -5
- package/src/plugins/http.plugin.ts +0 -171
- package/src/plugins/logging.plugin.ts +0 -52
- package/src/plugins/websocket.plugin.ts +0 -130
- package/src/services/teardown.service.ts +0 -27
- package/src/teardown.client.ts +0 -74
- /package/{src/components/index.ts → dist/components/index.d.ts} +0 -0
- /package/{src/containers/index.ts → dist/containers/index.d.ts} +0 -0
- /package/{src/services/index.ts → dist/services/index.d.ts} +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoggingPlugin = void 0;
|
|
4
|
+
const methods = ["log", "warn", "error", "debug", "info"];
|
|
5
|
+
class LoggingPlugin {
|
|
6
|
+
client = null;
|
|
7
|
+
originalConsoleMethods = {};
|
|
8
|
+
createConsoleProxy(method) {
|
|
9
|
+
const original = console[method];
|
|
10
|
+
return new Proxy(original, {
|
|
11
|
+
apply: (target, thisArg, args) => {
|
|
12
|
+
target.apply(thisArg, args);
|
|
13
|
+
this.client?.debugger?.send("CONSOLE_LOG", {
|
|
14
|
+
type: method,
|
|
15
|
+
args,
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
constructor() {
|
|
21
|
+
methods.forEach((method) => {
|
|
22
|
+
this.originalConsoleMethods[method] = console[method];
|
|
23
|
+
console[method] = this.createConsoleProxy(method);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
install(client) {
|
|
27
|
+
this.client = client;
|
|
28
|
+
}
|
|
29
|
+
uninstall() {
|
|
30
|
+
methods.forEach((method) => {
|
|
31
|
+
console[method] = this.originalConsoleMethods[method];
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.LoggingPlugin = LoggingPlugin;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IPlugin, TeardownClient } from "../teardown.client";
|
|
2
|
+
export declare class WebSocketPlugin implements IPlugin {
|
|
3
|
+
private logger;
|
|
4
|
+
private client;
|
|
5
|
+
private sockets;
|
|
6
|
+
constructor();
|
|
7
|
+
install(client: TeardownClient<any>): void;
|
|
8
|
+
private setupWebSocketInterceptor;
|
|
9
|
+
private wsConnectCallback;
|
|
10
|
+
private wsSendCallback;
|
|
11
|
+
private wsOnMessageCallback;
|
|
12
|
+
private wsOnCloseCallback;
|
|
13
|
+
private sendOpenEvent;
|
|
14
|
+
private sendMessageEvent;
|
|
15
|
+
private sendCloseEvent;
|
|
16
|
+
disableInterception(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WebSocketPlugin = void 0;
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
const WebSocketInterceptor_1 = __importDefault(require("react-native/Libraries/WebSocket/WebSocketInterceptor"));
|
|
9
|
+
const logger_1 = require("@teardown/logger");
|
|
10
|
+
const util_1 = require("@teardown/util");
|
|
11
|
+
class WebSocketPlugin {
|
|
12
|
+
logger = new logger_1.Logger("WebSocketPlugin");
|
|
13
|
+
client = null;
|
|
14
|
+
sockets = new Map();
|
|
15
|
+
constructor() {
|
|
16
|
+
this.setupWebSocketInterceptor();
|
|
17
|
+
}
|
|
18
|
+
install(client) {
|
|
19
|
+
this.client = client;
|
|
20
|
+
}
|
|
21
|
+
setupWebSocketInterceptor() {
|
|
22
|
+
if (WebSocketInterceptor_1.default.isInterceptorEnabled()) {
|
|
23
|
+
this.logger.warn("WebSocketInterceptor is already enabled by another library, disable it or run this first when your app loads");
|
|
24
|
+
this.disableInterception();
|
|
25
|
+
}
|
|
26
|
+
WebSocketInterceptor_1.default.setConnectCallback(this.wsConnectCallback);
|
|
27
|
+
WebSocketInterceptor_1.default.setSendCallback(this.wsSendCallback);
|
|
28
|
+
WebSocketInterceptor_1.default.setOnMessageCallback(this.wsOnMessageCallback);
|
|
29
|
+
WebSocketInterceptor_1.default.setOnCloseCallback(this.wsOnCloseCallback);
|
|
30
|
+
WebSocketInterceptor_1.default.enableInterception();
|
|
31
|
+
this.logger.log("WebSocketInterceptor enabled");
|
|
32
|
+
}
|
|
33
|
+
wsConnectCallback = (url, protocols, options, socketId) => {
|
|
34
|
+
const requestId = util_1.Util.generateUUID();
|
|
35
|
+
const socketInfo = {
|
|
36
|
+
id: requestId,
|
|
37
|
+
url,
|
|
38
|
+
protocols,
|
|
39
|
+
timestamp: performance.now(),
|
|
40
|
+
};
|
|
41
|
+
this.sockets.set(socketId, socketInfo);
|
|
42
|
+
this.sendOpenEvent(socketInfo);
|
|
43
|
+
};
|
|
44
|
+
wsSendCallback = (data, socketId) => {
|
|
45
|
+
const socket = this.sockets.get(socketId);
|
|
46
|
+
if (socket) {
|
|
47
|
+
const messageInfo = {
|
|
48
|
+
id: socket.id,
|
|
49
|
+
data: "", // TODO: Currently getting array buffer length errors here when sending data
|
|
50
|
+
timestamp: performance.now(),
|
|
51
|
+
direction: "sent",
|
|
52
|
+
};
|
|
53
|
+
console.log("messageInfo", messageInfo);
|
|
54
|
+
// this.sendMessageEvent(messageInfo);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
wsOnMessageCallback = (socketId, message) => {
|
|
58
|
+
const socket = this.sockets.get(socketId);
|
|
59
|
+
if (socket) {
|
|
60
|
+
const messageInfo = {
|
|
61
|
+
id: socket.id,
|
|
62
|
+
data: "", // TODO: Currently getting array buffer length errors here when sending data
|
|
63
|
+
timestamp: performance.now(),
|
|
64
|
+
direction: "received",
|
|
65
|
+
};
|
|
66
|
+
this.sendMessageEvent(messageInfo);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
wsOnCloseCallback = (socketId, event) => {
|
|
70
|
+
const socket = this.sockets.get(socketId);
|
|
71
|
+
if (socket) {
|
|
72
|
+
const closeInfo = {
|
|
73
|
+
id: socket.id,
|
|
74
|
+
code: event.code,
|
|
75
|
+
reason: event.reason,
|
|
76
|
+
timestamp: performance.now(),
|
|
77
|
+
};
|
|
78
|
+
this.sendCloseEvent(closeInfo);
|
|
79
|
+
this.sockets.delete(socketId);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
sendOpenEvent(info) {
|
|
83
|
+
if (this.client && this.client.debugger) {
|
|
84
|
+
this.client.debugger.send("NETWORK_WEBSOCKET_OPEN", info);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
sendMessageEvent(info) {
|
|
88
|
+
if (this.client && this.client.debugger) {
|
|
89
|
+
this.client.debugger.send("NETWORK_WEBSOCKET_MESSAGE", info);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
sendCloseEvent(info) {
|
|
93
|
+
if (this.client && this.client.debugger) {
|
|
94
|
+
this.client.debugger.send("NETWORK_WEBSOCKET_CLOSE", info);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
disableInterception() {
|
|
98
|
+
WebSocketInterceptor_1.default.disableInterception();
|
|
99
|
+
this.sockets.clear();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.WebSocketPlugin = WebSocketPlugin;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./teardown.service"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PluginTuple, TeardownClient } from "../teardown.client";
|
|
2
|
+
export type TeardownServiceContextType<T extends readonly PluginTuple[]> = {
|
|
3
|
+
client: TeardownClient<T>;
|
|
4
|
+
};
|
|
5
|
+
export declare const TeardownService: {
|
|
6
|
+
Context: import("react").Context<TeardownServiceContextType<any> | null>;
|
|
7
|
+
Provider: import("react").Provider<TeardownServiceContextType<any> | null>;
|
|
8
|
+
useState<T extends readonly PluginTuple[]>(): TeardownServiceContextType<T>;
|
|
9
|
+
useProvidedState<T extends readonly PluginTuple[]>(client: TeardownClient<T>): TeardownServiceContextType<T>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TeardownService = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const Context = (0, react_1.createContext)(null);
|
|
6
|
+
exports.TeardownService = {
|
|
7
|
+
Context,
|
|
8
|
+
Provider: Context.Provider,
|
|
9
|
+
useState() {
|
|
10
|
+
const state = (0, react_1.useContext)(Context);
|
|
11
|
+
if (state == null) {
|
|
12
|
+
throw new Error("TeardownService not found");
|
|
13
|
+
}
|
|
14
|
+
return state;
|
|
15
|
+
},
|
|
16
|
+
useProvidedState(client) {
|
|
17
|
+
return {
|
|
18
|
+
client
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Logger } from "@teardown/logger";
|
|
2
|
+
import { Debugger, type DebuggerOptions } from "./debugger";
|
|
3
|
+
export interface IPlugin {
|
|
4
|
+
install?(client: TeardownClient<any>): void;
|
|
5
|
+
uninstall?(): void;
|
|
6
|
+
}
|
|
7
|
+
export type DefaultPluginOptions<T> = {
|
|
8
|
+
debug?: boolean;
|
|
9
|
+
} & T;
|
|
10
|
+
export type PluginOptions<T> = DefaultPluginOptions<{
|
|
11
|
+
key: string;
|
|
12
|
+
}> & T;
|
|
13
|
+
export declare abstract class Plugin<T = any> {
|
|
14
|
+
protected logger: Logger;
|
|
15
|
+
protected constructor(options: PluginOptions<T>);
|
|
16
|
+
install?(client: TeardownClient<any>): void;
|
|
17
|
+
uninstall?(): void;
|
|
18
|
+
}
|
|
19
|
+
export type PluginTuple = readonly [string, IPlugin];
|
|
20
|
+
type InferPluginFromTuple<T extends PluginTuple> = {
|
|
21
|
+
[K in T[0]]: Omit<T[1], "install" | "uninstall">;
|
|
22
|
+
};
|
|
23
|
+
type InferPluginsFromArray<T extends readonly PluginTuple[]> = UnionToIntersection<InferPluginFromTuple<T[number]>>;
|
|
24
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
25
|
+
export type TeardownClientOptions<T extends readonly PluginTuple[]> = {
|
|
26
|
+
plugins?: T;
|
|
27
|
+
debuggerEnabled?: boolean;
|
|
28
|
+
loggingEnabled?: boolean;
|
|
29
|
+
} & DebuggerOptions;
|
|
30
|
+
export declare class TeardownClient<T extends readonly PluginTuple[]> {
|
|
31
|
+
readonly options?: TeardownClientOptions<T> | undefined;
|
|
32
|
+
logger: Logger;
|
|
33
|
+
debugger: Debugger | null;
|
|
34
|
+
private readonly plugins;
|
|
35
|
+
api: InferPluginsFromArray<T>;
|
|
36
|
+
constructor(options?: TeardownClientOptions<T> | undefined);
|
|
37
|
+
private installPlugin;
|
|
38
|
+
private uninstallPlugin;
|
|
39
|
+
private uninstallAllPlugins;
|
|
40
|
+
private reinstallPlugins;
|
|
41
|
+
shutdown(): void;
|
|
42
|
+
}
|
|
43
|
+
export declare const createTeardownClient: <Plugins extends readonly PluginTuple[]>(plugins: Plugins) => TeardownClient<Plugins>;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTeardownClient = exports.TeardownClient = exports.Plugin = void 0;
|
|
4
|
+
const logger_1 = require("@teardown/logger");
|
|
5
|
+
const debugger_1 = require("./debugger");
|
|
6
|
+
class Plugin {
|
|
7
|
+
logger;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.logger = new logger_1.Logger(options.key, options.debug ?? false);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.Plugin = Plugin;
|
|
13
|
+
class TeardownClient {
|
|
14
|
+
options;
|
|
15
|
+
logger;
|
|
16
|
+
debugger;
|
|
17
|
+
plugins = new Map();
|
|
18
|
+
api = {};
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.options = options;
|
|
21
|
+
this.logger = new logger_1.Logger("TeardownClient", options?.loggingEnabled ?? false);
|
|
22
|
+
const debuggerEnabled = options?.debuggerEnabled ?? __DEV__;
|
|
23
|
+
this.debugger = debuggerEnabled ? new debugger_1.Debugger(options) : null;
|
|
24
|
+
options?.plugins?.forEach(([key, plugin]) => {
|
|
25
|
+
this.plugins.set(key, plugin);
|
|
26
|
+
});
|
|
27
|
+
this.installPlugin();
|
|
28
|
+
}
|
|
29
|
+
installPlugin() {
|
|
30
|
+
this.logger.log("Installing plugins");
|
|
31
|
+
this.plugins.forEach((plugin, key) => {
|
|
32
|
+
plugin.install?.(this);
|
|
33
|
+
this.api[key] = plugin;
|
|
34
|
+
});
|
|
35
|
+
this.logger.log("Plugins installed");
|
|
36
|
+
}
|
|
37
|
+
uninstallPlugin(key) {
|
|
38
|
+
const plugin = this.plugins.get(key);
|
|
39
|
+
if (plugin) {
|
|
40
|
+
plugin.uninstall?.();
|
|
41
|
+
this.plugins.delete(key);
|
|
42
|
+
delete this.api[key];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
uninstallAllPlugins() {
|
|
46
|
+
this.plugins.forEach((_, key) => this.uninstallPlugin(key));
|
|
47
|
+
}
|
|
48
|
+
reinstallPlugins() {
|
|
49
|
+
this.uninstallAllPlugins();
|
|
50
|
+
this.installPlugin();
|
|
51
|
+
}
|
|
52
|
+
shutdown() {
|
|
53
|
+
this.uninstallAllPlugins();
|
|
54
|
+
this.debugger?.shutdown();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.TeardownClient = TeardownClient;
|
|
58
|
+
const createTeardownClient = (plugins) => {
|
|
59
|
+
return new TeardownClient({
|
|
60
|
+
loggingEnabled: true,
|
|
61
|
+
debuggerEnabled: true,
|
|
62
|
+
plugins,
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
exports.createTeardownClient = createTeardownClient;
|
package/package.json
CHANGED
|
@@ -1,28 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teardown/react-native",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0-beta-04",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "./src/index.ts",
|
|
6
|
-
"module": "./src/index.ts",
|
|
7
|
-
"types": "./src/index.ts",
|
|
8
5
|
"scripts": {
|
|
9
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
+
"build": "tsc",
|
|
8
|
+
"dev": "tsc --declaration --watch"
|
|
10
9
|
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
11
12
|
"files": [
|
|
12
13
|
"README.md",
|
|
13
|
-
"
|
|
14
|
+
"dist/**/*"
|
|
14
15
|
],
|
|
15
16
|
"dependencies": {
|
|
16
|
-
"@teardown/logger": "
|
|
17
|
-
"@teardown/util": "
|
|
18
|
-
"@teardown/websocket": "
|
|
17
|
+
"@teardown/logger": "^1.1.0-beta-04",
|
|
18
|
+
"@teardown/util": "^1.1.0-beta-04",
|
|
19
|
+
"@teardown/websocket": "^1.1.0-beta-04"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
|
21
|
-
"@types/react": "^18.3.
|
|
22
|
+
"@types/react": "^18.3.1",
|
|
23
|
+
"@types/react-native": "^0.73.0",
|
|
24
|
+
"metro-config": "^0.81.0",
|
|
22
25
|
"react": "^18.3.1",
|
|
23
|
-
"react-native": "^0.
|
|
24
|
-
"react-native-
|
|
25
|
-
"react-native-
|
|
26
|
-
"
|
|
26
|
+
"react-native": "^0.75.4",
|
|
27
|
+
"react-native-device-info": "^14.0.0",
|
|
28
|
+
"react-native-gesture-handler": "^2.20.0",
|
|
29
|
+
"typescript": "^5.6.3"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": "^18",
|
|
33
|
+
"react-native": "^0.75",
|
|
34
|
+
"react-native-device-info": "^14",
|
|
35
|
+
"react-native-gesture-handler": "^2"
|
|
27
36
|
}
|
|
28
37
|
}
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import {FunctionComponent, useEffect, useRef, useState} from 'react';
|
|
2
|
-
import {DevSettings, Pressable, StyleSheet, Text, View, ViewStyle,} from 'react-native';
|
|
3
|
-
import {EdgeInsets, useSafeAreaInsets} from 'react-native-safe-area-context';
|
|
4
|
-
import {TeardownLogo} from './teardown-logo';
|
|
5
|
-
import {GestureHandlerRootView} from 'react-native-gesture-handler';
|
|
6
|
-
import {
|
|
7
|
-
BottomSheet,
|
|
8
|
-
BottomSheetCloseIcon,
|
|
9
|
-
BottomSheetContent,
|
|
10
|
-
BottomSheetHandleProps,
|
|
11
|
-
BottomSheetHeader,
|
|
12
|
-
BottomSheetModalProvider,
|
|
13
|
-
BottomSheetTitle,
|
|
14
|
-
BottomSheetView,
|
|
15
|
-
Button
|
|
16
|
-
} from '@teardown/react-native-ui';
|
|
17
|
-
import {TeardownService} from "../services/teardown.service";
|
|
18
|
-
import {DebuggerStatus} from "../debugger";
|
|
19
|
-
|
|
20
|
-
export type DebuggerUiPosition =
|
|
21
|
-
| 'top-left'
|
|
22
|
-
| 'top-right'
|
|
23
|
-
| 'bottom-left'
|
|
24
|
-
| 'bottom-right'
|
|
25
|
-
| 'center-left'
|
|
26
|
-
| 'center-right';
|
|
27
|
-
|
|
28
|
-
export type DebuggerUiOptions = {
|
|
29
|
-
enabled?: boolean;
|
|
30
|
-
position?: DebuggerUiPosition;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const DebuggerUi: FunctionComponent<DebuggerUiOptions> = props => {
|
|
34
|
-
const {enabled = true} = props;
|
|
35
|
-
|
|
36
|
-
return null;
|
|
37
|
-
|
|
38
|
-
if (!__DEV__) {
|
|
39
|
-
// never render the debugger ui in any mode apart from __DEV__ == true "development"
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const isNotEnabled = !enabled;
|
|
44
|
-
|
|
45
|
-
if (isNotEnabled) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return <DebuggerUiEnabled {...props} />;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const DebuggerUiEnabled: FunctionComponent<DebuggerUiOptions> = props => {
|
|
53
|
-
const {position} = props;
|
|
54
|
-
|
|
55
|
-
const safeAreaInsets = useSafeAreaInsets();
|
|
56
|
-
const bottomSheetRef = useRef<BottomSheet>(null);
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<>
|
|
60
|
-
<View style={styles.container} pointerEvents={'box-none'}>
|
|
61
|
-
<GestureHandlerRootView>
|
|
62
|
-
<BottomSheetModalProvider>
|
|
63
|
-
<Pressable
|
|
64
|
-
onPress={() => {
|
|
65
|
-
// bottomSheetRef.current?.snapToIndex(0);
|
|
66
|
-
}}
|
|
67
|
-
style={[
|
|
68
|
-
styles.orb,
|
|
69
|
-
getOrbPosition(safeAreaInsets, position ?? 'center-right'),
|
|
70
|
-
]}>
|
|
71
|
-
<TeardownLogo height={20} width={20} />
|
|
72
|
-
</Pressable>
|
|
73
|
-
|
|
74
|
-
<BottomSheet
|
|
75
|
-
sheetRef={bottomSheetRef}
|
|
76
|
-
handleComponent={handleProps => (
|
|
77
|
-
<DebuggerStatusHandleComponent {...handleProps} />
|
|
78
|
-
)}>
|
|
79
|
-
<BottomSheetCloseIcon />
|
|
80
|
-
<BottomSheetView
|
|
81
|
-
className={''}
|
|
82
|
-
style={{
|
|
83
|
-
paddingBottom: safeAreaInsets.bottom + 16,
|
|
84
|
-
}}>
|
|
85
|
-
<BottomSheetHeader>
|
|
86
|
-
<BottomSheetTitle>Debugger</BottomSheetTitle>
|
|
87
|
-
</BottomSheetHeader>
|
|
88
|
-
<BottomSheetContent>
|
|
89
|
-
<Button
|
|
90
|
-
onPress={() => {
|
|
91
|
-
DevSettings.reload('Teardown reconnect');
|
|
92
|
-
}}>
|
|
93
|
-
Reconnect debugger
|
|
94
|
-
</Button>
|
|
95
|
-
</BottomSheetContent>
|
|
96
|
-
</BottomSheetView>
|
|
97
|
-
</BottomSheet>
|
|
98
|
-
</BottomSheetModalProvider>
|
|
99
|
-
</GestureHandlerRootView>
|
|
100
|
-
|
|
101
|
-
{/*<View style={styles.half_height}>*/}
|
|
102
|
-
{/* */}
|
|
103
|
-
{/*</View>*/}
|
|
104
|
-
</View>
|
|
105
|
-
</>
|
|
106
|
-
);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const DebuggerStatusHandleComponent: FunctionComponent<
|
|
110
|
-
BottomSheetHandleProps
|
|
111
|
-
> = () => {
|
|
112
|
-
const {client} = TeardownService.useState();
|
|
113
|
-
|
|
114
|
-
const [debuggerStatus, setDebuggerStatus] = useState<DebuggerStatus | null>(
|
|
115
|
-
client.debugger?.getStatus() ?? null,
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
useEffect(() => {
|
|
119
|
-
const listener = client.debugger?.emitter.on("CONNECTION_STATUS_CHANGED", (event) => {
|
|
120
|
-
const { payload } = event;
|
|
121
|
-
setDebuggerStatus(event.payload.status);
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
return () => {
|
|
125
|
-
listener?.remove();
|
|
126
|
-
};
|
|
127
|
-
}, [client]);
|
|
128
|
-
|
|
129
|
-
return (
|
|
130
|
-
<View
|
|
131
|
-
style={[
|
|
132
|
-
{
|
|
133
|
-
backgroundColor: getColorForDebuggerStatus(
|
|
134
|
-
debuggerStatus,
|
|
135
|
-
),
|
|
136
|
-
},
|
|
137
|
-
styles.debugger_status,
|
|
138
|
-
]}>
|
|
139
|
-
<Text style={styles.debugger_status_text}>{debuggerStatus}</Text>
|
|
140
|
-
</View>
|
|
141
|
-
);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const styles = StyleSheet.create({
|
|
145
|
-
debugger_status: {
|
|
146
|
-
flex: 1,
|
|
147
|
-
borderTopLeftRadius: 15,
|
|
148
|
-
borderTopRightRadius: 15,
|
|
149
|
-
padding: 4,
|
|
150
|
-
},
|
|
151
|
-
debugger_status_text: {
|
|
152
|
-
color: 'white',
|
|
153
|
-
fontSize: 12,
|
|
154
|
-
textAlign: 'center',
|
|
155
|
-
fontWeight: 'bold',
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
container: {
|
|
159
|
-
...StyleSheet.absoluteFillObject,
|
|
160
|
-
backgroundColor: 'white',
|
|
161
|
-
},
|
|
162
|
-
orb: {
|
|
163
|
-
height: 40,
|
|
164
|
-
width: 40,
|
|
165
|
-
backgroundColor: 'hsl(240 5% 6%)',
|
|
166
|
-
borderRadius: 40,
|
|
167
|
-
position: 'absolute',
|
|
168
|
-
justifyContent: 'center',
|
|
169
|
-
alignItems: 'center',
|
|
170
|
-
},
|
|
171
|
-
half_height: {
|
|
172
|
-
height: '50%',
|
|
173
|
-
backgroundColor: '#e1e1e1',
|
|
174
|
-
position: 'absolute',
|
|
175
|
-
left: 0,
|
|
176
|
-
right: 0,
|
|
177
|
-
bottom: 0,
|
|
178
|
-
},
|
|
179
|
-
logo: {
|
|
180
|
-
height: 20,
|
|
181
|
-
width: 20,
|
|
182
|
-
},
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
const getColorForDebuggerStatus = (status: DebuggerStatus | null) => {
|
|
186
|
-
switch (status) {
|
|
187
|
-
case 'CONNECTING':
|
|
188
|
-
return 'yellow';
|
|
189
|
-
case 'CONNECTED':
|
|
190
|
-
return 'green';
|
|
191
|
-
case 'DISCONNECTED':
|
|
192
|
-
return 'red';
|
|
193
|
-
case 'FAILED':
|
|
194
|
-
return 'red';
|
|
195
|
-
default:
|
|
196
|
-
return 'gray';
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
const getOrbPosition = (
|
|
201
|
-
edgeInsets: EdgeInsets,
|
|
202
|
-
position: DebuggerUiPosition,
|
|
203
|
-
): ViewStyle => {
|
|
204
|
-
const DEFAULT_PADDING = 16;
|
|
205
|
-
switch (position) {
|
|
206
|
-
case 'top-left':
|
|
207
|
-
return {
|
|
208
|
-
top: DEFAULT_PADDING + edgeInsets.top,
|
|
209
|
-
left: DEFAULT_PADDING,
|
|
210
|
-
};
|
|
211
|
-
case 'top-right':
|
|
212
|
-
return {
|
|
213
|
-
top: DEFAULT_PADDING + edgeInsets.top,
|
|
214
|
-
right: DEFAULT_PADDING,
|
|
215
|
-
};
|
|
216
|
-
case 'bottom-left':
|
|
217
|
-
return {
|
|
218
|
-
bottom: DEFAULT_PADDING + edgeInsets.bottom,
|
|
219
|
-
left: DEFAULT_PADDING,
|
|
220
|
-
};
|
|
221
|
-
case 'bottom-right':
|
|
222
|
-
return {
|
|
223
|
-
bottom: DEFAULT_PADDING + edgeInsets.bottom,
|
|
224
|
-
right: DEFAULT_PADDING,
|
|
225
|
-
};
|
|
226
|
-
case 'center-left':
|
|
227
|
-
return {
|
|
228
|
-
top: '50%',
|
|
229
|
-
left: DEFAULT_PADDING,
|
|
230
|
-
};
|
|
231
|
-
case 'center-right':
|
|
232
|
-
return {
|
|
233
|
-
top: '50%',
|
|
234
|
-
right: DEFAULT_PADDING,
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// import type {FunctionComponent} from 'react';
|
|
2
|
-
// import Svg, {Path, SvgProps} from "react-native-svg";
|
|
3
|
-
//
|
|
4
|
-
// export type TeardownLogoProps = SvgProps
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// export const TeardownLogo: FunctionComponent<TeardownLogoProps> = (props) => {
|
|
8
|
-
// const {} = props;
|
|
9
|
-
// return (
|
|
10
|
-
// <Svg width="350" height="350" viewBox="0 0 350 350" fill="none" {...props}>
|
|
11
|
-
// <Path fillRule="evenodd" clipRule="evenodd"
|
|
12
|
-
// d="M175.09 345L300 218.574L256.859 174.909L299.821 131.426L174.91 5.00001L50 131.426L93.141 175.091L50.179 218.574L175.09 345ZM114.879 197.093L93.656 218.574L175.09 300.995L256.523 218.574L235.12 196.911L174.91 257.853L114.879 197.093ZM213.382 174.909L174.91 213.848L136.618 175.091L175.09 136.152L213.382 174.909ZM235.12 152.907L175.09 92.147L114.879 153.089L93.477 131.426L174.91 49.005L256.344 131.426L235.12 152.907Z"
|
|
13
|
-
// fill="white"/>
|
|
14
|
-
// </Svg>
|
|
15
|
-
// );
|
|
16
|
-
// }
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import {FunctionComponent, PropsWithChildren} from 'react';
|
|
2
|
-
import {PluginTuple, TeardownClient} from '../teardown.client';
|
|
3
|
-
import {DebuggerUiOptions} from '../components/debugger-ui';
|
|
4
|
-
import {SafeAreaProvider} from 'react-native-safe-area-context';
|
|
5
|
-
|
|
6
|
-
export type TeardownContainerOptions = {
|
|
7
|
-
debugger: DebuggerUiOptions;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type TeardownContainerProps<T extends readonly PluginTuple[]> = PropsWithChildren<{
|
|
11
|
-
client: TeardownClient<T>;
|
|
12
|
-
options?: TeardownContainerOptions;
|
|
13
|
-
}>;
|
|
14
|
-
|
|
15
|
-
export const TeardownContainer: FunctionComponent<
|
|
16
|
-
TeardownContainerProps<any>
|
|
17
|
-
> = props => {
|
|
18
|
-
const {children, client, options} = props;
|
|
19
|
-
|
|
20
|
-
// const providedState = TeardownService.useProvidedState(client);
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<>
|
|
24
|
-
{children}
|
|
25
|
-
</>
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<SafeAreaProvider className={"flex-1 bg-white"}>
|
|
30
|
-
{/*<GestureHandlerRootView>*/}
|
|
31
|
-
{/* <BottomSheetModalProvider> /!* TODO: Move this into a theme provider/package *!/*/}
|
|
32
|
-
{/* <TeardownService.Provider value={providedState}>*/}
|
|
33
|
-
{/* {children}*/}
|
|
34
|
-
{/* <DebuggerUi {...options?.debugger} />*/}
|
|
35
|
-
{/* </TeardownService.Provider>*/}
|
|
36
|
-
{/* </BottomSheetModalProvider>*/}
|
|
37
|
-
{/*</GestureHandlerRootView>*/}
|
|
38
|
-
</SafeAreaProvider>
|
|
39
|
-
);
|
|
40
|
-
};
|