Skip to content

Commit

Permalink
Reset home screen scroll position when selected feed state changes (#181
Browse files Browse the repository at this point in the history
)
  • Loading branch information
msasikanth authored Dec 5, 2023
1 parent 473de78 commit 2d3cf53
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@ sealed interface HomeEffect {
data object MinimizeSheet : HomeEffect

class ShowError(val homeErrorType: HomeErrorType) : HomeEffect

data object ScrollToTop : HomeEffect
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.distinctUntilChangedBy
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
Expand Down Expand Up @@ -224,8 +223,6 @@ class HomePresenter(
it.copy(selectedFeed = selectedFeed, posts = posts, featuredPosts = featuredPosts)
}
}
.distinctUntilChangedBy { (selectedFeed, _, _) -> selectedFeed }
.onEach { effects.emit(HomeEffect.ScrollToTop) }
.launchIn(coroutineScope)

settingsRepository.enableFeaturedItemBlur
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,15 @@ internal fun HomeScreen(homePresenter: HomePresenter, modifier: Modifier = Modif
is HomeEffect.ShowError -> {
displayErrorMessage(effect, strings, bottomSheetScaffoldState)
}
is HomeEffect.ScrollToTop -> {
listState.scrollToItem(0)
featuredPostsPagerState.scrollToPage(0)
}
}
}
}

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

LaunchedEffect(bottomSheetState.targetValue) {
if (bottomSheetState.targetValue == BottomSheetValue.Collapsed) {
homePresenter.dispatch(HomeEvent.OnCancelAddFeedClicked)
Expand Down

0 comments on commit 2d3cf53

Please sign in to comment.