wovvmap-webview-bridge 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/README.md +0 -0
- package/dist/index.js +3 -0
- package/index.ts +8 -0
- package/package.json +21 -0
- package/src/handlers/WebBridgeHandlers.ts +69 -0
- package/src/types/BridgeMessage.ts +68 -0
- package/src/types/NodePoint.ts +53 -0
- package/src/types/PathFindingResult.ts +10 -0
- package/src/webviewBridge/WebViewBridgeRef.ts +15 -0
- package/src/webviewBridge/WebViewScreen.tsx +31 -0
package/README.md
ADDED
|
File without changes
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { WebViewScreen } from './src/webviewBridge/WebViewScreen';
|
|
2
|
+
export { sendToWeb, webviewRef } from './src/webviewBridge/WebViewBridgeRef';
|
|
3
|
+
export { bridgeMessageStore, eventHandlers, handleBridgeMessage, registerBridgeHandler } from './src/handlers/WebBridgeHandlers';
|
package/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { WebViewScreen } from './src/webviewBridge/WebViewScreen';
|
|
2
|
+
export { sendToWeb, webviewRef } from './src/webviewBridge/WebViewBridgeRef';
|
|
3
|
+
export { PathFindingResult } from './src/types/PathFindingResult';
|
|
4
|
+
export { NavigationInstruction, SerializablePoint2D, SerializableNodePoint } from './src/types/NodePoint';
|
|
5
|
+
export { NodePointOuterFiled, Point3D, NodeLineOuterFiled, SendToWebMessage } from './src/types/BridgeMessage';
|
|
6
|
+
export { bridgeMessageStore, eventHandlers, handleBridgeMessage, registerBridgeHandler } from './src/handlers/WebBridgeHandlers';
|
|
7
|
+
export { EventHandlerMap } from './src/handlers/WebBridgeHandlers';
|
|
8
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wovvmap-webview-bridge",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"src",
|
|
8
|
+
"index.ts"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc "
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"react": "^19.1.0",
|
|
15
|
+
"react-native": "^0.80.1",
|
|
16
|
+
"react-native-webview": "^13.15.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/react": "^19.1.8"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { WebViewMessageEvent } from "react-native-webview";
|
|
2
|
+
import type { BridgeMessage, NodeLineOuterFiled, NodePointOuterFiled } from "../types/BridgeMessage";
|
|
3
|
+
import { SerializableNodePoint } from "../types/NodePoint";
|
|
4
|
+
import { PathFindingResult } from "../types/PathFindingResult";
|
|
5
|
+
import { SerializableNodePoint as NodePoint, SerializablePoint2D as Point2D } from "../types/NodePoint";
|
|
6
|
+
|
|
7
|
+
// ✅ 1. Event handler map
|
|
8
|
+
export type EventHandlerMap = {
|
|
9
|
+
floor?: (floor: number) => void;
|
|
10
|
+
pathData?: (val: NodePoint[]) => void;
|
|
11
|
+
PathFindingResult?: (val: PathFindingResult) => void;
|
|
12
|
+
searchTextResult?: (val: NodePoint[]) => void;
|
|
13
|
+
shapeZoomAndSelect?: (val: NodePoint | undefined) => void;
|
|
14
|
+
searchablePoints?: (val: NodePoint[]) => void;
|
|
15
|
+
nodePoint?: (val: { [key: string]: NodePointOuterFiled }) => void;
|
|
16
|
+
nodeline?: (val: { [key: string]: NodeLineOuterFiled }) => void;
|
|
17
|
+
categoryList?: (val: { [key: string]: NodePoint }) => void;
|
|
18
|
+
floorInfo?: (val: {
|
|
19
|
+
floors: {
|
|
20
|
+
index: number;
|
|
21
|
+
shortName: string;
|
|
22
|
+
fullName: string;
|
|
23
|
+
floorNumber: number;
|
|
24
|
+
}[];
|
|
25
|
+
defaultFloorIndex: number;
|
|
26
|
+
}) => void;
|
|
27
|
+
to?: (val: string) => void;
|
|
28
|
+
from?: (val: string) => void;
|
|
29
|
+
elevator?: (val: "true" | "false") => void;
|
|
30
|
+
escalator?: (val: "true" | "false") => void;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// ✅ 2. Global handler storage
|
|
34
|
+
export const eventHandlers: Partial<EventHandlerMap> = {};
|
|
35
|
+
|
|
36
|
+
// ✅ 3. Runtime key-value store for all event data
|
|
37
|
+
export const bridgeMessageStore: Partial<Record<keyof EventHandlerMap, any>> = {};
|
|
38
|
+
|
|
39
|
+
// ✅ 4. Register handler function
|
|
40
|
+
export const registerBridgeHandler = <K extends keyof EventHandlerMap>(
|
|
41
|
+
type: K,
|
|
42
|
+
handler: EventHandlerMap[K]
|
|
43
|
+
) => {
|
|
44
|
+
eventHandlers[type] = handler;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// ✅ 5. Main bridge handler
|
|
48
|
+
export const handleBridgeMessage = (
|
|
49
|
+
event: WebViewMessageEvent,
|
|
50
|
+
) => {
|
|
51
|
+
try {
|
|
52
|
+
const data: BridgeMessage = JSON.parse(event.nativeEvent.data);
|
|
53
|
+
|
|
54
|
+
if (data.type === "event") {
|
|
55
|
+
const key = data.key as keyof EventHandlerMap;
|
|
56
|
+
const fn = eventHandlers[key];
|
|
57
|
+
|
|
58
|
+
// ✅ Store latest data in bridgeMessageStore
|
|
59
|
+
bridgeMessageStore[key] = data.value;
|
|
60
|
+
// ✅ Call handler if available
|
|
61
|
+
// @ts-expect-error safe
|
|
62
|
+
fn?.(data.value);
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.error("WebView message error:", e);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Shared types
|
|
2
|
+
|
|
3
|
+
import { SerializableNodePoint as NodePoint, SerializablePoint2D as Point2D } from "./NodePoint";
|
|
4
|
+
import { PathFindingResult } from "./PathFindingResult";
|
|
5
|
+
|
|
6
|
+
export interface NodePointOuterFiled {
|
|
7
|
+
point: NodePoint, name: string, x: number, y: number, z: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export interface Point3D extends Point2D {
|
|
12
|
+
z: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export interface NodeLineOuterFiled {
|
|
17
|
+
a: Point3D; b: Point3D;
|
|
18
|
+
distance: number;
|
|
19
|
+
pointA: NodePoint;
|
|
20
|
+
pointB: NodePoint;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export type BridgeMessage =
|
|
26
|
+
| { type: "event"; key: "floor"; value: number }
|
|
27
|
+
| { type: "event"; key: "pathData"; value: NodePoint[] }
|
|
28
|
+
| { type: "event"; key: "PathFindingResult"; value: PathFindingResult }
|
|
29
|
+
| { type: "event"; key: "searchTextResult"; value: NodePoint[] }
|
|
30
|
+
| { type: "event"; key: "shapeZoomAndSelect"; value: NodePoint | undefined }
|
|
31
|
+
| { type: "event"; key: "searchablePoints"; value: NodePoint[] }
|
|
32
|
+
| { type: "event"; key: "nodePoint"; value: {[key:string]: NodePointOuterFiled} }
|
|
33
|
+
| { type: "event"; key: "nodeline"; value: {[key:string]: NodeLineOuterFiled} }
|
|
34
|
+
| { type: "event"; key: "categoryList"; value: { [key: string]: NodePoint } }
|
|
35
|
+
| {
|
|
36
|
+
type: "event"; key: "floorInfo"; value: {
|
|
37
|
+
floors: {
|
|
38
|
+
index: number;
|
|
39
|
+
shortName: string;
|
|
40
|
+
fullName: string;
|
|
41
|
+
floorNumber: number;
|
|
42
|
+
}[],
|
|
43
|
+
defaultFloorIndex: number
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
| { type: "event"; key: "to"; value:string}
|
|
47
|
+
| { type: "event"; key: "from"; value:string}
|
|
48
|
+
| { type: "event"; key: "elevator"; value:"true" | "false"}
|
|
49
|
+
| { type: "event"; key: "escalator"; value:"true" | "false"}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
export type SendToWebMessage =
|
|
56
|
+
| {
|
|
57
|
+
type: "setNavigationData";
|
|
58
|
+
payload: {
|
|
59
|
+
from?: string;
|
|
60
|
+
to?: string;
|
|
61
|
+
elevator?: boolean;
|
|
62
|
+
escalator?: boolean;
|
|
63
|
+
floor?: number;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
| {
|
|
67
|
+
type: "condtiotion"; // 👈 you had this as example
|
|
68
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// src/types/NodePoint.ts
|
|
2
|
+
|
|
3
|
+
export type NavigationInstruction =
|
|
4
|
+
| "left"
|
|
5
|
+
| "right"
|
|
6
|
+
| "startPoint"
|
|
7
|
+
| "endPoint"
|
|
8
|
+
| "Take Elevator"
|
|
9
|
+
| "Take Escalator"
|
|
10
|
+
| "Exit Elevator"
|
|
11
|
+
| "Exit Escalator"
|
|
12
|
+
| null;
|
|
13
|
+
|
|
14
|
+
export type SerializablePoint2D = {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type SerializableNodePoint = {
|
|
20
|
+
x?: number;
|
|
21
|
+
y?: number;
|
|
22
|
+
z?: number;
|
|
23
|
+
targetDist?: number;
|
|
24
|
+
close?: boolean;
|
|
25
|
+
elementTag?: string;
|
|
26
|
+
type?: string;
|
|
27
|
+
LeaseType?: string;
|
|
28
|
+
Category?: string;
|
|
29
|
+
color?: string;
|
|
30
|
+
Description?: string;
|
|
31
|
+
shape?: SerializablePoint2D[];
|
|
32
|
+
key?: string;
|
|
33
|
+
myAngle?: number;
|
|
34
|
+
NavigationInstruction?: NavigationInstruction;
|
|
35
|
+
distanceToNextPoint: number;
|
|
36
|
+
stepsToNextPoint: number;
|
|
37
|
+
floorBash?: boolean;
|
|
38
|
+
brand_Id?: string | null;
|
|
39
|
+
|
|
40
|
+
LocationName?: {
|
|
41
|
+
text?: string;
|
|
42
|
+
textColor?: string;
|
|
43
|
+
textSize?: string;
|
|
44
|
+
rotate?: number;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
colleague?: {
|
|
48
|
+
name: string;
|
|
49
|
+
role?: string;
|
|
50
|
+
}[];
|
|
51
|
+
|
|
52
|
+
// NOTE: shapeMesh, texture, THREE.Vector3 are removed
|
|
53
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createRef } from "react";
|
|
2
|
+
import type { WebView } from "react-native-webview";
|
|
3
|
+
import type { SendToWebMessage } from "../types/BridgeMessage";
|
|
4
|
+
|
|
5
|
+
// Shared WebView ref
|
|
6
|
+
export const webviewRef = createRef<WebView>();
|
|
7
|
+
|
|
8
|
+
// Exported send function
|
|
9
|
+
export const sendToWeb = (data: SendToWebMessage) => {
|
|
10
|
+
if (webviewRef.current) {
|
|
11
|
+
webviewRef.current.postMessage(JSON.stringify(data));
|
|
12
|
+
} else {
|
|
13
|
+
console.warn("WebView not ready yet");
|
|
14
|
+
}
|
|
15
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from "react";
|
|
2
|
+
import { WebView } from "react-native-webview";
|
|
3
|
+
import { handleBridgeMessage, registerBridgeHandler } from "../handlers/WebBridgeHandlers";
|
|
4
|
+
import type { BridgeMessage } from "../types/BridgeMessage";
|
|
5
|
+
import { webviewRef } from "./WebViewBridgeRef";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
url: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export const WebViewScreen = ({ url }: Props) => {
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const onMessage = (event: any) => {
|
|
17
|
+
console.log("on message event",event);
|
|
18
|
+
handleBridgeMessage(event);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<WebView
|
|
25
|
+
ref={webviewRef} // ✅ bind shared ref
|
|
26
|
+
source={{ uri: url }}
|
|
27
|
+
onMessage={onMessage}
|
|
28
|
+
style={{ flex: 1 }}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
};
|