From 61324a0072f91fa2fa174bb142fe2e79b1a56461 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Wed, 25 Nov 2026 12:09:15 +0100 Subject: [PATCH] Resync keyboard insets after a back-gesture dismissal (#177) --- CHANGELOG.md | 5 ++ .../agendula/ui/ImeInsetsResyncTest.kt | 79 +++++++++++++++++++ .../jeanlucmakiola/agendula/MainActivity.kt | 2 + floret-kit | 2 +- 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 app/src/androidTest/java/de/jeanlucmakiola/agendula/ui/ImeInsetsResyncTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index ca31fa1..8e0ee08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,11 @@ All notable changes to this project are documented here. The format follows all-day reminder time. With a tasks app as the store, both ends gain or drop their time together (#101). +### Fixed +- Closing the keyboard with the back gesture no longer leaves the task lists + squeezed into the top half of the screen, as if the keyboard were still open, + until it was opened again (#177). + ## [1.3.2] - 2026-11-13 ### Added diff --git a/app/src/androidTest/java/de/jeanlucmakiola/agendula/ui/ImeInsetsResyncTest.kt b/app/src/androidTest/java/de/jeanlucmakiola/agendula/ui/ImeInsetsResyncTest.kt new file mode 100644 index 0000000..02d0382 --- /dev/null +++ b/app/src/androidTest/java/de/jeanlucmakiola/agendula/ui/ImeInsetsResyncTest.kt @@ -0,0 +1,79 @@ +package de.jeanlucmakiola.agendula.ui + +import android.graphics.Insets +import android.view.View +import android.view.WindowInsets +import android.view.WindowInsetsAnimation +import androidx.compose.foundation.layout.WindowInsets as ComposeInsets +import androidx.compose.foundation.layout.ime +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalView +import androidx.compose.ui.test.junit4.v2.createComposeRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.SdkSuppress +import com.google.common.truth.Truth.assertThat +import de.jeanlucmakiola.floret.components.ImeInsetsResync +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +/** + * A keyboard hidden by a predictive back gesture runs an insets animation without a + * duration; Compose then keeps the last keyboard height it saw (#177). + */ +@RunWith(AndroidJUnit4::class) +@SdkSuppress(minSdkVersion = 30) +class ImeInsetsResyncTest { + + @get:Rule + val rule = createComposeRule() + + private var imeBottom = -1 + private lateinit var view: View + + @Test + fun keyboardInsetsSettleAfterUserDrivenAnimation() { + setContent(resync = true) + runUserDrivenKeyboardAnimation() + rule.waitUntil(TIMEOUT_MS) { imeBottom == 0 } + assertThat(imeBottom).isEqualTo(0) + } + + /** Shows the Compose behaviour [ImeInsetsResync] works around; drop both once this fails. */ + @Test + fun withoutResyncKeyboardInsetsStayStale() { + setContent(resync = false) + runUserDrivenKeyboardAnimation() + rule.waitForIdle() + assertThat(imeBottom).isEqualTo(KEYBOARD_PX) + } + + private fun setContent(resync: Boolean) { + rule.setContent { + if (resync) ImeInsetsResync() + view = LocalView.current + imeBottom = ComposeInsets.ime.getBottom(LocalDensity.current) + } + rule.waitForIdle() + } + + private fun runUserDrivenKeyboardAnimation() { + rule.runOnUiThread { + val root = view.rootView + val ime = WindowInsets.Type.ime() + val animation = WindowInsetsAnimation(ime, null, -1) + val keyboard = Insets.of(0, 0, 0, KEYBOARD_PX) + val midway = WindowInsets.Builder().setInsets(ime, keyboard).setVisible(ime, true).build() + root.dispatchWindowInsetsAnimationPrepare(animation) + root.dispatchWindowInsetsAnimationStart(animation, WindowInsetsAnimation.Bounds(Insets.NONE, keyboard)) + root.dispatchWindowInsetsAnimationProgress(midway, listOf(animation)) + root.dispatchWindowInsetsAnimationEnd(animation) + } + rule.waitForIdle() + } + + private companion object { + const val KEYBOARD_PX = 500 + const val TIMEOUT_MS = 2_000L + } +} diff --git a/app/src/main/java/de/jeanlucmakiola/agendula/MainActivity.kt b/app/src/main/java/de/jeanlucmakiola/agendula/MainActivity.kt index cc3aff0..c636d91 100644 --- a/app/src/main/java/de/jeanlucmakiola/agendula/MainActivity.kt +++ b/app/src/main/java/de/jeanlucmakiola/agendula/MainActivity.kt @@ -36,6 +36,7 @@ import de.jeanlucmakiola.agendula.ui.navigation.NavRequest import de.jeanlucmakiola.agendula.ui.settings.SettingsViewModel import de.jeanlucmakiola.agendula.ui.theme.AgendulaTheme import de.jeanlucmakiola.agendula.ui.theme.SystemTheme +import de.jeanlucmakiola.floret.components.ImeInsetsResync import de.jeanlucmakiola.floret.crash.CrashReportDialog import de.jeanlucmakiola.floret.crash.CrashReporter import de.jeanlucmakiola.floret.crash.submitCrashReport @@ -99,6 +100,7 @@ class MainActivity : ComponentActivity() { launchHooks.forEach { hook -> lifecycleScope.launch { runCatching { hook.onLaunch(intent) } } } } setContent { + ImeInsetsResync() val settingsViewModel: SettingsViewModel = hiltViewModel() val ui by settingsViewModel.state.collectAsStateWithLifecycle() val darkTheme = ui.settings.themeMode.isDark(isSystemInDarkTheme()) diff --git a/floret-kit b/floret-kit index 31281bb..2d40749 160000 --- a/floret-kit +++ b/floret-kit @@ -1 +1 @@ -Subproject commit 31281bb2245776f7f793e26fc8086c4233c77615 +Subproject commit 2d407495dbb908a4c415d16f401c5d0b37d86821