forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Invalidate parent layer every time child layer is invalidated
Fixes JetBrains/compose-multiplatform#4681 The issue was because of this situation: - the parent RenderNodeLayer is drawn and cached it's `picture` - the child RenderNodeLayer isn't drawn, but `invalidate` is called the child's `invalidate` should invalidate parent layer unconditionally, but we called it only if the child was drawn (picture != null), which is incorrect. It is a regression after #1260, but it just revealed the bug, not introduced it. ## Testing - new added tests fail before, work after the fix - the issue is no longer reproducible This should be tested by QA ## Release Notes > Fixes - Multiple Platforms - _(prerelease fix)_ Fix frozen composition with pager and text field
- Loading branch information
Showing
3 changed files
with
132 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
compose/ui/ui/src/skikoTest/kotlin/androidx/compose/ui/platform/GraphicLayerBugTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2024 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package androidx.compose.ui.platform | ||
|
||
import androidx.compose.foundation.Canvas | ||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.pager.HorizontalPager | ||
import androidx.compose.foundation.pager.rememberPagerState | ||
import androidx.compose.material.Scaffold | ||
import androidx.compose.material.TextField | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.assertThat | ||
import androidx.compose.ui.draw.drawBehind | ||
import androidx.compose.ui.isEqualTo | ||
import androidx.compose.ui.test.ExperimentalTestApi | ||
import androidx.compose.ui.test.runComposeUiTest | ||
import androidx.compose.ui.unit.dp | ||
import kotlin.test.Test | ||
|
||
// Tests for fixed bugs | ||
class GraphicLayerBugTest { | ||
// https://github.com/JetBrains/compose-multiplatform/issues/4681 | ||
@OptIn(ExperimentalTestApi::class, ExperimentalFoundationApi::class) | ||
@Test | ||
fun draw_invalidates_inside_complex_layout() = | ||
runComposeUiTest { | ||
var valueForDraw by mutableStateOf(0f) | ||
var lastDrawnValue = -1f | ||
|
||
setContent { | ||
val pagerState = rememberPagerState { 1 } | ||
Scaffold( | ||
modifier = Modifier.fillMaxSize(), | ||
topBar = { | ||
Spacer(Modifier.drawBehind { pagerState.targetPage }) | ||
}, | ||
) { | ||
HorizontalPager(modifier = Modifier.fillMaxSize(), state = pagerState) { | ||
var value by remember { mutableStateOf("") } | ||
TextField( | ||
value = value, | ||
onValueChange = { value = it }, | ||
) | ||
|
||
Canvas(Modifier.size(40.dp)) { | ||
lastDrawnValue = valueForDraw | ||
} | ||
} | ||
} | ||
} | ||
|
||
waitForIdle() | ||
assertThat(lastDrawnValue).isEqualTo(0f) | ||
|
||
valueForDraw = 1f | ||
waitForIdle() | ||
assertThat(lastDrawnValue).isEqualTo(1f) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters