From 80197aff00dd66e11751632afbe5b3702df059f1 Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Tue, 20 Oct 2026 15:17:34 -0400 Subject: [PATCH] add keyboard inset workaround to MainActivity Should be reverted once https://github.com/flutter/flutter/issues/191156 is fixed --- .../nexus/federated/nexus/MainActivity.kt | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/kotlin/nexus/federated/nexus/MainActivity.kt b/android/app/src/main/kotlin/nexus/federated/nexus/MainActivity.kt index 25aab2f..f2b0f68 100644 --- a/android/app/src/main/kotlin/nexus/federated/nexus/MainActivity.kt +++ b/android/app/src/main/kotlin/nexus/federated/nexus/MainActivity.kt @@ -1,5 +1,40 @@ package nexus.federated.nexus +import android.os.Build +import android.os.Bundle +import android.view.View +import android.view.WindowInsets +import android.view.WindowInsetsAnimation import io.flutter.embedding.android.FlutterActivity -class MainActivity: FlutterActivity() +// TODO: Revert this commit once https://github.com/flutter/flutter/issues/191156 is fixed +class MainActivity: FlutterActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) return + + window.decorView.setWindowInsetsAnimationCallback( + object : WindowInsetsAnimation.Callback(DISPATCH_MODE_CONTINUE_ON_SUBTREE) { + override fun onProgress( + insets: WindowInsets, + runningAnimations: List, + ) = insets + + override fun onEnd(animation: WindowInsetsAnimation) { + if ((animation.typeMask and WindowInsets.Type.ime()) != 0) reapplyInsets() + } + }, + ) + } + + override fun onWindowFocusChanged(hasFocus: Boolean) { + super.onWindowFocusChanged(hasFocus) + if (hasFocus && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) reapplyInsets() + } + + // Posted so it runs after Flutter has applied any insets it deferred. + private fun reapplyInsets() { + val view = findViewById(FLUTTER_VIEW_ID) ?: return + view.post { view.rootWindowInsets?.let(view::onApplyWindowInsets) } + } +}