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

feat(android): new event for empty TextFields #13975

Merged
merged 4 commits into from
Jun 15, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading