Shreyash Kore
02/05/2024, 5:17 PM/// Approach 1: Nested declarations
@Composable
fun MyView1(currentNum: Int) {
@Composable
fun InnerView(num: Int) {
Text(
"$num",
color = if (currentNum == num) Color.Red else Color.Black
)
}
for (i in 0..currentNum) {
InnerView(i)
}
}
/// Approach 2: Normal top level declarations
@Composable
fun MyView2(currentNum: Int) {
for (i in 0..currentNum) {
InnerView(i, currentNum)
}
}
@Composable
fun InnerView(num: Int, currentNum: Int) {
Text(
"$num",
color = if (currentNum == num) Color.Red else Color.Black
)
}
https://stackoverflow.com/questions/77940487/are-nested-composable-declarations-considered-as-an-antipatternephemient
02/05/2024, 5:23 PM@Composable
fun MyView1(currentNum: Int) {
val innerView = @Composable { num: Int ->
Text(
"$num",
color = if (currentNum == num) Color.Red else Color.Black
)
}
for (i in 0..currentNum) {
innerView(i)
}
}
Shreyash Kore
02/05/2024, 5:34 PMshikasd
02/05/2024, 7:51 PMvide
02/05/2024, 10:08 PMshikasd
02/05/2024, 10:55 PMShreyash Kore
02/06/2024, 5:56 PM