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

[TIMOB-25671]Android : TextField's some returnKeyType values not firing 'return' event #9933

Merged
merged 7 commits into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public class UIModule extends KrollModule implements Handler.Callback
{
private static final String TAG = "TiUIModule";

@Kroll.constant
public static final int RETURN_KEY_TYPE_ACTION = 0;
@Kroll.constant
public static final int RETURN_KEY_TYPE_NEW_LINE = 1;
@Kroll.constant
public static final int RETURNKEY_GO = 0;
@Kroll.constant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

import static ti.modules.titanium.ui.UIModule.RETURN_KEY_TYPE_ACTION;
import static ti.modules.titanium.ui.UIModule.RETURN_KEY_TYPE_NEW_LINE;

public class TiUIText extends TiUIView implements TextWatcher, OnEditorActionListener, OnFocusChangeListener
{
private static final String TAG = "TiUIText";
Expand Down Expand Up @@ -407,6 +410,8 @@ public void onTextChanged(CharSequence s, int start, int before, int count)
String value = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_VALUE));
KrollDict data = new KrollDict();
data.put(TiC.PROPERTY_VALUE, value);
// TODO: Enable this once we have it on iOS as well.
//data.put(TiC.PROPERTY_BUTTON, RETURN_KEY_TYPE_NEW_LINE);
fireEvent(TiC.EVENT_RETURN, data);
}
/**
Expand Down Expand Up @@ -519,15 +524,32 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent keyEvent)
return true;
}

//This is to prevent 'return' event from being fired twice when return key is hit. In other words, when return key is clicked,
//this callback is triggered twice (except for keys that are mapped to EditorInfo.IME_ACTION_NEXT or EditorInfo.IME_ACTION_DONE). The first check is to deal with those keys - filter out
//one of the two callbacks, and the next checks deal with 'Next' and 'Done' callbacks, respectively.
//Refer to TiUIText.handleReturnKeyType(int) for a list of return keys that are mapped to EditorInfo.IME_ACTION_NEXT and EditorInfo.IME_ACTION_DONE.
if (actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE) {
// TODO: Enable this once we have it on iOS as well.
//data.put(TiC.PROPERTY_BUTTON, RETURN_KEY_TYPE_ACTION);

// Check whether we are dealing with text area or text field. Multiline TextViews in Landscape
// orientation for phones have separate buttons for IME_ACTION and new line.
// And because of that we skip the firing of a RETURN event from this call in favor of the
// one from onTextChanged. The event carries a property to determine whether it was fired
// from the IME_ACTION button or the new line one.
if (field) {
fireEvent(TiC.EVENT_RETURN, data);
// Since IME_ACTION_NEXT and IME_ACTION_DONE take care of consuming the second call to
// onEditorAction we do not consume it for either of them.
return (!(actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE));
} else {
// After clicking the IME_ACTION button we get two calls of onEditorAction.
// The second call of onEditorAction is treated as a KeyPress event and gives the
// keyEvent for that as the third parameter. If it is 'null' that's the first call -
// fire the JS event and consume the event to prevent the duplicate call.
if (keyEvent == null) {
fireEvent(TiC.EVENT_RETURN, data);
return true;
}
// New line is treated immediately as KeyEvent, so we let the system propagate it
// to onTextChange where the JS event is loaded with the property that with was a new line.
return false;
}

return false;
}

public void handleTextAlign(String textAlign, String verticalAlign)
Expand Down