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

Conversation

ypbnv
Copy link
Contributor

@ypbnv ypbnv commented Mar 14, 2018

JIRA: https://jira.appcelerator.org/browse/TIMOB-25671

Description:
Always trigger the return key event from software keyboard.
In Landscape mode for phones Android provides both the return key for New Line and an Action key with the desired IME_ACTION mode. I extended the return event with a property that distinguishes from which key the return event has been fired.
Names of constants and name of the property I have added can be changed.

Note: This relies on user interaction with the software keyboard, so I don't think we can have unit tests for the code.

Test case:
app.js

var win = Ti.UI.createWindow({ backgroundColor : 'gray'});

var textField = Ti.UI.createTextField({
    top : 40,
    left : 20,
    right : 20,
    hintText : 'Hit \'Return\' button'
});

var textArea = Ti.UI.createTextArea({
  font: {fontSize:20, fontWeight:'bold'},
  textAlign: 'left',
  value: 'I am a textarea',
  top: 150,
  width: 300, height : 70
});

textField.addEventListener('return', function (e) {
  showAlert(e);
});

textArea.addEventListener('return', function (e) {
  showAlert(e);
});

function showAlert(event) {
  var message;
  if (event.button == Ti.UI.BUTTON_TYPE_ACTION) {
      message = 'Action!';
  } else {
      message = 'Cartridge return!';
  }
  alert(message);
}

win.add(textField);
win.add(textArea);
win.open();

Add return event property for distinguishing the origin of the event.
@build
Copy link
Contributor

build commented Mar 14, 2018

Messages
📖

💾 Here's the generated SDK zipfile.

Generated by 🚫 dangerJS

@jquick-axway
Copy link
Contributor

@ypbnv, I tested the "return" event handling on iOS with TextFields and TextAreas. The "return" event is always fired when the key is pressed. It is also fired in a TextAreas where the return key inserts a newline. I've tried with suppressReturn property set to true/false (an iOS-only feature) and the "return" event is always fired as well (this property just changes what the key does; insert newline or act as a submit button).

@@ -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;

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea of indicating the return type. Especially on iOS since TextAreas can fire a "return" event when its an action or newline, depending on the TextArea.suppressReturn property setting. But I don't think we should add this feature in a patch release. We should talk to @hansemannn about it. Ideally, we should add such a feature on both Android and iOS at the same time.

Also, I think you mean "carriage return", not "cartridge return". :)
The comments below need to be correct for this as well.

And perhaps calling the return key type "NEWLINE" instead of "CARRIAGE_RETURN" would be better as well. Especially since Android and iOS technically add a \n character, not a \r.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, "carriage". I guess I carrieged away typing it wrong...
If we rename the constant we can get replace it with "new line" everywhere.

Also, yes, I did not think about a patch release being inappropriate for new additions. Would a minor be fine if we push it together with iOS? For now I will comment the additional key in the dictionary. We can have a separate ticket for that if we are doing it.

Copy link
Contributor

Choose a reason for hiding this comment

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

The idea is new "features" and APIs should not go into patch releases. So, if we're adding a new API, it's a new feature. And ideally, new APIs should be discussed with Hans (iOS) and Kota (Windows) in advance for their feedback and so they can schedule it to be implemented in the future.

That said, we do allow "enhancements" in a patch release from time to time. That's a gray-area for us. But typically its a change in behavior for an existing API (assuming it's not a breaking change). Any enhancements we want to add to a patch release needs to be a team decision beyond you and I.

// 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of checking if getMaxLines() is 1, we should use the field member variable instead. It'll be set to true for TextFields.

Note that upcoming PR #9927 will make max-lines settable and I don't want you to get burned by this.

@jquick-axway
Copy link
Contributor

@ypbnv, do you have a bluetooth keyboard you can test with on your Android phone? We may want to double check the handling of the return key from the keyboard as well.

Rename constant.
Change the check for UIText being a field or area.
@ypbnv
Copy link
Contributor Author

ypbnv commented Mar 21, 2018

@jquick-axway Yes, I can get my hands on a bluetooth keyboard to check if everything is fine.

@ypbnv
Copy link
Contributor Author

ypbnv commented Mar 22, 2018

@jquick-axway Tried a bluetooth keyboard with a tablet (Samsung Galaxy Tab S) and a phone (Samsung S8). Both in landscape and portrait. Hitting the return key on the keyboard is handled as a KeyEvent in all cases. And the result is that our Ti.UI.TextField.return and Ti.UI.TextArea.return events are fired twice. No matter if the component has returnKeyType set.
This is fixed after applying the change from #9948 together with this PR.
I suspect this is the case the customer had, because it matches the behavior with versions as reported.

Copy link
Contributor

@jquick-axway jquick-axway left a comment

Choose a reason for hiding this comment

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

Just one more minor edit. Everything else is fine. Thanks!

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
Contributor

Choose a reason for hiding this comment

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

Let's get rid of this description since we're not offering this new property yet.

@lokeshchdhry
Copy link
Contributor

FR Passed.

return event is successfully fired for all returnKeyType.

Studio Ver: 5.1.0
SDK Ver: 7.2.0.GA
OS Ver: 10.13.2
Xcode Ver: Xcode 9.2
Appc NPM: 4.2.12
Appc CLI: 7.0.2
Daemon Ver: 1.0.1
Ti CLI Ver: 5.0.14
Alloy Ver: 1.11.0
Node Ver: 8.9.1
NPM Ver: 5.5.1
Java Ver: 1.8.0_131
Devices: ⇨ google Nexus 5 --- Android 6.0.1
⇨ google Nexus 6P --- Android 8.0.0

@lokeshchdhry
Copy link
Contributor

Waiting for CR to pass.

@build build added the android label Mar 26, 2018
@lokeshchdhry lokeshchdhry merged commit 86e03d1 into tidev:master Mar 26, 2018
@sgtcoolguy sgtcoolguy modified the milestones: 7.2.0, 7.3.0 May 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants