Skip to content

Commit

Permalink
* [android] fix input restore init value when batch
Browse files Browse the repository at this point in the history
  • Loading branch information
sospartan committed Jun 29, 2016
1 parent b6c2d31 commit 3a54da2
Showing 1 changed file with 37 additions and 38 deletions.
75 changes: 37 additions & 38 deletions android/sdk/src/main/java/com/taobao/weex/ui/component/WXInput.java
Expand Up @@ -261,6 +261,8 @@ protected void initView() {
inputView.setSingleLine();//default use single line , same to ios
inputView.setMovementMethod(null);

inputView.setText((String) mDomObj.attr.get("value"));

mHost = inputView;
}

Expand All @@ -276,43 +278,48 @@ public void addEvent(String type) {
return;
}
final TextView text = (WXEditText) mHost;
text.setOnFocusChangeListener(new View.OnFocusChangeListener() {
CharSequence mLastValue = text.getText();
@Override
public void onFocusChange(View v, boolean hasFocus) {
CharSequence newValue = text.getText();
newValue = newValue== null?"":newValue;
if(!hasFocus && !newValue.equals(mLastValue)){
mLastValue = newValue;

String event = mDomObj.event.contains(WXEventType.INPUT_CHANGE)?WXEventType.INPUT_CHANGE:null;
fireEvent(event,newValue.toString());
}
}
});
text.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}
if(type.equals(WXEventType.INPUT_CHANGE)) {
text.setOnFocusChangeListener(new View.OnFocusChangeListener() {
CharSequence mLastValue = text.getText();

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (mBeforeText.equals(s.toString())) {
return;
@Override
public void onFocusChange(View v, boolean hasFocus) {
CharSequence newValue = text.getText();
newValue = newValue == null ? "" : newValue;
if (!hasFocus && !newValue.equals(mLastValue)) {
mLastValue = newValue;

String event = mDomObj.event.contains(WXEventType.INPUT_CHANGE) ? WXEventType.INPUT_CHANGE : null;
fireEvent(event, newValue.toString());
}
}
});
}else if(type.equals(WXEventType.INPUT)) {
text.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

String event = mDomObj.event.contains(WXEventType.INPUT)?WXEventType.INPUT:null;
fireEvent(event,s.toString());
}

mBeforeText = s.toString();
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (mBeforeText.equals(s.toString())) {
return;
}

@Override
public void afterTextChanged(Editable s) {
String event = mDomObj.event.contains(WXEventType.INPUT) ? WXEventType.INPUT : null;
fireEvent(event, s.toString());

}
});
mBeforeText = s.toString();
}

@Override
public void afterTextChanged(Editable s) {

}
});
}
}

private void fireEvent(String event,String value){
Expand All @@ -331,14 +338,6 @@ private void fireEvent(String event,String value){
}


@Override
public void updateExtra(Object extra) {
if (extra instanceof Layout &&
getView() != null) {
getView().setText(((Layout) extra).getText());
}
}

@WXComponentProp(name = WXDomPropConstant.WX_ATTR_INPUT_PLACEHOLDER)
public void setPlaceholder(String placeholder) {
if (placeholder == null || mHost == null) {
Expand Down

0 comments on commit 3a54da2

Please sign in to comment.