HarmonyOS NEXT应用开发之ArkWeb同层渲染,头条面试题前端

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数HarmonyOS鸿蒙开发工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年HarmonyOS鸿蒙开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img

img
img
htt

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上HarmonyOS鸿蒙开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新

如果你觉得这些内容对你有帮助,可以添加VX:vip204888 (备注鸿蒙获取)
img

一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

}
}
}


4. embed标签可以在H5页面中嵌入任何类型的内容,在H5界面上通过embed标签标识同层元素,应用侧会将原生组件渲染到H5页面embed标签所在位置。




5. 通过WebView的enableNativeEmbedMode()控制同层渲染开关,通过onNativeEmbedLifecycleChange获取embed标签的生命周期变化数据。



build(){
Column() {
Stack() {
// 性能知识点:此处componentId项确定且数量较少,使用了ForEach,在数据量多的情况下,推荐使用LazyForeEach
ForEach(this.componentIdArr, (componentId: string) => {
NodeContainer(this.nodeControllerMap.get(componentId));
}, (embedId: string) => embedId)
// web组件加载本地test.html页面
Web({ src: KaTeX parse error: Expected 'EOF', got '}' at position 61: …rTabController }̲) .back…r(‘app.color.ohos_id_color_sub_background’))
// 不允许执行缩放
.zoomAccess(false)
// Todo: 知识点:通过enableNativeEmbedMode()配置同层渲染开关
.enableNativeEmbedMode(true)
// Todo: 知识点:通过onNativeEmbedLifecycleChange获取embed标签的生命周期变化数据
.onNativeEmbedLifecycleChange((embed) => {
// 获取web侧embed元素的id
const componentId = embed.info?.id?.toString() as string
if (embed.status === NativeEmbedStatus.CREATE) {
// 创建节点控制器,设置参数并rebuild
let nodeController = new SearchNodeController();
// 外接纹理与WebView同层渲染
nodeController.setRenderOption({surfaceId : embed.surfaceId as string, type : embed.info?.type as string, renderType : NodeRenderType.RENDER_componentTypeTEXTURE, embedId : embed.embedId as string, width : px2vp(embed.info?.width), height : px2vp(embed.info?.height)});
nodeController.rebuild();
// 根据web传入的embed的id属性作为key,将nodeController存入map
this.nodeControllerMap.set(componentId, nodeController);
// 将web传入的embed的id属性存入@State状态数组变量中,用于动态创建nodeContainer节点容器,需要将push动作放在set之后
this.componentIdArr.push(componentId);
} else if (embed.status === NativeEmbedStatus.UPDATE) {
let nodeController = this.nodeControllerMap.get(componentId);
nodeController?.updateNode({text: ‘update’, width: px2vp(embed.info?.width), height: px2vp(embed.info?.height)} as ESObject);
nodeController?.rebuild();
} else {
let nodeController = this.nodeControllerMap.get(componentId);
nodeController?.setBuilderNode(null);
nodeController?.rebuild();
}
})// 获取同层渲染组件触摸事件信息
.onNativeEmbedGestureEvent((touch) => {
this.componentIdArr.forEach((componentId: string) => {
let nodeController = this.nodeControllerMap.get(componentId);
if (nodeController?.getEmbedId() === touch.embedId) {
nodeController?.postEvent(touch.touchEvent);
}
})
})
}
}
}


6. h5侧通过id名获取embed标签信息,并通过embed标签添加同层渲染界面的touch监听事件;应用侧添加onNativeEmbedGestureEvent回调使得手指触摸到embed标签时能获取到触摸事件信息。



let nativeEmbed = {
// 通过id名获取embed标签
nativeSearch : document.getElementById(‘nativeSearch’),
// 事件
events:{},
// 初始化
init:function(){
let self = this;
// 添加touch的监听事件
self.nativeSearch.addEventListener(‘touchstart’, self.events, false);
}
};
nativeEmbed.init();




---



