HarmonyOS 自定义弹窗(CustomDialog)被键盘顶上去?

在自定义弹窗 CustomDialog1 中调起带输入的自定义弹窗CustomDialog2,CustomDialog2拉取键盘后,CustomDialog1被键盘顶上去了,显示位置异常

阅读 464
1 个回答

这个问题属于一个规格问题,弹窗存在完全避让输入法行为,使用模态框实现拟态框demo:

@Entry
@Component
struct Index {
  @State bottomOpacity: number = 1;
  @State topOpacity: number = 0;

  popShow() {
    console.info("Pop show ...");
    if (this.topOpacity === 1) {
      return;
    }
    console.info("Pop show start ...");
    this.bottomOpacity = 0.6;
    this.topOpacity = 1;
    console.info("Pop show end ...");
  }

  popHide(): void {
    console.info("Pop hide ...");
    if (this.topOpacity === 0) {
      return;
    }
    console.info("Pop hide start ...");
    this.bottomOpacity = 1;
    this.topOpacity = 0;
    console.info("Pop hide end ...");
  }

  build() {
    Stack({ alignContent: Alignment.Bottom }) {
      Column() {
        Text('First child, show in level 1')
          .width('60%')
          .height('20%')
          .align(Alignment.Center)
      }
      .width('100%')
      .height('100%')
      .backgroundColor(0xd2cab3)
      .justifyContent(FlexAlign.Center)
      .opacity(this.bottomOpacity)

      this.popup();

      Button('Click Me')
        .width('40%')
        .height('10%')
        .backgroundColor(Color.Green)
        .zIndex(3)
        .onClick(() => this.popShow())
    }
    .width('100%')
    .height('100%')
    .margin({ top: 5 })
  }

  @Builder popup() {
    if (this.topOpacity === 1) {
      Column() {
        Text('Second child, show in level2')
          .width('70%')
          .height('20%')
          .align(Alignment.Center)
      }
      .width('70%')
      .height('20%')
      .backgroundColor(0xc1cbac)
      .justifyContent(FlexAlign.Center)
      .position({
        x: 50,
        y: 90
      })
      .opacity(this.topOpacity)
      .onClick(() => this.popHide())
    }
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进