Skip to content

Commit

Permalink
feat(android): new event for empty TextFields (#13975)
Browse files Browse the repository at this point in the history
* feat(android): new event for empty TextFields

* docs and length check

* rename and check for listener
  • Loading branch information
m1ga authored Jun 15, 2024
1 parent afb253e commit 29964cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ public void onLayoutChange(
this.tv.setOnEditorActionListener(this);
this.tv.setOnFocusChangeListener(this);
this.tv.setIncludeFontPadding(true);
if (proxy.hasListeners("empty")) {
this.tv.setOnKeyListener(new View.OnKeyListener()
{
@Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if (tv.getText().length() == 0) {
KrollDict data = new KrollDict();
data.put("keyCode", keyCode);
fireEvent("empty", data);
}
return false;
}
});
}

if (field) {
this.tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
} else {
Expand Down
9 changes: 9 additions & 0 deletions apidoc/Titanium/UI/TextField.yml
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,15 @@ events:
summary: New value of the field.
type: String

- name: empty
summary: Fired when the field is empty and you press backspace key again.
since: {android: "12.4.0"}
platforms: [android]
properties:
- name: keyCode
summary: Key code of the key.
type: Number

- name: focus
summary: Fired when the field gains focus.
properties:
Expand Down

0 comments on commit 29964cf

Please sign in to comment.