in JetNews/app/src/main/java/com/example/jetnews/ui/home/HomeScreens.kt [120:200]
fun HomeFeedWithArticleDetailsScreen(
uiState: HomeUiState,
showTopAppBar: Boolean,
onToggleFavorite: (String) -> Unit,
onSelectPost: (String) -> Unit,
onRefreshPosts: () -> Unit,
onErrorDismiss: (Long) -> Unit,
onInteractWithList: () -> Unit,
onInteractWithDetail: (String) -> Unit,
openDrawer: () -> Unit,
homeListLazyListState: LazyListState,
articleDetailLazyListStates: Map<String, LazyListState>,
scaffoldState: ScaffoldState,
modifier: Modifier = Modifier,
onSearchInputChanged: (String) -> Unit,
) {
HomeScreenWithList(
uiState = uiState,
showTopAppBar = showTopAppBar,
onRefreshPosts = onRefreshPosts,
onErrorDismiss = onErrorDismiss,
openDrawer = openDrawer,
homeListLazyListState = homeListLazyListState,
scaffoldState = scaffoldState,
modifier = modifier,
) { hasPostsUiState, contentModifier ->
val contentPadding = rememberContentPaddingForScreen(additionalTop = 8.dp)
Row(contentModifier) {
PostList(
postsFeed = hasPostsUiState.postsFeed,
favorites = hasPostsUiState.favorites,
showExpandedSearch = !showTopAppBar,
onArticleTapped = onSelectPost,
onToggleFavorite = onToggleFavorite,
contentPadding = contentPadding,
modifier = Modifier
.width(334.dp)
.notifyInput(onInteractWithList)
.imePadding(), // add padding for the on-screen keyboard
state = homeListLazyListState,
searchInput = hasPostsUiState.searchInput,
onSearchInputChanged = onSearchInputChanged,
)
// Crossfade between different detail posts
Crossfade(targetState = hasPostsUiState.selectedPost) { detailPost ->
// Get the lazy list state for this detail view
val detailLazyListState by derivedStateOf {
articleDetailLazyListStates.getValue(detailPost.id)
}
// Key against the post id to avoid sharing any state between different posts
key(detailPost.id) {
LazyColumn(
state = detailLazyListState,
contentPadding = contentPadding,
modifier = Modifier
.padding(horizontal = 16.dp)
.fillMaxSize()
.notifyInput {
onInteractWithDetail(detailPost.id)
}
.imePadding() // add padding for the on-screen keyboard
) {
stickyHeader {
val context = LocalContext.current
PostTopBar(
isFavorite = hasPostsUiState.favorites.contains(detailPost.id),
onToggleFavorite = { onToggleFavorite(detailPost.id) },
onSharePost = { sharePost(detailPost, context) },
modifier = Modifier
.fillMaxWidth()
.wrapContentWidth(Alignment.End)
)
}
postContentItems(detailPost)
}
}
}
}
}
}