Skip to content

Commit

Permalink
Fix home screen scroll position getting reset after navigation (#230)
Browse files Browse the repository at this point in the history
* Add effect to reset scroll position when selected feed is changed

* Remove launched effect for resetting scroll position based on selected feed

This is causing the scroll position to reset every time composition happens after navigation. Which is not ideal, so we are removing it.
  • Loading branch information
msasikanth authored Jan 19, 2024
1 parent 190c550 commit 512fcc2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ package dev.sasikanth.rss.reader.feeds
sealed interface FeedsEffect {

data object MinimizeSheet : FeedsEffect

data object SelectedFeedChanged : FeedsEffect
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ class FeedsPresenter(
if (_state.value.selectedFeed?.link != feed.link) {
observableSelectedFeed.selectFeed(feed)
}

effects.emit(FeedsEffect.SelectedFeedChanged)
effects.emit(FeedsEffect.MinimizeSheet)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ internal fun FeedsBottomSheet(
feedsSheetMode: FeedsSheetMode,
closeSheet: () -> Unit,
editFeeds: () -> Unit,
exitFeedsEdit: () -> Unit
exitFeedsEdit: () -> Unit,
selectedFeedChanged: () -> Unit
) {
val state by feedsPresenter.state.collectAsState()
val selectedFeed = state.selectedFeed
Expand All @@ -114,6 +115,7 @@ internal fun FeedsBottomSheet(
feedsPresenter.effects.collect { effect ->
when (effect) {
FeedsEffect.MinimizeSheet -> closeSheet()
FeedsEffect.SelectedFeedChanged -> selectedFeedChanged()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.coerceIn
import androidx.compose.ui.unit.dp
import androidx.paging.LoadState
import app.cash.paging.compose.collectAsLazyPagingItems
Expand Down Expand Up @@ -154,11 +153,6 @@ internal fun HomeScreen(homePresenter: HomePresenter, modifier: Modifier = Modif
}
}

LaunchedEffect(state.selectedFeed) {
listState.scrollToItem(0)
featuredPostsPagerState.scrollToPage(0)
}

LaunchedEffect(bottomSheetState.targetValue) {
if (bottomSheetState.targetValue == BottomSheetValue.Collapsed) {
homePresenter.dispatch(HomeEvent.OnCancelAddFeedClicked)
Expand Down Expand Up @@ -204,7 +198,13 @@ internal fun HomeScreen(homePresenter: HomePresenter, modifier: Modifier = Modif
feedsSheetMode = state.feedsSheetMode,
closeSheet = { coroutineScope.launch { bottomSheetState.collapse() } },
editFeeds = { homePresenter.dispatch(HomeEvent.EditFeedsClicked) },
exitFeedsEdit = { homePresenter.dispatch(HomeEvent.ExitFeedsEdit) }
exitFeedsEdit = { homePresenter.dispatch(HomeEvent.ExitFeedsEdit) },
selectedFeedChanged = {
coroutineScope.launch {
listState.scrollToItem(0)
featuredPostsPagerState.scrollToPage(0)
}
}
)
},
snackbarHost = {
Expand Down

0 comments on commit 512fcc2

Please sign in to comment.