Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[WEEX-581][android] fix 'onFocus invoked twice (#1460)
Browse files Browse the repository at this point in the history
* fix @Focus invoked twice

when set @foucus & @blur method to <input> ,@Focus will be called twice when <input> is focused
  • Loading branch information
chenzefeng09 authored and YorkShen committed Jan 9, 2019
1 parent 425e0a9 commit cd8c6c7
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public abstract class WXComponent<T extends View> extends WXBasicComponent imple
public boolean mIsAddElementToTree = false;
//for fix element case
public int interactionAbsoluteX=0,interactionAbsoluteY=0;
private boolean mHasAddFocusListener = false;

public WXTracing.TraceInfo mTraceInfo = new WXTracing.TraceInfo();

Expand Down Expand Up @@ -347,14 +348,17 @@ public void addEvent(final String type) {
}
addClickListener(mClickEventListener);
} else if ((type.equals(Constants.Event.FOCUS) || type.equals(Constants.Event.BLUR))) {
addFocusChangeListener(new OnFocusChangeListener() {
if (!mHasAddFocusListener){
mHasAddFocusListener = true;
addFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(boolean hasFocus) {
Map<String, Object> params = new HashMap<>();
params.put("timeStamp", System.currentTimeMillis());
fireEvent(hasFocus ? Constants.Event.FOCUS : Constants.Event.BLUR, params);
}
});
}
} else if (needGestureDetector(type)) {
if (null == view) {
// wait next time to add.
Expand Down

0 comments on commit cd8c6c7

Please sign in to comment.