rajesh
06/15/2021, 4:50 PMval user by remember(profileViewModel) { profileViewModel.user }.collectAsState()
val posts by remember(profileViewModel) { profileViewModel.posts }.collectAsState()
when (user) {
is UiState.Loading -> {
CircularProgressIndicator(
modifier = Modifier.wrapContentWidth(CenterHorizontally)
)
}
is UiState.Success -> {
(user as UiState.Success).data?.let {
ProfileView(user = it)
}
}
}
when (posts) {
is UiState.Loading -> {
CircularProgressIndicator(
modifier = Modifier.wrapContentWidth(CenterHorizontally)
)
}
is UiState.Success -> {
(posts as UiState.Success).data?.let {
PostView(post = it)
}
}
}
How do i make sure that PostView()
is drawn below ProfileView()
?Zun
06/15/2021, 4:52 PMmartinsumera
06/15/2021, 4:53 PMColumn {
when (user) ….
when (posts) ….
}
rajesh
06/15/2021, 5:01 PMmartinsumera
06/15/2021, 5:02 PMrajesh
06/15/2021, 5:11 PMZun
06/15/2021, 5:12 PMrajesh
06/15/2021, 5:21 PMZun
06/15/2021, 5:22 PMrajesh
06/15/2021, 5:24 PMfun ProfileScreen(profileViewModel: ProfileViewModel) {
Column {
ProfileView(profileViewModel)
PostView(profileViewModel)
}
}
fun ProfileView(profileViewModel: ProfileViewModel) {
val user by remember(profileViewModel) { profileViewModel.user }.collectAsState()
when (user) {
is UiState.Loading -> {
CircularProgressIndicator(
modifier = Modifier.wrapContentWidth(CenterHorizontally)
)
}
is UiState.Success -> {
(user as UiState.Success).data?.let { user ->
Scaffold(
topBar = { ProfileAppBar(user) }
) { innerPadding ->
val modifier = Modifier.padding(innerPadding)
Column(modifier = modifier) {
UserInfo(user = user)
Spacer(modifier = Modifier.padding(top = 10.dp))
}
}
}
}
}
}
fun PostView(profileViewModel: ProfileViewModel) {
val posts by remember(profileViewModel) { profileViewModel.posts }.collectAsState()
when (posts) {
is UiState.Loading -> {
CircularProgressIndicator(
modifier = Modifier.wrapContentWidth(CenterHorizontally)
)
}
is UiState.Success -> {
Log.d(TAG, "posts: ${(posts as UiState.Success).data}")
(posts as UiState.Success).data?.let { posts ->
lazyGridFor(posts) { post, index ->
GridItem(post = post) {
}
}
}
}
}
}