From 100967c57bd7d9480fb3aa7d1d7fa8a71b4f1458 Mon Sep 17 00:00:00 2001 From: mcfans Date: Thu, 2 Nov 2023 00:37:21 +0800 Subject: [PATCH] fix: set focusable before request focus --- .../main/kotlin/com/carriez/flutter_hbb/InputService.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/InputService.kt b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/InputService.kt index b70d01374..48f0ec9aa 100644 --- a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/InputService.kt +++ b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/InputService.kt @@ -424,6 +424,9 @@ class InputService : AccessibilityService() { node.refresh() this.fakeEditTextForTextStateCalculation?.setSelection(0,0) this.fakeEditTextForTextStateCalculation?.setText(null) + + this.fakeEditTextForTextStateCalculation?.setFocusable(true) + this.fakeEditTextForTextStateCalculation?.setFocusableInTouchMode(true) val text = node.getText() var isShowingHint = false if (Build.VERSION.SDK_INT >= 26) { @@ -447,12 +450,14 @@ class InputService : AccessibilityService() { var success = false - val focused = this.fakeEditTextForTextStateCalculation?.isFocused + val previousFocusedState = this.fakeEditTextForTextStateCalculation?.isFocused this.fakeEditTextForTextStateCalculation?.let { it.requestFocus() } - Log.d(logTag, "existing text:$text textToCommit:$textToCommit textSelectionStart:$textSelectionStart textSelectionEnd:$textSelectionEnd $focused") + val nowFocusedState = this.fakeEditTextForTextStateCalculation?.isFocused + + Log.d(logTag, "existing text:$text textToCommit:$textToCommit textSelectionStart:$textSelectionStart textSelectionEnd:$textSelectionEnd previous focus: $previousFocusedState now focus: $nowFocusedState") if (textToCommit != null) { var newText = ""