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 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
10 changes: 10 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,19 @@ 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
16 changes: 16 additions & 0 deletions android/tests_backend/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ 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()
if input_type & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS:
# TYPE_TEXT_FLAG_NO_SUGGESTIONS is set
if focusable:
raise ValueError(
"TYPE_TEXT_FLAG_NO_SUGGESTIONS is not set on the input."
)
else:
# TYPE_TEXT_FLAG_NO_SUGGESTIONS is not set
if not focusable:
raise ValueError(
"TYPE_TEXT_FLAG_NO_SUGGESTIONS has been set when the input is readonly."
)

return not focusable

async def type_character(self, char):
Expand Down
1 change: 1 addition & 0 deletions changes/2136.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Multiline text inputs no longer show spelling suggestions when in readonly mode.