1 个回答

自定义弹窗规格问题,无法控制弹窗不被键盘顶起的情况。

1、可看下半模态相关文档看是否符合诉求

2、请参考以下示例

@Entry
@Component
struct SafeAreaPage2 {
  @State text: string = ''
  controller: TextInputController = new TextInputController()
  @State panelHeight: string = '0'

  build() {
    Stack({ alignContent: Alignment.Bottom }) {
      Column() {
        Button('弹起/收起').onClick(() => {
          if (this.panelHeight === '0') {
            this.panelHeight = '85%'
          }else {
            this.panelHeight = '0'
            this.controller.stopEditing()
          }
        })
      }
      .expandSafeArea([SafeAreaType.KEYBOARD])
      .width('100%')
      .height('100%')
      CustomEdit()
        .height(this.panelHeight)
        .visibility(this.panelHeight === '0' ? Visibility.Hidden : Visibility.Visible)
        .animation({ duration: 300 })
    }
    .width('100%')
    .height('100%')

  }
}
@Component
struct CustomEdit {
  build() {
    Column() {
      Text('请评论')
        .margin({ top: 10 })
      TextArea({ placeholder: '请输入' })
        .width('96%')
        .backgroundColor(Color.White)
        .borderWidth(1)
        .borderColor('#666')
        .borderRadius(10)
        .margin({ top: 5,bottom:5})
        .defaultFocus(true)
        .layoutWeight(1)
        .textAlign(TextAlign.Start)
    }
    .width('100%')
    .borderRadius({topLeft:15,topRight:15})
    .backgroundColor(Color.Pink)
    .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进