textarea 安卓 文本框内一直按“删除键”删除,会卡

bug情况:

https://aliossdl3.tower.im/652017/55a3f503c2538c8c7df9e7a084368d3f?Expires=1636338453&OSSAccessKeyId=LTAI4FzdzJ63WYH36wjrvT56&Signature=%2F4sdZKGdG8e690IPP%2Ba%2BelA1Tbc%3D&response-content-disposition=inline%3Bfilename%3D%22tmp_3559dc555c289f259bbce1992609df370e5d137598899f6f.mp4%22&response-content-type=video%2Fmp4

可以看到,长按删除按钮,文本框在闪烁

原因是

textInputAction 方法里面频繁调用  setData,页面会重复渲染
textInputAction: function (e) {
    var text = e.detail.value;
    var textLen = util.fnGetCpmisWords(text)

    var submitBtnActive = false
    if (this.data.type == 1 && textLen > 0) {
      submitBtnActive = true
    } else if (this.data.type == 2 && textLen > 0 && this.data.customTitle.length > 0) {
      submitBtnActive = true
    }
    // this.data.inputText = text
    this.setData({
      currentTextLength: textLen,
      inputText: text,
      sbActiveState: submitBtnActive,
      submitBtnText: text == this.data.tempRecogText ? '请编辑识别后的文本再提交' :'提交作文'
    })
  },

改成    this.data.inputText = text, 别在setData里面更新inputText    就好了:

textInputAction: function (e) {
    var text = e.detail.value;
    var textLen = util.fnGetCpmisWords(text)

    var submitBtnActive = false
    if (this.data.type == 1 && textLen > 0) {
      submitBtnActive = true
    } else if (this.data.type == 2 && textLen > 0 && this.data.customTitle.length > 0) {
      submitBtnActive = true
    }
    this.data.inputText = text
    this.setData({
      currentTextLength: textLen,
      // inputText: text,
      sbActiveState: submitBtnActive,
      submitBtnText: text == this.data.tempRecogText ? '请编辑识别后的文本再提交' :'提交作文'
    })
  },

 补充wxml:

<textarea class='mTextArea' auto-height='{{true}}' maxlength='-1' value='{{inputText}}' bindinput='textInputAction'
      placeholder="{{sData.my_writing.hint}}" placeholder-class="tiClass" hidden="{{showSuccessCover}}"
      cursor-spacing='90'></textarea>

 

 

posted on 2021-11-08 10:23  土匪7  阅读(274)  评论(0编辑  收藏  举报