HarmonyOS鸿蒙Next中RichEditor的自定义控件不会弹起底部控件

HarmonyOS鸿蒙Next中RichEditor的自定义控件不会弹起底部控件 设置了键盘避让 this.getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE);

自定义键盘也设置了 supportAvoidance: true

如果是使用 TextInput 就可以是底部控件弹起, 但是改成 RichEditor 就不行了

cke_3699.png

cke_4167.png


更多关于HarmonyOS鸿蒙Next中RichEditor的自定义控件不会弹起底部控件的实战教程也可以访问 https://www.itying.com/category-93-b0.html

4 回复

我应该找到问题了,如果单独设置自定义键盘或者自定义键盘参数为null,都可以使顶部按钮顶起.但是用一个变量控制customKeyboard的值切换的时候就无法弹起

更多关于HarmonyOS鸿蒙Next中RichEditor的自定义控件不会弹起底部控件的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


我本地跑了个RichEditor自定义键盘的demo,如下,没有复现你说的问题,可以提供下你的完整demo吗?

@Entry
@Component
struct RichEditorExample {
  controller: RichEditorController = new RichEditorController()
  height1: string | number = '80%'
  height2: number = 100
  supportAvoidance: boolean = true;

  aboutToAppear(): void {
    this.getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE)
  }

  // 自定义键盘组件
  @Builder CustomKeyboardBuilder() {
    Column() {
      Row(){
        Button('增加特表情包').onClick(() => {
          this.controller.addTextSpan("\uD83D\uDE0A",
            {
              style:
              {
                fontColor: Color.Orange,
              }
            })
        })
      }
      Grid() {
        ForEach([1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#'], (item: number | string) => {
          GridItem() {
            Button(item + "").width(110).onClick(() => {
              this.controller.addTextSpan(item + '', {
                offset: this.controller.getCaretOffset(),
                style:
                {
                  fontColor: Color.Orange,
                  fontSize: 30
                }
              })
              this.controller.setCaretOffset(this.controller.getCaretOffset() + item.toString().length)
            })
          }
        }).maxCount(3).columnsGap(10).rowsGap(10).padding(5)
      }.backgroundColor(Color.Gray)
    }
  }

  build() {
    Column() {
      Row(){
        Button("20%")
          .fontSize(24)
          .onClick(()=>{
            this.height1 = "20%"
          })
        Button("80%")
          .fontSize(24)
          .margin({left:20})
          .onClick(()=>{
            this.height1 = "80%"
          })
      }
      .justifyContent(FlexAlign.Center)
      .alignItems(VerticalAlign.Bottom)
      .height(this.height1)
      .width("100%")
      .padding({bottom:50})
      RichEditor({ controller: this.controller })
        // 绑定自定义键盘
        .customKeyboard(this.CustomKeyboardBuilder(),{ supportAvoidance: this.supportAvoidance }).margin(10).border({ width: 1 })
        .borderWidth(1)
        .borderColor(Color.Red)
        .width("100%")
    }
  }
}

在HarmonyOS鸿蒙Next中,RichEditor自定义控件不会弹起底部控件的问题可能与布局或事件处理机制有关。首先,确保RichEditor的布局与底部控件的布局没有冲突,例如使用RelativeLayoutStackLayout时,控件之间的相对位置可能会影响显示效果。其次,检查RichEditor的焦点事件处理,确保在输入时没有错误地阻止底部控件的弹起。如果使用了自定义的键盘事件处理逻辑,可能需要调整以确保底部控件在输入时能够正确响应。此外,确保没有在代码中手动设置底部控件的可见性或位置,这可能导致其无法弹起。最后,检查是否有其他全局的布局或样式设置影响了底部控件的显示行为。

在HarmonyOS鸿蒙Next中,RichEditor自定义控件不会弹起底部控件的问题,可能是由于布局或焦点管理不当导致的。首先,检查布局文件,确保RichEditor和其他底部控件的层级关系正确。其次,确认RichEditor的焦点设置,避免影响到底部控件的显示。最后,可以通过重写相关事件处理逻辑,确保在RichEditor获取焦点时,底部控件能够正常弹起。如果问题依旧,建议查看官方文档或社区寻求更详细的解决方案。

回到顶部