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

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

Merged
merged 6 commits into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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_CARTRIDGE_RETURN = 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_CARTRIDGE_RETURN;

public class TiUIText extends TiUIView implements TextWatcher, OnEditorActionListener, OnFocusChangeListener
{
private static final String TAG = "TiUIText";
Expand Down Expand Up @@ -406,6 +409,7 @@ 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);
data.put(TiC.PROPERTY_BUTTON, RETURN_KEY_TYPE_CARTRIDGE_RETURN);
fireEvent(TiC.EVENT_RETURN, data);
}
/**
Expand Down Expand Up @@ -518,15 +522,30 @@ 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) {
data.put(TiC.PROPERTY_BUTTON, RETURN_KEY_TYPE_ACTION);
// Check whether we a dealing with text area or text field. Multiline TextViews in Landscape
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"we are dealing"

// orientation for phones have separate buttons for IME_ACTION and cartridge return.
// 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 cartridge return one.
if (tv.getMaxLines() == 1) {
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;
}
// Cartridge return 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 cartridge return.
return false;
}

return false;
}

public void handleTextAlign(String textAlign, String verticalAlign)
Expand Down
10 changes: 10 additions & 0 deletions apidoc/Titanium/UI/TextField.yml
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,20 @@ events:

- name: return
summary: Fired when the return key is pressed on the keyboard.
description: |
Since in Landscape mode Android provides both the New Line and the Action type
buttons as return keys the 'button' property in the event is used to distinguish from
which key has the event been fired.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Android provides both the new line- and the action buttons as return keys in landscape mode, the button property in the event is used to distinguish from which key the event has been fired.

In general: I think @jquick-axway can give some language advices here as well.

properties:
- name: value
summary: Value of this text area.
type: String
- name: button
summary: Constant indication whether the event is from New line or Action key.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constant indicating whether the event is from a new line- or action key.

type: Number
platforms: [android]
since: "7.1.1"
constants: Titanium.UI.RETURN_KEY_TYPE_*

examples:
- title: Basic Text Field with rounded border
Expand Down
14 changes: 14 additions & 0 deletions apidoc/Titanium/UI/UI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2720,6 +2720,20 @@ properties:
since: "3.0.0"
permission: read-only

- name: RETURN_KEY_TYPE_ACTION
summary: The returnKeyEvent has been send by the Action button on the software keyboard.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return event has been sent by the action button on the software keyboard.

type: Number
platforms: [android]
since: "7.1.1"
permission: read-only

- name: RETURN_KEY_TYPE_CARTRIDGE_RETURN
summary: The returnKeyEvent has been send by the New Line\Cartridge Return button on the software keyboard.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return evtn has been sent by the new line- or cartridge return button on the software keyboard.

type: Number
platforms: [android]
since: "7.1.1"
permission: read-only

- name: backgroundColor
summary: |
Sets the background color of the master view (when there are no windows or other top-level
Expand Down