Skip to content

Commit 99736e0

Browse files
committed
feat: 🎸 ios
1 parent 6eb4704 commit 99736e0

File tree

10 files changed

+27
-65
lines changed

10 files changed

+27
-65
lines changed

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99

1010
# Files
1111
.eslintcache
12+
13+
/build

‎README.md‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
Native inject global function into browser:
88

9-
- iOS: window.webkit.messageHandlers.nativeApp.postMessage
10-
- Android: window.nativeApp.sendToNative
9+
- nativeBridge?.sendMessage
1110

1211
### Native -> Web
1312

@@ -70,21 +69,3 @@ setTimeout(() => {
7069
webApp.callBack(eventId, params);
7170
});
7271
```
73-
74-
## Preview
75-
76-
- [online examples](https://0x0006e.github.io/Hybrid-JS-SDK/examples/dist/)
77-
78-
```bash
79-
git clone https://github.com/0x0006e/Hybrid-JS-SDK.git
80-
cd Hybrid-JS-SDK/examples
81-
yarn && yarn start
82-
```
83-
84-
## TODO
85-
86-
- [ ] tests
87-
88-
## Others
89-
90-
- PR thanks!

‎examples/dist/main.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/src/index.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import simulator from "../../build/simulator";
1+
// import simulator from "../../build/simulator";
22
import { log } from "./util";
33

44
log("native inject js into webview");
5-
simulator();
5+
// simulator();
66

77
log("web page import hybrid js sdk");
88
import hybrid from "../../build";

‎package.json‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,16 @@
2828
"url": "https://github.com/0x0006e/Hybrid-JS-SDK/issues"
2929
},
3030
"homepage": "https://github.com/0x0006e/Hybrid-JS-SDK#readme",
31-
"dependencies": {
32-
"typescript": "^5.8.3",
33-
"uuid": "^3.3.2"
34-
},
3531
"devDependencies": {
3632
"@commitlint/cli": "^8.3.5",
3733
"@commitlint/config-conventional": "^8.3.4",
3834
"@types/node": "^13.7.7",
3935
"@types/uuid": "^7.0.0",
4036
"cz-conventional-changelog": "^3.2.0",
4137
"husky": "^4.2.5",
42-
"standard-version": "^8.0.0"
38+
"standard-version": "^8.0.0",
39+
"typescript": "^4.9.5",
40+
"uuid": "^3.3.2"
4341
},
4442
"directories": {
4543
"example": "examples",

‎src/core/Adaper.ts‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,12 @@ class Adapter {
1212
params?: T;
1313
};
1414
}) {
15-
const postMessage =
16-
global?.webkit?.messageHandlers?.nativeApp?.postMessage;
17-
18-
const sendToNative = global?.nativeApp?.sendToNative;
15+
const postMessage = global.nativeBridge?.postMessage;
1916

2017
if (typeof postMessage === "function") {
21-
postMessage(message);
22-
} else if (typeof sendToNative === "function") {
23-
sendToNative(JSON.stringify(message));
18+
postMessage?.(message);
2419
} else {
25-
console.error(
26-
"Adapter: can not find postMessage or sendToNative"
27-
);
20+
console.error("Adapter: can not find postMessage");
2821
}
2922
}
3023

‎src/core/EventEmitter.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class EventEmitter {
55
if (!this.#listener.has(event)) {
66
this.#listener.set(event, new Set<Function>())
77
}
8-
8+
99
this.#listener.get(event)?.add(handler)
1010
}
1111

‎src/global.d.ts‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,15 @@ import NativeInterface from "./core/NativeInterface";
33
declare global {
44
namespace NodeJS {
55
interface Global {
6-
webkit: {
7-
messageHandlers: {
8-
nativeApp: {
9-
postMessage: <T>(params: {
10-
readonly id: string;
11-
payload: {
12-
module: string;
13-
action: string;
14-
params?: T;
15-
};
16-
}) => void;
6+
nativeBridge: {
7+
postMessage: <T>(params: {
8+
readonly id: string;
9+
payload: {
10+
module: string;
11+
action: string;
12+
params?: T;
1713
};
18-
};
19-
};
20-
nativeApp: {
21-
sendToNative: (params: string) => void;
14+
}) => void;
2215
};
2316
webApp: NativeInterface;
2417
}

‎src/simulator/index.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@ import handleAnswerAction from "./handleAnswerAction";
44
import handleCallBack from "./handleCallBack";
55

66
function simulator() {
7-
global.webkit = global.webkit ?? {};
8-
global.webkit.messageHandlers = global.webkit.messageHandlers ?? {};
9-
global.webkit.messageHandlers.nativeApp =
10-
global.webkit.messageHandlers.nativeApp ?? {};
11-
12-
global.webkit.messageHandlers.nativeApp.postMessage = function<T>({
7+
global.nativeBridge.postMessage = function <T>({
138
id,
14-
payload: { module, action, params }
9+
payload: { module, action, params },
1510
}: {
1611
readonly id: string;
1712
payload: {

‎yarn.lock‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,10 +2528,10 @@ typedarray@^0.0.6:
25282528
resolved "https://registry.npmmirror.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
25292529
integrity sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==
25302530

2531-
typescript@^5.8.3:
2532-
version "5.8.3"
2533-
resolved "https://registry.npmmirror.com/typescript/-/typescript-5.8.3.tgz#92f8a3e5e3cf497356f4178c34cd65a7f5e8440e"
2534-
integrity sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==
2531+
typescript@^4.9.5:
2532+
version "4.9.5"
2533+
resolved "https://registry.npmmirror.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
2534+
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==
25352535

25362536
uglify-js@^3.1.4:
25372537
version "3.19.3"

0 commit comments

Comments
 (0)