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

Disabling suggestions on Android if readonly mode is set. #2139

Merged
merged 4 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions android/src/toga_android/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ def set_readonly(self, readonly):
if readonly:
# Implicitly calls setFocusableInTouchMode(False)
self.native.setFocusable(False)
# Add TYPE_TEXT_FLAG_NO_SUGGESTIONS to the input type to disable suggestions
input_type = self.native.getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
self.native.setInputType(input_type)
else:
# Implicitly calls setFocusable(True)
self.native.setFocusableInTouchMode(True)
# Remove TYPE_TEXT_FLAG_NO_SUGGESTIONS to enable suggestions
input_type = self.native.getInputType() & ~InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
self.native.setInputType(input_type)

def get_placeholder(self):
return str(self.native.getHint())
Expand Down
7 changes: 7 additions & 0 deletions android/tests_backend/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ def readonly(self):
focusable_in_touch_mode = self.native.isFocusableInTouchMode()
if focusable != focusable_in_touch_mode:
raise ValueError(f"invalid state: {focusable=}, {focusable_in_touch_mode=}")

# Check if TYPE_TEXT_FLAG_NO_SUGGESTIONS is set in the input type
input_type = self.native.getInputType()
is_no_suggestions_set = (input_type & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS) != 0
if not is_no_suggestions_set:
raise ValueError("readonly is True, but TYPE_TEXT_FLAG_NO_SUGGESTIONS is not set.")

return not focusable

async def type_character(self, char):
Expand Down
Loading