Skip to content

Commit a9c32cd

Browse files
committed
Add keyboard height to WXKeyboardEventData and event handling
The WXKeyboardEventData model now includes a height property to provide the keyboard's pixel height. WXActivity has been updated to calculate and pass this value when posting keyboard events, and the event handler logic has been refactored to always listen for layout changes, improving keyboard visibility and height reporting.
1 parent 042bb84 commit a9c32cd

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

webui/src/main/kotlin/com/dergoogler/mmrl/webui/activity/WXActivity.kt

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -139,30 +139,31 @@ open class WXActivity : ComponentActivity() {
139139
registerBackEvents()
140140

141141
config {
142-
if (windowResize) {
143-
rootView.viewTreeObserver.addOnGlobalLayoutListener {
144-
val r = Rect()
145-
rootView.getWindowVisibleDisplayFrame(r)
146-
147-
val screenHeight = rootView.rootView.height
148-
val keypadHeight = screenHeight - r.bottom
149-
val keyboardVisibleNow = keypadHeight > screenHeight * 0.15
150-
151-
if (keyboardVisibleNow != isKeyboardShowing) {
152-
isKeyboardShowing = keyboardVisibleNow
153-
154-
view?.wx?.postWXEvent(
155-
WXEventHandler(
156-
WXEvent.WX_ON_KEYBOARD,
157-
WXKeyboardEventData(visible = keyboardVisibleNow)
142+
rootView.viewTreeObserver.addOnGlobalLayoutListener {
143+
val r = Rect()
144+
rootView.getWindowVisibleDisplayFrame(r)
145+
146+
val screenHeight = rootView.rootView.height
147+
val keypadHeight = screenHeight - r.bottom
148+
val keyboardVisibleNow = keypadHeight > screenHeight * 0.15
149+
150+
if (keyboardVisibleNow != isKeyboardShowing) {
151+
isKeyboardShowing = keyboardVisibleNow
152+
153+
view?.wx?.postWXEvent(
154+
WXEventHandler(
155+
WXEvent.WX_ON_KEYBOARD,
156+
WXKeyboardEventData(
157+
height = keypadHeight.asPx,
158+
visible = keyboardVisibleNow
158159
)
159160
)
161+
)
160162

161-
if (keyboardVisibleNow) {
162-
adjustWebViewHeight(keypadHeight)
163-
} else {
164-
resetWebViewHeight()
165-
}
163+
if (windowResize && keyboardVisibleNow) {
164+
adjustWebViewHeight(keypadHeight)
165+
} else {
166+
resetWebViewHeight()
166167
}
167168
}
168169
}
@@ -313,6 +314,9 @@ open class WXActivity : ComponentActivity() {
313314
}
314315
}
315316

317+
private val Int.asPx: Int
318+
get() = (this / baseContext.resources.displayMetrics.density).toInt()
319+
316320
companion object {
317321
private const val TAG = "WXActivity"
318322

webui/src/main/kotlin/com/dergoogler/mmrl/webui/model/Event.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ data class WXInsetsEventData(
2828

2929
@JsonClass(generateAdapter = true)
3030
data class WXKeyboardEventData(
31+
val height: Int,
3132
val visible: Boolean,
3233
)
3334

0 commit comments

Comments
 (0)