fix(android): search crashes

This commit is contained in:
Tienson Qin
2025-12-13 00:59:55 +08:00
parent 56593a0924
commit b7cd27a92a

View File

@@ -7,6 +7,7 @@ import android.view.Gravity
import android.view.KeyEvent import android.view.KeyEvent
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import android.widget.EditText import android.widget.EditText
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.LinearLayout import android.widget.LinearLayout
@@ -276,6 +277,7 @@ class LiquidTabsPlugin : Plugin() {
val input = EditText(activity).apply { val input = EditText(activity).apply {
hint = "Search" hint = "Search"
setSingleLine(true) setSingleLine(true)
imeOptions = EditorInfo.IME_ACTION_SEARCH
setTextColor(labelColor) setTextColor(labelColor)
setHintTextColor(secondaryLabelColor) setHintTextColor(secondaryLabelColor)
// Remove EditText default background/border for a flat look // Remove EditText default background/border for a flat look
@@ -292,14 +294,38 @@ class LiquidTabsPlugin : Plugin() {
// Layout params to make EditText take most of the horizontal space // Layout params to make EditText take most of the horizontal space
layoutParams = LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f) layoutParams = LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f)
setOnKeyListener { _, keyCode, event -> setOnEditorActionListener { _, actionId, event ->
if (event.action == KeyEvent.ACTION_DOWN) { val isEnter =
when (keyCode) { actionId == EditorInfo.IME_ACTION_SEARCH ||
KeyEvent.KEYCODE_DEL -> notifyListeners("keyboardHackKey", JSObject().put("key", "backspace")) actionId == EditorInfo.IME_ACTION_DONE ||
KeyEvent.KEYCODE_ENTER -> notifyListeners("keyboardHackKey", JSObject().put("key", "enter")) actionId == EditorInfo.IME_ACTION_GO ||
} (event?.keyCode == KeyEvent.KEYCODE_ENTER)
if (isEnter) {
notifyListeners("keyboardHackKey", JSObject().put("key", "enter"))
true
} else {
false
}
}
setOnKeyListener { _, keyCode, event ->
when (keyCode) {
KeyEvent.KEYCODE_ENTER -> {
if (event.action == KeyEvent.ACTION_DOWN) {
notifyListeners("keyboardHackKey", JSObject().put("key", "enter"))
}
true
}
KeyEvent.KEYCODE_DEL -> {
if (text.isNullOrEmpty() && event.action == KeyEvent.ACTION_DOWN) {
notifyListeners("keyboardHackKey", JSObject().put("key", "backspace"))
true
} else {
false
}
}
else -> false
} }
false
} }
addTextChangedListener(object : TextWatcher { addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) { override fun afterTextChanged(s: Editable?) {