harmony 鸿蒙FormComponent

  • 2023-06-24
  • 浏览 (397)

FormComponent

提供卡片组件,实现卡片的显示功能。

说明:

  • 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
  • 该组件为卡片组件的使用方,对应提供方的使用参考文档JS服务卡片UI组件
  • 该组件使用需要具有系统签名。
  • 本组件为系统接口。

权限

ohos.permission.REQUIRE_FORM, ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

子组件

接口

FormComponent(value: { id: number; name: string; bundle: string; ability: string; module: string; dimension?: FormDimension; temporary?: boolean })

创建卡片组件,用于显示提供的卡片。

参数:

参数名 参数类型 必填 参数描述
id number 卡片标识(新建卡片填0)。
说明:
不同使用方不可使用相同id。
同一使用方使用相同id时,显示后添加的卡片。
name string 卡片名称。
bundle string 目标卡片包名。
ability string 目标卡片Ability名称。
module string 卡片模块名称。
dimension FormDimension 卡片尺寸,支持2 * 2,4 * 4,4 * 2类型卡片。
默认值:Dimension_2_2。
temporary boolean 卡片是否为临时卡片。

FormDimension

名称 描述
Dimension_1_2 1*2 卡片
Dimension_2_2 2*2 卡片
Dimension_2_4 2*4 卡片
Dimension_4_4 4*4 卡片
Dimension_2_19+ 2*1 卡片

属性

名称 参数类型 必填 描述
size {
width?: Length,
height?: Length
}
设置高宽尺寸。
moduleName string 卡片模块名称。
dimension FormDimension 卡片尺寸,支持2 * 2,4 * 4,4 * 2类型卡片。
默认值:Dimension_2_2。
allowUpdate boolean 是否允许卡片更新。
默认值:true。
visibility Visibility 是否允许卡片可见。
默认值:Visible。

事件

名称 功能描述
onAcquired(callback: (info: { id: number }) => void) 获取到卡片后触发,返回卡片的id.
onError(callback: (info: { errcode: number, msg: string }) => void) 组件加载错误回调。
errcode: 错误码。
msg: 错误信息。
具体可参考卡片错误码说明文档
onRouter(callback: (info: any) => void) 组件路由事件回调,返回routerEvent中的信息。
onUninstall(callback: (info: { id: number }) => void) 组件卸载回调,返回卸载卡片的id.

示例

//card.ets
@Entry
@Component
struct CardExample {
   @State formId:number = 0;
  build() {
    Column() {
      Text('this is a card')
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
      FormComponent({
        id:this.formId,
        name:"Form1",
        bundle:"com.example.cardexample",
        ability:"FormAbility",
        module:"entry",
        dimension:FormDimension.Dimension_2_2,
        temporary:false
      })
        .allowUpdate(true)
        .size({width:360,height:360})
        .visibility(Visibility.Visible)
        .onAcquired((form)=>{
          console.log(`form info : ${JSON.stringify(form)}`);
          this.formId = form.id;
        })
        .onError((err)=>{
          console.log(`fail to add form, err: ${JSON.stringify(err)}`);
        })

    }
    .width('100%')
    .height('100%')
  }
}

Form

你可能感兴趣的鸿蒙文章

harmony 鸿蒙基于ArkTS的声明式开发范式

harmony 鸿蒙@ohos.arkui.advanced.Counter(计数器组件)

harmony 鸿蒙@ohos.arkui.advanced.SegmentButton(分段按钮)

harmony 鸿蒙@ohos.multimedia.avCastPicker (投播组件)

harmony 鸿蒙属性动画

harmony 鸿蒙枚举说明

harmony 鸿蒙Blank

harmony 鸿蒙Button

harmony 鸿蒙CalendarPicker

harmony 鸿蒙Checkbox

0  赞