fix(player): 修复评论输入聚焦时面板消失

This commit is contained in:
Zhou Weidong committed 2026-10-21 12:40:12 +08:00
1 parent 226ac5920c
commit c7b230263a
4 files changed
+399 -280

No files matched your search

@@ -8,6 +8,8 @@ import android.content.res.Configuration
import android.os.Build
import android.util.Rational
import android.content.pm.PackageManager
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
@@ -16,6 +18,8 @@ class MainActivity : FlutterActivity() {
private val shareRequestCode = 9041
private var pendingShare: MethodChannel.Result? = null
private var pipChannel: MethodChannel? = null
private var keyboardChannel: MethodChannel? = null
private var imeInset = 0
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
@@ -62,6 +66,37 @@ class MainActivity : FlutterActivity() {
result.error("share_failed", error.message, null)
}
}
keyboardChannel = MethodChannel(
flutterEngine.dartExecutor.binaryMessenger,
"com.stormg.lumadrama/keyboard"
)
keyboardChannel?.setMethodCallHandler { call, result ->
if (call.method != "get") {
result.notImplemented()
return@setMethodCallHandler
}
val inset = currentImeInset()
emitImeInset(inset)
result.success(inset)
}
val decorView = window.decorView
ViewCompat.setOnApplyWindowInsetsListener(decorView) { view, insets ->
emitImeInset(insets.getInsets(WindowInsetsCompat.Type.ime()).bottom)
ViewCompat.onApplyWindowInsets(view, insets)
}
ViewCompat.requestApplyInsets(decorView)
}
private fun currentImeInset(): Int =
ViewCompat.getRootWindowInsets(window.decorView)
?.getInsets(WindowInsetsCompat.Type.ime())
?.bottom
?: 0
private fun emitImeInset(value: Int) {
if (value == imeInset) return
imeInset = value
keyboardChannel?.invokeMethod("insetsChanged", value)
}
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration) {
@@ -77,4 +112,11 @@ class MainActivity : FlutterActivity() {
pendingShare = null
}
}
override fun onDestroy() {
ViewCompat.setOnApplyWindowInsetsListener(window.decorView, null)
keyboardChannel?.setMethodCallHandler(null)
keyboardChannel = null
super.onDestroy()
}
}