Skip to content

Commit

Permalink
Merge pull request #2139 from Aarontheissueguy/main
Browse files Browse the repository at this point in the history
Disabling suggestions on Android if readonly mode is set.
  • Loading branch information
freakboy3742 authored Oct 4, 2023
2 parents 38b2831 + 77805fe commit 7356cb2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
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.

0 comments on commit 7356cb2

Please sign in to comment.