鸿蒙系统支持reactnative,鸿蒙开源三方组件--跨平台自适应布局yoga组件

本文介绍了Facebook的Yoga布局引擎,它是一个跨平台的Flexbox布局解决方案,已在鸿蒙系统上开源。文章通过实例展示了如何在鸿蒙系统中使用Yoga进行动态布局,并提供了集成和使用Yoga的相关信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

aa67ac1f9d2dd2cc396b577e5cbff913.png

介绍

yoga是facebook打造的一个跨IOS、Android、Window平台在内的布局引擎,兼容Flexbox布局方式,让界面更加简单。

Yoga官网:https://facebook.github.io/yoga/

官网上描述的特性包括:

完全兼容Flexbox布局,遵循W3C的规范

支持java、C#、Objective-C、C四种语言

底层代码使用C语言编写,性能不是问题

支持流行框架如React Native

目前在已开源的鸿蒙组件(https://gitee.com/openharmony-tpc/yoga)的功能现状如下:

native层和接口已经打通

支持自定义xml属性来控制布局(通过YogaLayout)

设置布局中不支持Image控件(onDrawCanvas暂不支持主动回调,所以yoga没办法扫描到它),请使用Text控件替代

不支持VirtualYogaLayout

如何使用

首先我们在MainAbility中定义界面路由。

publicclass MainAbility extends Ability {

@Override

publicvoid onStart(Intent intent) {

super.onStart(intent);

super.setMainRoute(MainAbilitySlice.class.getName());

addActionRoute("action.dydrawnode.slice", DynamicsDrawNodeSlice.class.getName());

addActionRoute("action.showrow.slice", ShowRowAbilitySlice.class.getName());

addActionRoute("action.inflate.slice", BenchmarkInflateAbilitySlice.class.getName());

}

}

然后我们来到MainAbilitySlice,其实就是做了一个向其他界面跳转的动作,并提前加载yoga的so库。

publicclass MainAbilitySlice extends AbilitySlice {

static{

System.loadLibrary("yoga");

System.loadLibrary("yogacore");

System.loadLibrary("fb");

}

@Override

publicvoid onStart(Intent intent) {

super.onStart(intent);

setUIContent(ResourceTable.Layout_main_layout);

Button btn0= (Button) findComponentById(ResourceTable.Id_btn_1);

btn0.setClickedListener(component -> {

Intent intent1 = new Intent();

Operation operation = new Intent.OperationBuilder()

.withAction("action.dydrawnode.slice")

.build();

intent1.setOperation(operation);

startAbilityForResult(intent1, 1);

});

Button btn2= (Button) findComponentById(ResourceTable.Id_btn_2);

btn2.setClickedListener(component -> {

Intent intent1 = new Intent();

Operation operation = new Intent.OperationBuilder()

.withAction("action.showrow.slice")

.build();

intent1.setOperation(operation);

startAbilityForResult(intent1, 1);

});

Button btn1= (Button) findComponentById(ResourceTable.Id_btn_3);

btn1.setClickedListener(component -> {

Intent intent1 = new Intent();

Operation operation = new Intent.OperationBuilder()

.withA

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值