harmony 鸿蒙FormComponent

2023-06-24 浏览 (1174)

FormComponent

The FormComponent is used to display widgets.

NOTE

  • This component is supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
  • This component is intended for the widget host. For details about the widget provider, see JS Service Widget UI Components.
  • To use this component, you must have the system signature.
  • The APIs provided by this component are system APIs.

Required Permissions

ohos.permission.REQUIRE_FORM, ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

Child Components

Not supported

APIs

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

Creates a FormComponent instance to display the provided widget.

Parameters

NameTypeMandatoryDescription
idnumberYesWidget ID. Set this parameter to 0 for a new widget.
NOTE
Different widget hosts cannot use the same ID.
If a widget host uses the same ID for two widgets, the one added later is displayed.
namestringYesWidget name.
bundlestringYesBundle name of the widget.
abilitystringYesAbility name of the widget.
modulestringYesModule name of the widget.
dimensionFormDimensionNoDimensions of the widget. The widgets in the 2 x 2, 4 x 4, and 4 x 2 dimensions are supported.
Default value: Dimension_2_2
temporarybooleanNoWhether the widget is a temporary one.

FormDimension

NameDescription
Dimension_1_21 x 2 widget.
Dimension_2_22 x 2 widget.
Dimension_2_42 x 4 widget.
Dimension_4_44 x 4 widget.
Dimension_2_19+2 x 1 widget.

Attributes

NameTypeMandatoryDescription
size{
width?: Length,
height?: Length
}
YesSize of the widget.
moduleNamestringYesModule name of the widget.
dimensionFormDimensionNoDimensions of the widget. The widgets in the 2 x 2, 4 x 4, and 4 x 2 dimensions are supported.
Default value: Dimension_2_2
allowUpdatebooleanNoWhether to allow the widget to update.
Default value: true
visibilityVisibilityNoWhether the widget is visible.
Default value: Visible

Events

NameDescription
onAcquired(callback: (info: { id: number }) => void)Triggered when a widget is obtained. This API returns the ID of the obtained widget.
onError(callback: (info: { errcode: number, msg: string }) => void)Triggered when an error occurs during component loading.
errcode: error code.
msg: error information.
For details, see Form Error Codes.
onRouter(callback: (info: any) => void)Triggered when routing occurs for the widget. This API returns information in routerEvent.
onUninstall(callback: (info: { id: number }) => void)Triggered when a widget is uninstalled. This API returns the ID of the uninstalled widget.

Example

//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-based Declarative Development Paradigm

harmony 鸿蒙@ohos.multimedia.avCastPicker (AVCastPicker)

harmony 鸿蒙Property Animation

harmony 鸿蒙Enums

harmony 鸿蒙Blank

harmony 鸿蒙Button

harmony 鸿蒙CalendarPicker

harmony 鸿蒙Checkbox

harmony 鸿蒙CheckboxGroup

harmony 鸿蒙DataPanel

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/3c5be62d142d4c80b7dd1eeac04264a4