Web({ src: $rawfile(“view.html”), controller: this.browserTabController })
// 获取同层渲染组件触摸事件信息
.onNativeEmbedGestureEvent((touch) => {
this.componentIdArr.forEach((componentId: string) => {
let nodeController = this.nodeControllerMap.get(componentId);
if (nodeController?.getEmbedId() === touch.embedId) {
nodeController?.postEvent(touch.touchEvent);
}
})
})


#### 高性能知识点


ArkWeb同层渲染原生组件,原生组件不仅可以提供H5组件无法实现的一些功能,还能提升用户体验的流畅度;同层渲染节点上下树,实现节点复用,节省节点重复开销。


#### 工程结构&模块类型



nativeembed // har类型
|—mock
| |—GoodsMock.ets // 数据源
|—model
| |—GoodsModel.ets // 数据类
|—view
| |—NativeEmbedView.ets // 视图层


#### 模块依赖


本实例依赖common模块来实现[资源]( )的调用。 依赖[动态路由模块]( )来实现页面的动态加载。


#### 参考资料


1. [Web]( )
2. [BuilderNode]( )
3. [NodeController]( )
4. [ArkWeb(方舟Web)]( )


**为了能让大家更好的学习鸿蒙(HarmonyOS NEXT)开发技术,这边特意整理了《鸿蒙开发学习手册》(共计890页),希望对大家有所帮助:[`https://qr21.cn/FV7h05`]( )**


### 《鸿蒙开发学习手册》:


#### **如何快速入门:[`https://qr21.cn/FV7h05`]( )**


1. 基本概念
2. 构建第一个ArkTS应用
3. ……


![](https://img-blog.csdnimg.cn/img_convert/afd6b98a09014e557566dec0fd065c41.webp?x-oss-process=image/format,png)


#### **开发基础知识:[`https://qr21.cn/FV7h05`]( )**


1. 应用基础知识
2. 配置文件
3. 应用数据管理
4. 应用安全管理
5. 应用隐私保护
6. 三方应用调用管控机制
7. 资源分类与访问
8. 学习ArkTS语言
9. ……


![](https://img-blog.csdnimg.cn/img_convert/c02d1bcf9201e3d3d8baf3b812f8e370.webp?x-oss-process=image/format,png)


#### **基于ArkTS 开发:[`https://qr21.cn/FV7h05`]( )**


1. Ability开发
2. UI开发
3. 公共事件与通知
4. 窗口管理
5. 媒体
6. 安全
7. 网络与链接
8. 电话服务
9. 数据管理
10. 后台任务(Background Task)管理
11. 设备管理
12. 设备使用信息统计
13. DFX
14. 国际化开发
15. 折叠屏系列
16. ……


![](https://img-blog.csdnimg.cn/img_convert/ac0f330dc7d6738a5b1180f68865890c.webp?x-oss-process=image/format,png)


#### 鸿蒙开发面试真题(含参考答案):[`https://qr18.cn/F781PH`]( )


![](https://img-blog.csdnimg.cn/img_convert/b2b4ab55693c8db2d124f48f0ea89c1d.webp?x-oss-process=image/format,png)


#### 鸿蒙开发面试大盘集篇(共计319页):[`https://qr18.cn/F781PH`]( )


1.项目开发必备面试题  
 2.性能优化方向  
 3.架构方向  
 4.鸿蒙开发系统底层方向  
 5.鸿蒙音视频开发方向  
 6.鸿蒙车载开发方向  
 7.鸿蒙南向开发方向

.cn/img_convert/b2b4ab55693c8db2d124f48f0ea89c1d.webp?x-oss-process=image/format,png)


#### 鸿蒙开发面试大盘集篇(共计319页):[`https://qr18.cn/F781PH`]( )


1.项目开发必备面试题  
 2.性能优化方向  
 3.架构方向  
 4.鸿蒙开发系统底层方向  
 5.鸿蒙音视频开发方向  
 6.鸿蒙车载开发方向  
 7.鸿蒙南向开发方向

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值