Skip to content

Commit 50bb461

Browse files
committed
Remove more inline Composables
1 parent 890e4ec commit 50bb461

File tree

1 file changed

+63
-29
lines changed
  • app/src/main/java/com/cornellappdev/android/eatery/ui/screens

1 file changed

+63
-29
lines changed

app/src/main/java/com/cornellappdev/android/eatery/ui/screens/HomeScreen.kt

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ private fun HomeScrollableMainContent(
322322
onReload: () -> Unit
323323
) {
324324
val listState = rememberLazyListState()
325+
val filterRowState = rememberLazyListState()
325326
val isFirstVisible =
326327
remember { derivedStateOf { listState.firstVisibleItemIndex > 0 } }
327328

@@ -331,36 +332,19 @@ private fun HomeScrollableMainContent(
331332
if (favorites.isNotEmpty()) {
332333
lastFavorite = favorites[0]
333334
}
334-
val filterRowState = rememberLazyListState()
335-
val homeLazyColumn: @Composable (LazyListScope.() -> Unit) -> Unit = { content ->
336-
LazyColumn(
337-
state = listState,
338-
modifier = Modifier
339-
.fillMaxSize()
340-
) {
341-
stickyHeader {
342-
HomeStickyHeader(
343-
collapsed = isFirstVisible.value,
344-
loaded = eateriesApiResponse is EateryApiResponse.Success,
345-
onSearchClick = onSearchClick,
346-
onNotificationsClick = onNotificationsClick
347-
)
348-
}
349-
item {
350-
HomeMainHeader(
351-
onSearchClick = onSearchClick,
352-
selectedFilters = selectedFilters,
353-
onFilterClicked = onFilterClicked,
354-
filters = filters,
355-
filterRowState = filterRowState
356-
)
357-
}
358-
content()
359-
}
360-
}
361335
when (eateriesApiResponse) {
362336
is EateryApiResponse.Success -> {
363-
homeLazyColumn {
337+
HomeLazyColumn(
338+
listState = listState,
339+
collapsed = isFirstVisible.value,
340+
loaded = true,
341+
onSearchClick = onSearchClick,
342+
onNotificationsClick = onNotificationsClick,
343+
selectedFilters = selectedFilters,
344+
onFilterClicked = onFilterClicked,
345+
filters = filters,
346+
filterRowState = filterRowState
347+
) {
364348
regularContent(
365349
eateriesApiResponse,
366350
selectedFilters,
@@ -379,7 +363,17 @@ private fun HomeScrollableMainContent(
379363
}
380364

381365
is EateryApiResponse.Pending -> {
382-
homeLazyColumn {
366+
HomeLazyColumn(
367+
listState = listState,
368+
collapsed = isFirstVisible.value,
369+
loaded = false,
370+
onSearchClick = onSearchClick,
371+
onNotificationsClick = onNotificationsClick,
372+
selectedFilters = selectedFilters,
373+
onFilterClicked = onFilterClicked,
374+
filters = filters,
375+
filterRowState = filterRowState
376+
) {
383377
items(MainLoadingItem.mainItems) { item ->
384378
CreateMainLoadingItem(item, shimmer)
385379
}
@@ -409,6 +403,46 @@ private fun HomeScrollableMainContent(
409403
}
410404
}
411405

406+
@OptIn(ExperimentalFoundationApi::class)
407+
@Composable
408+
private fun HomeLazyColumn(
409+
listState: LazyListState,
410+
collapsed: Boolean,
411+
loaded: Boolean,
412+
onSearchClick: () -> Unit,
413+
onNotificationsClick: () -> Unit,
414+
selectedFilters: List<Filter>,
415+
onFilterClicked: (Filter) -> Unit,
416+
filters: List<Filter>,
417+
filterRowState: LazyListState,
418+
content: LazyListScope.() -> Unit
419+
) {
420+
LazyColumn(
421+
state = listState,
422+
modifier = Modifier
423+
.fillMaxSize()
424+
) {
425+
stickyHeader {
426+
HomeStickyHeader(
427+
collapsed = collapsed,
428+
loaded = loaded,
429+
onSearchClick = onSearchClick,
430+
onNotificationsClick = onNotificationsClick
431+
)
432+
}
433+
item {
434+
HomeMainHeader(
435+
onSearchClick = onSearchClick,
436+
selectedFilters = selectedFilters,
437+
onFilterClicked = onFilterClicked,
438+
filters = filters,
439+
filterRowState = filterRowState
440+
)
441+
}
442+
content()
443+
}
444+
}
445+
412446
@Composable
413447
fun ErrorContent(onTryAgain: () -> Unit) {
414448
Column(

0 commit comments

Comments
 (0)