Hi Compose Team, I wrote a DemoApp with only two T...
# compose-android
z
Hi Compose Team, I wrote a DemoApp with only two Text(). In the first Text(), I started a coroutine to update the value every two seconds. As we expected, each time the number changes, only the first Text() is recompositioned. However, the redrawing occurred on the entire screen. I printed the log to check and found that after the RenderNode corresponding to the first Text() was invalidated, all its parent nodes were set to invalid, including AndroidComposeView, ComposeView, FrameLayout, LinearLayout, DecorView and RootRenderNode. I am confused why we have to redraw all ancestors of the RenderNode corresponding to the first Text() instead of just redrawing this one node?
Copy code
class ComposeTestActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            LazyColumn(Modifier.background(Color.White)) {
                item { MyMutableText() }
                item { MyText() }
            }
        }
    }
}

@Composable
fun MyMutableText() {
    var count by remember { mutableIntStateOf(10) }

    LaunchedEffect(count) {
        delay(2000L)
        count++
    }

    Text("Now Number is: $count")
}

@Composable
fun MyText() {
    Text("Demo")
}
r
It's how rendering has always worked on Android. Every thing is drawn back to front, so if the topmost item changes (your text here), all the pixels behind it need to be redrawn
Note that there are various optimizations happening, the biggest one being that the ancestor render nodes are not re-recorded
z
I am sorry I don't quite understand what you mean. According to what you said, if I use Compose to write the UI, then all controls like Text, Button, TextField... will be drawn on DecorView. So no matter where the recomposition occurs, the entire screen will be redrawn?
r
No. All ancestors will redraw but in a smaller portion of the screen
z
Could you check the video? I set debug.hwui.show_dirty_regions to 1 to show the redrawn regions. When recomposition happens, the whole screen is set to red.
c
z
Yes, but I think these two problems are not particularly similar. The previous one only redraws the Column() area, while the current one redraws the entire screen.
c
We are also usually optimizing for the case of scrolling lazy layouts that take the whole screen, and everything has to be redrawn anyways with such layout.
m
What about state management (remembersaveable, mutablestateof) for the textfield composable? Check that for avoiding recomposition
c
They do not care about recomposition but redrawing on the pixel layer.
z
Correct. Redraw area is more important to us.