harmony 鸿蒙Sheet Transition

2023-06-24 浏览 (1082)

Sheet Transition

You can bind a sheet to a component through the bindSheet attribute. You can also set the sheet to the preset or custom height for when the component is inserted.

NOTE

The APIs of this module are supported since API version 10. Updates will be marked with a superscript to indicate their earliest API version.

Switching between landscape and portrait modes is not supported.

Route hopping is not supported.

Attributes

NameParameterDescription
bindSheetisShow: boolean,
builder: CustomBuilder,
options?: SheetOptions
Binds a sheet to the component, which can be displayed when the component is touched.
isShow: whether to display the sheet.
Since API version 10, this parameter supports two-way binding through $$.
builder: content of the sheet.
options: optional attributes of the sheet.

NOTE

When no two-way binding is set up for the isShow parameter, closing the sheet by dragging does not change the parameter value.

To synchronize the value of isShow with the actual state of the sheet, it is recommended that you use the $$ to set up two-way binding for isShow.

SheetOptions

NameTypeMandatoryDescription
heightSheetSize |LengthNoHeight of the sheet.
Default value: LARGE
dragBarbooleanNoWhether to display the drag bar. By default, the drag bar is displayed .
backgroundColorResourceColorNoBackground color of the sheet.
maskColorResourceColorNoMask color of the sheet.
onAppear() => voidNoCallback invoked when the sheet is displayed.
onDisappear() => voidNoCallback invoked when the sheet is hidden.

SheetSize

NameDescription
MEDIUMThe sheet height is half of the screen height.
LARGEThe sheet height is almost the screen height.

Example

// xxx.ets
@Entry
@Component
struct SheetTransitionExample {
  @State isShow:boolean = false
  @State isShow2:boolean = false
  @State sheetHeight:number = 300;
  @State showDragBar:boolean = true;

  @Builder myBuilder() {
    Column() {
      Button("change height")
        .margin(10)
        .fontSize(20)
        .onClick(()=>{
          this.sheetHeight = 500;
        })

      Button("Set Illegal height")
        .margin(10)
        .fontSize(20)
        .onClick(()=>{
          this.sheetHeight = 300;
        })

      Button("close dragBar")
        .margin(10)
        .fontSize(20)
        .onClick(()=>{
          this.showDragBar = false;
        })

      Button("close modal 1")
        .margin(10)
        .fontSize(20)
        .onClick(()=>{
          this.isShow = false;
        })
    }
    .width('100%')
    .height('100%')
  }

  build() {
    Column() {
      Button("transition modal 1")
        .onClick(() => {
          this.isShow = true
        })
        .fontSize(20)
        .margin(10)
        .bindSheet($$this.isShow, this.myBuilder(), {height: this.sheetHeight, dragBar: this.showDragBar, backgroundColor: Color.Green, onAppear: () => {console.log("BindSheet onAppear.")}, onDisappear: () => {console.log("BindSheet onDisappear.")}})
    }
    .justifyContent(FlexAlign.Center)
    .width('100%')
    .height('100%')
  }
}

en-us_sheet

你可能感兴趣的鸿蒙文章

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/043b77f9bdd94e7fa1fdcdc5fcd3c168