Merge branch 'fix/177-ime-insets' into release/v1.4.0

# Conflicts:
#	CHANGELOG.md
This commit is contained in:
makiolaj committed 2026-11-25 15:43:42 +01:00
commit 850ffcdfa3
3 files changed
+126 -1

No files matched your search

+4
View File
@@ -70,6 +70,10 @@ All notable changes to this project are documented here. The format follows
its due date. This reaches tasks you already have that have no reminders of
their own. A new task starting "now" still takes none from its start, which
would ring at once (#178).
- 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. The editor, task details and pickers kept the same
keyboard-sized gap at the bottom (#177).
## [1.3.2] - 2026-11-13
@@ -0,0 +1,121 @@
package de.jeanlucmakiola.agendula.ui
import android.graphics.Insets
import android.view.View
import android.view.WindowInsets
import android.view.WindowInsetsAnimation
import androidx.activity.ComponentActivity
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.WindowInsets as ComposeInsets
import androidx.compose.foundation.layout.ime
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.test.junit4.v2.createAndroidComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SdkSuppress
import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.agendula.ui.theme.AgendulaTheme
import de.jeanlucmakiola.floret.components.FullScreenPicker
import de.jeanlucmakiola.agendula.ui.theme.AgendulaDarkFallback
import de.jeanlucmakiola.agendula.ui.theme.AgendulaLightFallback
import de.jeanlucmakiola.floret.identity.FloretExpressiveTheme
import de.jeanlucmakiola.floret.identity.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 = 35)
class ImeInsetsResyncTest {
@get:Rule
val rule = createAndroidComposeRule<ComponentActivity>()
@Volatile
private var imeBottom = -1
@Volatile
private var root: View? = null
@Test
fun themeSettlesKeyboardInsetsAfterUserDrivenAnimation() {
setContent { AgendulaTheme { ImeReader() } }
runUserDrivenKeyboardAnimation()
rule.waitUntil(TIMEOUT_MS) { imeBottom == 0 }
}
@Test
fun pickerSettlesKeyboardInsetsAfterUserDrivenAnimation() {
setContent { FullScreenPicker(title = "", onDismiss = {}) { ImeReader() } }
runUserDrivenKeyboardAnimation()
rule.waitUntil(TIMEOUT_MS) { imeBottom == 0 }
}
@Test
fun themeWithoutResyncLeavesKeyboardInsetsAlone() {
setContent {
FloretExpressiveTheme(AgendulaLightFallback, AgendulaDarkFallback, resyncImeInsets = false) { ImeReader() }
}
runUserDrivenKeyboardAnimation()
assertStaysStale()
}
/** Shows the Compose behaviour [ImeInsetsResync] works around; drop it and this once this fails. */
@Test
fun withoutResyncKeyboardInsetsStayStale() {
setContent { ImeReader() }
runUserDrivenKeyboardAnimation()
assertStaysStale()
}
private fun assertStaysStale() {
val settled = runCatching { rule.waitUntil(STALE_WINDOW_MS) { imeBottom != KEYBOARD_PX } }.isSuccess
assertThat(settled).isFalse()
}
private fun setContent(content: @Composable () -> Unit) {
rule.runOnUiThread { rule.activity.enableEdgeToEdge() }
rule.setContent(content)
rule.waitUntil(TIMEOUT_MS) { root != null }
}
/** Reports the keyboard insets, and the window it sits in, as Compose sees them. */
@Composable
private fun ImeReader() {
val view = LocalView.current
val bottom = ComposeInsets.ime.getBottom(LocalDensity.current)
SideEffect {
imeBottom = bottom
root = view.rootView
}
}
private fun runUserDrivenKeyboardAnimation() {
val ime = WindowInsets.Type.ime()
val animation = WindowInsetsAnimation(ime, null, -1)
val keyboard = Insets.of(0, 0, 0, KEYBOARD_PX)
val decor = checkNotNull(root)
rule.runOnUiThread {
val midway = WindowInsets.Builder().setInsets(ime, keyboard).setVisible(ime, true).build()
decor.dispatchWindowInsetsAnimationPrepare(animation)
decor.dispatchWindowInsetsAnimationStart(animation, WindowInsetsAnimation.Bounds(Insets.NONE, keyboard))
decor.dispatchWindowInsetsAnimationProgress(midway, listOf(animation))
}
rule.waitForIdle()
assertThat(imeBottom).isEqualTo(KEYBOARD_PX)
rule.runOnUiThread { decor.dispatchWindowInsetsAnimationEnd(animation) }
rule.waitForIdle()
}
private companion object {
const val KEYBOARD_PX = 500
const val TIMEOUT_MS = 10_000L
const val STALE_WINDOW_MS = 2_000L
}
}