HarmonyOS TextArea获取焦点
有一个页面由List组成,里面有很多ItemView,然后我的这个页面 还有一个评论输入组件,起名为:CommentPublishBar
代码如下:
@Preview
@Component
export default struct CommentPublishBar {
@Prop keyboardShow: boolean = false //软键盘当前是否展示
@Prop showHeight: number = getScreenWidth()
@State textAreaHeight: number = 0;
@Prop postData: PostDataBean
@Prop rid: number = 0;
@State content: string = ''
commentPublisher: CommentPublisher = new CommentPublisher()
@Link commentList: Comment[]
textInputController: TextAreaController = new TextAreaController()
aboutToAppear(): void {
}
build() {
Column() {
Column()
.backgroundColor(Color.Transparent)
.width('100%')
.height(this.keyboardShow ? px2vp(this.showHeight) - 50 - (this.textAreaHeight - 38) : 0)
.onClick(() => {
this.closePublish(false)
})
Row() {
TextArea({
placeholder: '说亿点好听的',
controller: this.textInputController,
text: this.content
})
.width(this.keyboardShow ? px2vp(getScreenWidth()) - 96 : px2vp(getScreenWidth()) - 32)
.backgroundColor($r('app.color.BG_2'))
.borderRadius(18)
.margin({ left: 16, right: 16 })
.fontColor($r('app.color.CT_2'))
.placeholderColor($r('app.color.Text_4'))
.fontSize(15)
.padding({ left: 12 })
.constraintSize({
minHeight: 38
})
.onChange((value) => {
this.content = value
})
.onAreaChange((oldValue, newValue) => {
if (typeof newValue.height === 'number') {
this.textAreaHeight = newValue.height
}
}
)
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
if (this.keyboardShow) {
Text('发布')
.width(58)
.height(32)
.borderRadius(4)
.backgroundColor($r('app.color.CM_Blue'))
.textAlign(TextAlign.Center)
.fontColor($r('app.color.CW'))
.fontSize(14)
.onClick(() => {
this.commentPublisher.localId = systemDateTime.getTime().toString()
ToastUtils.showToast('评论发送中')
this.commentPublisher.checkReviewContent(this.postData, this.content, this.postData.id, this.rid, (data: PostReviewResult) => {
let list: Comment[] = []
list.push(data.comment)
for (let item of this.commentList) {
list.push(item)
}
this.commentList = list
})
this.closePublish(true)
})
}
}.width('100%')
.alignItems(VerticalAlign.Bottom)
.padding({ top: 6, bottom: 6 })
.backgroundColor($r('app.color.CB'))
}
}
closePublish(needClearContent: boolean) {
this.rid = 0
inputMethod.getInputMethodController().stopInputSession()
this.getUIContext().getFocusController().clearFocus()
if (needClearContent) {
this.content = ''
}
}
getTextAreaHeight() {
}
}
希望点击itemView可以和直接点击TextArea达到同样的效果,唤起软键盘,TextArea获取焦点,应该怎么做
HarmonyOS
赞
收藏 0
回答 1
待解决
相关问题
HarmonyOS TextArea组件如何主动获取焦点
107浏览 • 1回复 待解决
HarmonyOS TextInput或TextArea如何自动获取焦点
256浏览 • 1回复 待解决
HarmonyOS TextArea如何自动获取焦点弹出键盘
415浏览 • 1回复 待解决
HarmonyOS TextArea无法自动获取焦点弹出键盘
379浏览 • 1回复 待解决
HarmonyOS 文本输入框TextArea主动获取焦点的方法
982浏览 • 1回复 待解决
HarmonyOS Image获取焦点和失去焦点失效
206浏览 • 1回复 待解决
HarmonyOS 主动获取组件焦点
424浏览 • 1回复 待解决
HarmonyOS 主动获取焦点失败
543浏览 • 1回复 待解决
textInput组件获取焦点和失去焦点的事件
852浏览 • 1回复 待解决
HarmonyOS Button组件无法触发获取焦点和失去焦点事件
549浏览 • 1回复 待解决
HarmonyOS TextArea填充值,如何自动滚动到文本底部和如何手动失去焦点
726浏览 • 1回复 待解决
HarmonyOS 获取焦点api提示异常
301浏览 • 1回复 待解决
HarmonyOS TextInput自动获取焦点问题
405浏览 • 1回复 待解决
HarmonyOS 如何控制自定义键盘获取焦点和失去焦点
304浏览 • 1回复 待解决
HarmonyOS TextInput组件无法自动获取焦点
492浏览 • 1回复 待解决
HarmonyOS TextInput如何通过代码获取焦点
394浏览 • 1回复 待解决
HarmonyOS 获取焦点弹出键盘后,点击空白区域不能自动取消焦点
344浏览 • 1回复 待解决
HarmonyOS 用focusControl.requestFocus获取焦点失败
218浏览 • 1回复 待解决
HarmonyOS TextInput如何获取焦点但不弹出键盘
216浏览 • 1回复 待解决
TextInput组件获取焦点的几种场景
3238浏览 • 1回复 待解决
focusControl.requestFocus获取焦点的问题
460浏览 • 1回复 待解决
HarmonyOS 输入框获取焦点后无法弹出
355浏览 • 1回复 待解决
如何判断音频焦点的获取和丢失?
6401浏览 • 1回复 待解决
TextInput输入框如何失去焦点?输入框获取焦点后,点击页面上其他任意地方无法失去焦点,焦点在输入框中
2614浏览 • 1回复 待解决
可以参考一下下面的demo