HarmonyOS NEXT应用开辟之ArkWeb同层渲染(1),HarmonyOS鸿蒙开辟网络视频框 ...

打印 上一主题 下一主题

主题 960|帖子 960|积分 2880

自我先容一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里不停到现在。
深知大多数HarmonyOS鸿蒙开辟工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技能停滞不前!
因此收集整理了一份《2024年HarmonyOS鸿蒙开辟全套学习资料》,初衷也很简单,就是盼望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。





既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,根本涵盖了95%以上HarmonyOS鸿蒙开辟知识点,真正体系化!
由于文件比较大,这里只是将部门目录大纲截图出来,每个节点里面都包罗大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会连续更新
假如你以为这些内容对你有帮助,可以添加VX:vip204888 (备注鸿蒙获取)

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


  • 获取EmbedId
    /
    getEmbedId() : string {
    return this.embedId;
    }
    /
    *
  • 将触摸变乱派发到rootNode创建出的FrameNode上
    */
    postEvent(event: TouchEvent | undefined) : boolean {
    return this.rootNode?.postTouchEvent(event) as boolean;
    }
    }
  1. 3. 添加同层渲染的组件。
复制代码
@Component
struct SearchComponent {
@Prop params: Params;
controller: SearchController = new SearchController();
build() {
Column() {
Column({ space: MARGIN_VERTICAL }) {
Text(                                   r                                   (                            ′                                  a                         p                         p                         .                         s                         t                         r                         i                         n                         g                         .                         h                         e                         a                         d                         l                         i                         n                                   e                            ′                                  )                         )                         .                         f                         o                         n                         t                         S                         i                         z                         e                         (                              r('app.string.headline')).fontSize(                  r(′app.string.headline′)).fontSize(r(‘app.string.ohos_id_text_size_body1’))
Text(                                   r                                   (                            ′                                  a                         p                         p                         .                         s                         t                         r                         i                         n                         g                         .                         i                         l                         l                         u                         s                         t                         r                         a                         t                                   e                            ′                                  )                         )                         .                         f                         o                         n                         t                         S                         i                         z                         e                         (                              r('app.string.illustrate')).fontSize(                  r(′app.string.illustrate′)).fontSize(r(‘app.string.ohos_id_text_size_body1’))
}
// 原生Text组件
Text(                                   r                                   (                            ′                                  a                         p                         p                         .                         s                         t                         r                         i                         n                         g                         .                         m                         a                         l                                   l                            ′                                  )                         )                         .                         f                         o                         n                         t                         S                         i                         z                         e                         (                              r('app.string.mall')).fontSize(                  r(′app.string.mall′)).fontSize(r(‘app.string.ohos_id_text_size_body1’))
// 原生Search组件
Search({ placeholder: ‘Type to search…’, controller: this.controller })
.searchButton(SEARCH_BUTTON)
// 原生Grid组件,Grid中包罗Image和Text
Grid() {
// 性能知识点:此处数据量确定且数量较少,利用了ForEach,在数据量多的环境下,保举利用LazyForeEach
ForEach(PRODUCT_DATA, (item: ProductDataModel, index: number) => {
GridItem() {
Column({ space: MARGIN_VERTICAL }) {
Image(item.uri).width(KaTeX parse error: Expected '}', got 'EOF' at end of input: …itle).fontSize(r(‘app.string.ohos_id_text_size_body3’))
Text(item.price).fontSize(KaTeX parse error: Expected 'EOF', got '}' at position 54: …)) }̲ } …r(‘app.string.ohos_id_elements_margin_vertical_m’)) // 行间距
.columnsGap($r(‘app.string.ohos_id_elements_margin_vertical_m’)) // 列间距
}
}
}
  1. 4. embed标签可以在H5页面中嵌入任何类型的内容,在H5界面上通过embed标签标识同层元素,应用侧会将原生组件渲染到H5页面embed标签所在位置。
复制代码
        
  1. 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);
}
})
})
}
}
}
  1. 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();
  1. ---
复制代码
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);
}
})
})
  1. #### 高性能知识点
  2. ArkWeb同层渲染原生组件,原生组件不仅可以提供H5组件无法实现的一些功能,还能提升用户体验的流畅度;同层渲染节点上下树,实现节点复用,节省节点重复开销。
  3. #### 工程结构&模块类型
复制代码
nativeembed // har类型
|—mock
| |—GoodsMock.ets // 数据源
|—model
| |—GoodsModel.ets // 数据类
|—view
| |—NativeEmbedView.ets // 视图层
  1. #### 模块依赖
  2. 本实例依赖common模块来实现[资源]( )的调用。 依赖[动态路由模块]( )来实现页面的动态加载。
  3. #### 参考资料
  4. 1. [Web]( )
  5. 2. [BuilderNode]( )
  6. 3. [NodeController]( )
  7. 4. [ArkWeb(方舟Web)]( )
  8. **为了能让大家更好的学习鸿蒙(HarmonyOS NEXT)开发技术,这边特意整理了《鸿蒙开发学习手册》(共计890页),希望对大家有所帮助:[`https://qr21.cn/FV7h05`]( )**
  9. ### 《鸿蒙开发学习手册》:
  10. #### **如何快速入门:[`https://qr21.cn/FV7h05`]( )**
  11. 1. 基本概念
  12. 2. 构建第一个ArkTS应用
  13. 3. ……
  14. ![](https://img-blog.csdnimg.cn/img_convert/afd6b98a09014e557566dec0fd065c41.webp?x-oss-process=image/format,png)
  15. #### **开发基础知识:[`https://qr21.cn/FV7h05`]( )**
  16. ## **如何快速入门:[`https://qr21.cn/FV7h05`]( )**
  17. 1. 基本概念
  18. 2. 构建第一个ArkTS应用
  19. 3. ……
  20. ![](https://img-blog.csdnimg.cn/img_convert/afd6b98a09014e557566dec0fd065c41.webp?x-oss-process=image/format,png)
  21. #### **开发基础知识:[`https://qr21.cn/FV7h05`]( )**
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

光之使者

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表