Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): reduce duplicate textchange event #3497

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class HippyTextInput extends AppCompatEditText implements HippyViewBase,
TextView.OnEditorActionListener, View.OnFocusChangeListener {

boolean mHasAddWatcher = false;
private String mPreviousText;
private String mPreviousText = "";
TextWatcher mTextWatcher = null;
boolean mHasSetOnSelectListener = false;

Expand Down Expand Up @@ -365,7 +365,6 @@ public void showInputMethodManager() {
private String mValidator = ""; //这则表达式,前端传入,要比较小心导致的crash
private String sRegrexValidBefore = "";
private String sRegrexValidRepeat = ""; //如果有无效的正则输入,会设置.
private boolean mTextInputed = false; //文本是否输入过

public void setValidator(String validator) {
mValidator = validator;
Expand Down Expand Up @@ -402,12 +401,11 @@ public void afterTextChanged(Editable s) {
if (TextUtils.isEmpty((mValidator))) //如果没有正则匹配
{
//如果文本输入过,判断是否两次相同
if (mTextInputed && TextUtils.equals(s.toString(), mPreviousText)) {
if (TextUtils.equals(s.toString(), mPreviousText)) {
return;
}
//这里为什么不用sRegrexValidBefore,sRegrexValidBefore是每次有词汇变化就会被回调设置.
mPreviousText = s.toString();
mTextInputed = true;
if (!bUserSetValue) //如果是前端设置下来的值,不再需要回调给前端.
{
HippyMap hippyMap = new HippyMap();
Expand All @@ -425,13 +423,11 @@ public void afterTextChanged(Editable s) {
//为了避免前端收到两次内容同样的通知.记录一下正则匹配设置回去的值.
sRegrexValidRepeat = sRegrexValidBefore;
setSelection(getText().toString().length()); // TODO这里不应该通知
mTextInputed = true;
} else {
//如果文本输入过,判断是否两次相同
if (mTextInputed && TextUtils.equals(s.toString(), mPreviousText)) {
if (TextUtils.equals(s.toString(), mPreviousText)) {
return;
}
mTextInputed = true;
mPreviousText = s.toString();
if (!bUserSetValue //如果是前端设置的一定不通知
&& (TextUtils.isEmpty(sRegrexValidRepeat) //如果没有,输入过无效的内容
Expand Down
Loading