往期知识点整理
- 鸿蒙(HarmonyOS)北向开发知识点记录~
- 【鸿蒙实战开发】har和hsp的转换
- 【鸿蒙实战开发】基于CameraKit对相机进行操作
- 【鸿蒙实战开发】基于HAR的跨模块C++头文件引用
- 【鸿蒙实战开发】基于原生实现高级显示效果
- 【鸿蒙实战开发】基于动态配置签名的多人协同开发应用签名解决方案
- 【鸿蒙实战开发】基于webview的Picker拉起
- 【鸿蒙实战开发】基于@ohos.data.unifiedDataChannel实现数据共享
- 持续更新中……
C-API 版本使用XComponent总共分成了两个步骤:
-
createSurface的时候创建XComponentSurface;
-
startSurface的时候将CPP的XComponentSurface连接到ArkUI的Xcomponent上。
createSurface的时候主要做了以下的操作:
1.创建并将XComponentSurface记录到Map中:
void RNInstanceCAPI::createSurface(facebook::react::Tag surfaceId, std::string const& moduleName) {
m_surfaceById.emplace(
surfaceId,
XComponentSurface(
// ···
surfaceId,
moduleName)
);
}
2.在XComponentSurface中创建rootView,用于挂载C-API的组件,并在Surface上统一处理Touch事件:
XComponentSurface::XComponentSurface(
//···
SurfaceId surfaceId,
std::string const& appKey)
:
//···
m_nativeXComponent(nullptr),
m_rootView(nullptr),
m_surfaceHandler(SurfaceHandler(appKey, surfaceId)) {
m_scheduler->registerSurface(m_surfaceHandler);
m_rootView = componentInstanceFactory->create(
surfaceId, facebook::react::RootShadowNode::Handle(), "RootView");
m_componentInstanceRegistry->insert(m_rootView);
m_touchEventHandler = std::make_unique<SurfaceTouchEventHandler>(m_rootView);
}
startSurface的时候主要做了以下的操作:
- 在ArkTS侧创建XComponent,并设置id,type与libraryname属性。其中:
- id:组件的唯一标识,又由InstanceID和SurfaceID共同组成,记录了此XComponent属于哪一个Instance与Surface;
- type:node,标识该XComponent是一个占位组件,组件的实现都在C-API侧;
- libraryname:表示C-API组件在哪个so库中实现,并加载该so库,自动调用该so中定义的Init函数。当前React Native for OpenHarmony默认的so名字rnoh_app。
XComponent({
id: this.ctx.rnInstance.getId() + "_" + this.surfaceHandle.getTag(),
type: "node",
libraryname: 'rnoh_app'
})
- 在CPP侧的Init中调用registerNativeXComponent函数,该函数中调用了OH_NativeXComponent_GetXComponentId用于获取ArkTS设置的id,并根据id找到对应的Instance与Surface。同时还要获取nativeXComponent对象,记录ArkTS侧的XComponent。
if (OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize) !=
OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
···
}
std::string xcomponentStr(idStr);
std::stringstream ss(xcomponentStr);
std::string instanceId;
std::getline(ss, instanceId, '_');
std::string surfaceId;
std::getline(ss, surfaceId, '_');
3.调用OH_NativeXComponent_AttachNativeRootNode,将XComponentSurface中记录的rootView连接到ArkTS侧的XComponent上:
OH_NativeXComponent_AttachNativeRootNode(
nativeXComponent,
rootView.getLocalRootArkUINode().getArkUINodeHandle());
总是有很多小伙伴反馈说:鸿蒙开发不知道学习哪些技术?不知道需要重点掌握哪些鸿蒙开发知识点? 为了解决大家这些学习烦恼。在这准备了一份很实用的鸿蒙全栈开发学习路线与学习文档给大家用来跟着学习。
针对一些列因素,整理了一套纯血版鸿蒙(HarmonyOS Next)全栈开发技术的学习路线,包含了鸿蒙开发必掌握的核心知识要点,内容有(OpenHarmony多媒体技术、Napi组件、OpenHarmony内核、OpenHarmony驱动开发、系统定制移植……等)技术知识点。
《鸿蒙 (Harmony OS)开发学习手册》(共计892页):https://gitcode.com/HarmonyOS_MN/733GH/overview
如何快速入门?
1.基本概念
2.构建第一个ArkTS应用
3.……
开发基础知识:
1.应用基础知识
2.配置文件
3.应用数据管理
4.应用安全管理
5.应用隐私保护
6.三方应用调用管控机制
7.资源分类与访问
8.学习ArkTS语言
9.……
基于ArkTS 开发
1.Ability开发
2.UI开发
3.公共事件与通知
4.窗口管理
5.媒体
6.安全
7.网络与链接
8.电话服务
9.数据管理
10.后台任务(Background Task)管理
11.设备管理
12.设备使用信息统计
13.DFX
14.国际化开发
15.折叠屏系列
16.……
鸿蒙开发面试真题(含参考答案):https://gitcode.com/HarmonyOS_MN/733GH/overview
OpenHarmony 开发环境搭建
《OpenHarmony源码解析》:https://gitcode.com/HarmonyOS_MN/733GH/overview
- 搭建开发环境
- Windows 开发环境的搭建
- Ubuntu 开发环境搭建
- Linux 与 Windows 之间的文件共享
- ……
- 系统架构分析
- 构建子系统
- 启动流程
- 子系统
- 分布式任务调度子系统
- 分布式通信子系统
- 驱动子系统
- ……