xd-tayde / blog Goto Github PK
View Code? Open in Web Editor NEW博客
博客
《Hybrid App技术解析 -- 实战篇》里说:
Native 完成功能后,直接调用 Bridge.postMessage(handler, data),将 执行结果 和 之前 nativeCall 传过来的 标识 回传给 H5;
postMessage函数的关键代码是:
// 这里将data和handler分别从e变量中抽离出来了
const { handler, data} = e;
...
// 仅传入data
fireEvent(evName,data)
第二步是H5创建并触发名为evName
的事件,也就是fireEvent
。
// 核心代码
function fireEvent(evName,data){
...
if(data && eventItem){
// 这里挂载在eventItem.data上的只有data,而没有handler
eventItem.data = data
}
...
if(eventItem){
win.dispatchEvent(eventItem)
}
}
最后,我的理解是触发了“(二) H5 --> Native”这一节讲的nativeCall函数中使用的addEvent()
方法:
function nativeCall(...){
...
addEvent(handlerKey.e, e => {
// 这里的handler是???
const { data, handler } = e.data
...
})
}
简化下中间过程,就发现Native发送的数据/事件与 H5得到的数据/句柄的关系就是:
{ dataH5,handlerH5 } === dataNative
{ dataNative,handlerNative } === eventNative
// 如果下面这个我所理解的相等关系成立的话,那么是否存在`handler`数据冗余的情况?
handlerH5 === handlerNative
是不是应该由cd filename 改为 touch filename
方便的话提供一个Mini版-Hybrid App开发环境, 这样比较好的学习(自己动手中, 已实现Swift通信)
首先謝謝分享。
看您並不是用 github page 發佈博文,而是發佈到其他平台上,請問是不是有自動化的方式呢?
博主你好,我看到你文章中说明了native端如何去调用js的NativeCall,但是在js中如何去声明这个NativeCall呢?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.