Skip to content

Commit 4bc9d3e

Browse files
authored
[jetcaster] Fixed the laggy scrolling (#614)
* Fixed the laggy scrolling Extracted the Category podcasts and Episode lists to separate composables * Addressed review comments. * Remove extra spaces
1 parent 0a024d5 commit 4bc9d3e

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

Jetcaster/app/src/main/java/com/example/jetcaster/ui/home/category/PodcastCategory.kt

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.example.jetcaster.ui.home.category
1919
import androidx.compose.foundation.Image
2020
import androidx.compose.foundation.clickable
2121
import androidx.compose.foundation.interaction.MutableInteractionSource
22+
import androidx.compose.foundation.layout.Arrangement
2223
import androidx.compose.foundation.layout.Box
2324
import androidx.compose.foundation.layout.Column
2425
import androidx.compose.foundation.layout.PaddingValues
@@ -67,6 +68,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
6768
import coil.compose.rememberImagePainter
6869
import com.example.jetcaster.R
6970
import com.example.jetcaster.data.Episode
71+
import com.example.jetcaster.data.EpisodeToPodcast
7072
import com.example.jetcaster.data.Podcast
7173
import com.example.jetcaster.data.PodcastWithExtraInfo
7274
import com.example.jetcaster.ui.home.PreviewEpisodes
@@ -98,20 +100,39 @@ fun PodcastCategory(
98100
/**
99101
* TODO: reset scroll position when category changes
100102
*/
101-
LazyColumn(
102-
modifier = modifier,
103+
Column(modifier = modifier) {
104+
CategoryPodcasts(viewState.topPodcasts, viewModel)
105+
EpisodeList(viewState.episodes)
106+
}
107+
}
108+
109+
@Composable
110+
private fun CategoryPodcasts(
111+
topPodcasts: List<PodcastWithExtraInfo>,
112+
viewModel: PodcastCategoryViewModel
113+
) {
114+
LazyRow(
103115
contentPadding = PaddingValues(0.dp),
104-
horizontalAlignment = Alignment.Start
116+
horizontalArrangement = Arrangement.Start
105117
) {
106118
item {
107119
CategoryPodcastRow(
108-
podcasts = viewState.topPodcasts,
120+
podcasts = topPodcasts,
109121
onTogglePodcastFollowed = viewModel::onTogglePodcastFollowed,
110122
modifier = Modifier.fillParentMaxWidth()
111123
)
112124
}
125+
}
126+
}
127+
128+
@Composable
129+
private fun EpisodeList(episodes: List<EpisodeToPodcast>) {
130+
LazyColumn(
131+
contentPadding = PaddingValues(0.dp),
132+
verticalArrangement = Arrangement.Center
133+
) {
113134

114-
items(viewState.episodes, key = { it.episode.uri }) { item ->
135+
items(episodes, key = { it.episode.uri }) { item ->
115136
EpisodeListItem(
116137
episode = item.episode,
117138
podcast = item.podcast,

0 commit comments

Comments
 (0)