Skip to content

Commit 3f20ab9

Browse files
authored
Fix unnecessary invalidation and redraws on Desktop (JetBrains#2628)
Fixes unnecessary invalidation and redraws on Desktop caused by WindowInsetsRulers Fixes [CMP-9399](https://youtrack.jetbrains.com/issue/CMP-9399) WindowInsetsRulers cause invalidations on Desktop Fixes [CMP-9385](https://youtrack.jetbrains.com/issue/CMP-9385) Fix Desktop ApplicationTest after merging 1.11.0-alpha01 ## Testing `onGloballyPositioned is not called repeatedly with same position on screen` no longer ignored This should be tested by QA ## Release Notes ### Fixes - Desktop - Fix unnecessary redraws caused by `WindowInsetsRulers` implementation using `RulerScope.coordinates.size`
1 parent 7353e1a commit 3f20ab9

3 files changed

Lines changed: 4 additions & 28 deletions

File tree

compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/window/ApplicationTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import kotlinx.coroutines.CompletableDeferred
5151
import kotlinx.coroutines.delay
5252
import org.junit.Assume.assumeFalse
5353
import org.junit.Assume.assumeTrue
54-
import org.junit.Ignore
5554
import org.junit.Test
5655

5756
class ApplicationTest {
@@ -266,7 +265,6 @@ class ApplicationTest {
266265
}
267266

268267
@Test
269-
@Ignore // TODO: https://youtrack.jetbrains.com/issue/CMP-9385 , Ignored after merging 1.11.0-alpha01
270268
fun `onGloballyPositioned is not called repeatedly with same position on screen`() = runApplicationTest(useDelay = true) {
271269
lateinit var window: ComposeWindow
272270
val positionsOnScreen = mutableListOf<Offset>()

compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/layout/WindowInsetsRulers.skiko.kt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,10 @@ internal actual fun findInsetsAnimationProperties(
5858
return NoWindowInsetsAnimation
5959
}
6060

61-
internal class RulerProviderModifierElement(
61+
internal data class RulerProviderModifierElement(
6262
val windowInsets: PlatformWindowInsets
6363
): ModifierNodeElement<RulerProviderModifierNode>() {
6464
override fun create(): RulerProviderModifierNode = RulerProviderModifierNode(windowInsets)
65-
override fun hashCode(): Int = windowInsets.hashCode()
66-
override fun equals(other: Any?): Boolean {
67-
if (other === this) {
68-
return true
69-
}
70-
return (other as? RulerProviderModifierElement)?.windowInsets === windowInsets
71-
}
7265
override fun update(node: RulerProviderModifierNode) {
7366
node.windowInsets = windowInsets
7467
}
@@ -90,9 +83,7 @@ internal class RulerProviderModifierNode(
9083
}
9184
}
9285

93-
val rulerLambda: RulerScope.() -> Unit = {
94-
val (width, height) = coordinates.size
95-
86+
fun rulerLambda(width: Int, height: Int): RulerScope.() -> Unit = {
9687
provideInsetsValues(CaptionBar, windowInsets.captionBar, width, height)
9788
provideInsetsValues(DisplayCutout, windowInsets.displayCutout, width, height)
9889
provideInsetsValues(Ime, windowInsets.ime, width, height)
@@ -158,7 +149,7 @@ internal class RulerProviderModifierNode(
158149
val placeable = measurable.measure(constraints)
159150
val width = placeable.width
160151
val height = placeable.height
161-
return layout(width, height, rulers = rulerLambda) { placeable.place(0, 0) }
152+
return layout(width, height, rulers = rulerLambda(width, height)) { placeable.place(0, 0) }
162153
}
163154

164155
override val traverseKey: Any

compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/platform/PlatformWindowInsetsProviderNode.skiko.kt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,12 @@ abstract class PlatformWindowInsetsProviderNode(
7070
internal fun Modifier.excludeWindowInsets(safeInsets: Boolean, ime: Boolean) = this.then(
7171
ExcludedWindowInsetsProviderModifierElement(safeInsets, ime))
7272

73-
private class ExcludedWindowInsetsProviderModifierElement(
73+
private data class ExcludedWindowInsetsProviderModifierElement(
7474
private val safeInsets: Boolean,
7575
private val ime: Boolean,
7676
): ModifierNodeElement<ExcludedWindowInsetsProviderNode>() {
7777
override fun create(): ExcludedWindowInsetsProviderNode = ExcludedWindowInsetsProviderNode(safeInsets, ime)
78-
7978
override fun update(node: ExcludedWindowInsetsProviderNode) = node.update(safeInsets, ime)
80-
81-
override fun hashCode(): Int {
82-
var result = safeInsets.hashCode()
83-
result = 31 * result + ime.hashCode()
84-
return result
85-
}
86-
87-
override fun equals(other: Any?): Boolean {
88-
if (this === other) return true
89-
if (other !is ExcludedWindowInsetsProviderModifierElement) return false
90-
return safeInsets == other.safeInsets && ime == other.ime
91-
}
9279
}
9380

9481
private class ExcludedWindowInsetsProviderNode(

0 commit comments

Comments
 (0)