xugenyuan

ref |> 解决评论输入框默认弹起键盘问题

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
@@ -17,8 +17,6 @@ export struct CommentCustomDialog { @@ -17,8 +17,6 @@ export struct CommentCustomDialog {
17 @State positionInfo: CaretOffset = { index: 0, x: 0, y: 0 } 17 @State positionInfo: CaretOffset = { index: 0, x: 0, y: 0 }
18 18
19 aboutToAppear(): void { 19 aboutToAppear(): void {
20 -  
21 - // this.textInputController.caretPosition(0)  
22 } 20 }
23 21
24 publishCommentRequest() { 22 publishCommentRequest() {
@@ -51,12 +49,20 @@ export struct CommentCustomDialog { @@ -51,12 +49,20 @@ export struct CommentCustomDialog {
51 controller: this.textInputController, 49 controller: this.textInputController,
52 text: this.publishCommentModel.commentContent 50 text: this.publishCommentModel.commentContent
53 }) 51 })
  52 + .id("textAreaId")
  53 + .defaultFocus(true) // 获取默认焦点
  54 + .enableKeyboardOnFocus(true)
54 .height('100%') 55 .height('100%')
55 .width('100%') 56 .width('100%')
56 .backgroundColor($r('app.color.color_transparent')) 57 .backgroundColor($r('app.color.color_transparent'))
57 .onChange(value => { 58 .onChange(value => {
58 this.publishCommentModel.commentContent = value; 59 this.publishCommentModel.commentContent = value;
59 }) 60 })
  61 + .onFocus(() => {
  62 + if (this.emojiSwitch) {
  63 + this.emojiSwitch = false
  64 + }
  65 + })
60 } 66 }
61 .backgroundColor('#F9F9F9') 67 .backgroundColor('#F9F9F9')
62 // .width('100%') 68 // .width('100%')
@@ -81,6 +87,7 @@ export struct CommentCustomDialog { @@ -81,6 +87,7 @@ export struct CommentCustomDialog {
81 if (this.emojiSwitch) { 87 if (this.emojiSwitch) {
82 this.textInputController.stopEditing() 88 this.textInputController.stopEditing()
83 } else { 89 } else {
  90 + focusControl.requestFocus("textAreaId") // 弹起键盘
84 // this.textInputController.caretPosition(this.textInputController.getTextContentRect().x) 91 // this.textInputController.caretPosition(this.textInputController.getTextContentRect().x)
85 } 92 }
86 93