Skip to content

Commit 530cb95

Browse files
committed
Use LazyColumn instead of for loop
1 parent 1a69a09 commit 530cb95

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

app/src/main/java/com/example/nav3recipes/passingarguments/basicviewmodels/BasicViewModelsActivity.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.example.nav3recipes.passingarguments.basicviewmodels
1919
import android.os.Bundle
2020
import androidx.activity.ComponentActivity
2121
import androidx.activity.compose.setContent
22+
import androidx.compose.foundation.lazy.LazyColumn
2223
import androidx.compose.material3.Button
2324
import androidx.compose.material3.Text
2425
import androidx.compose.runtime.Composable
@@ -65,11 +66,13 @@ class BasicViewModelsActivity : ComponentActivity() {
6566
entryProvider = entryProvider {
6667
entry<RouteA> {
6768
ContentGreen("Welcome to Nav3") {
68-
for (i in 0 .. 10){
69-
Button(onClick = {
70-
backStack.add(RouteB("$i"))
71-
}) {
72-
Text("$i")
69+
LazyColumn {
70+
items(10) { i ->
71+
Button(onClick = {
72+
backStack.add(RouteB("$i"))
73+
}) {
74+
Text("$i")
75+
}
7376
}
7477
}
7578
}

app/src/main/java/com/example/nav3recipes/passingarguments/injectedviewmodels/InjectedViewModelsActivity.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.example.nav3recipes.passingarguments.injectedviewmodels
1919
import android.os.Bundle
2020
import androidx.activity.ComponentActivity
2121
import androidx.activity.compose.setContent
22+
import androidx.compose.foundation.lazy.LazyColumn
2223
import androidx.compose.material3.Button
2324
import androidx.compose.material3.Text
2425
import androidx.compose.runtime.Composable
@@ -34,6 +35,7 @@ import androidx.navigation3.ui.NavDisplay
3435
import androidx.navigation3.ui.rememberSceneSetupNavEntryDecorator
3536
import com.example.nav3recipes.content.ContentBlue
3637
import com.example.nav3recipes.content.ContentGreen
38+
import com.example.nav3recipes.passingarguments.basicviewmodels.RouteB
3739
import com.example.nav3recipes.ui.setEdgeToEdgeConfig
3840
import dagger.assisted.Assisted
3941
import dagger.assisted.AssistedFactory
@@ -71,11 +73,13 @@ class InjectedViewModelsActivity : ComponentActivity() {
7173
entryProvider = entryProvider {
7274
entry<RouteA> {
7375
ContentGreen("Welcome to Nav3") {
74-
for (i in 0 .. 10){
75-
Button(onClick = {
76-
backStack.add(RouteB("$i"))
77-
}) {
78-
Text("$i")
76+
LazyColumn {
77+
items(10) { i ->
78+
Button(onClick = {
79+
backStack.add(RouteB("$i"))
80+
}) {
81+
Text("$i")
82+
}
7983
}
8084
}
8185
}

0 commit comments

Comments
 (0)