wovvmap-webview-bridge 1.0.0 → 1.0.1
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 +126 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# 📱 Native Integration Guide – wovvmap-webview-bridge
|
|
2
|
+
|
|
3
|
+
This guide explains how to use the `wovvmap-webview-bridge` package **from the React Native side**. This package helps you send data to a WebView and listen for data coming from the WebView.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ✅ Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install wovvmap-webview-bridge
|
|
11
|
+
# or
|
|
12
|
+
yarn add wovvmap-webview-bridge
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 🔌 Setup WebView
|
|
18
|
+
|
|
19
|
+
Import and use the `<WebViewScreen />` component provided by the package:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import React from 'react';
|
|
23
|
+
import { View } from 'react-native';
|
|
24
|
+
import { WebViewScreen } from 'wovvmap-webview-bridge';
|
|
25
|
+
|
|
26
|
+
export default function App() {
|
|
27
|
+
return (
|
|
28
|
+
<View style={{ flex: 1 }}>
|
|
29
|
+
<WebViewScreen url="http://localhost:5173/map" />
|
|
30
|
+
</View>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 📤 Send Data to WebView
|
|
38
|
+
|
|
39
|
+
You can send navigation data (e.g. from, to, elevator, escalator) using `sendToWeb`:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { sendToWeb } from 'wovvmap-webview-bridge';
|
|
43
|
+
|
|
44
|
+
sendToWeb({
|
|
45
|
+
type: "setNavigationData",
|
|
46
|
+
payload: {
|
|
47
|
+
from: "store1",
|
|
48
|
+
to: "store9",
|
|
49
|
+
elevator: false,
|
|
50
|
+
escalator: true,
|
|
51
|
+
floor : 1
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 📥 Receive Events from WebView
|
|
59
|
+
|
|
60
|
+
Use `registerBridgeHandler` to listen for events sent from the web:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { registerBridgeHandler } from 'wovvmap-webview-bridge';
|
|
64
|
+
|
|
65
|
+
registerBridgeHandler("pathData", (points) => {
|
|
66
|
+
console.log("📍 Received pathData:", points);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
registerBridgeHandler("PathFindingResult", (result) => {
|
|
70
|
+
console.log("🧭 Path result:", result);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
registerBridgeHandler("changeFloor", (floor) => {
|
|
74
|
+
console.log("🏢 Web requested floor change:", floor);
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 🧠 Data Types
|
|
81
|
+
|
|
82
|
+
The bridge handles these types safely:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
type SendToWebMessage = {
|
|
86
|
+
type: "setNavigationData";
|
|
87
|
+
payload: {
|
|
88
|
+
from?: string;
|
|
89
|
+
to?: string;
|
|
90
|
+
elevator?: boolean;
|
|
91
|
+
escalator?: boolean;
|
|
92
|
+
floor?: boolean;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## 💡 Tips
|
|
100
|
+
|
|
101
|
+
- All bridge messages are serialized using `JSON.stringify`. Avoid non-serializable data like Maps or circular references.
|
|
102
|
+
- WebView must have messaging enabled (already done in `<WebViewScreen />`).
|
|
103
|
+
- You can directly access the `webviewRef` if needed.
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { webviewRef } from 'wovvmap-webview-bridge';
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## 📄 Summary of Exports (Native Side)
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import {
|
|
115
|
+
WebViewScreen,
|
|
116
|
+
sendToWeb,
|
|
117
|
+
webviewRef,
|
|
118
|
+
registerBridgeHandler,
|
|
119
|
+
} from 'wovvmap-webview-bridge';
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## 📘 Done!
|
|
125
|
+
|
|
126
|
+
You're now ready to communicate seamlessly between React Native and your WebView 🎉
|