Keeping the position of the feed in navigation
This commit is contained in:
@@ -64,14 +64,10 @@ fun AppNavigation(
|
||||
composable(route.route, route.arguments, content = {
|
||||
val scrollToTop = it.arguments?.getBoolean("scrollToTop") ?: false
|
||||
|
||||
LaunchedEffect(key1 = it) {
|
||||
if (scrollToTop) {
|
||||
launch {
|
||||
videoFeedViewModel.sendToTop()
|
||||
it.arguments?.remove("scrollToTop")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VideoScreen(
|
||||
videoFeedView = videoFeedViewModel,
|
||||
@@ -85,14 +81,10 @@ fun AppNavigation(
|
||||
composable(route.route, route.arguments, content = {
|
||||
val scrollToTop = it.arguments?.getBoolean("scrollToTop") ?: false
|
||||
|
||||
LaunchedEffect(key1 = it) {
|
||||
if (scrollToTop) {
|
||||
launch {
|
||||
searchFeedViewModel.sendToTop()
|
||||
it.arguments?.remove("scrollToTop")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SearchScreen(
|
||||
searchFeedViewModel = searchFeedViewModel,
|
||||
@@ -107,15 +99,11 @@ fun AppNavigation(
|
||||
val scrollToTop = it.arguments?.getBoolean("scrollToTop") ?: false
|
||||
val nip47 = it.arguments?.getString("nip47")
|
||||
|
||||
LaunchedEffect(key1 = it) {
|
||||
if (scrollToTop) {
|
||||
launch {
|
||||
homeFeedViewModel.sendToTop()
|
||||
repliesFeedViewModel.sendToTop()
|
||||
it.arguments?.remove("scrollToTop")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HomeScreen(
|
||||
homeFeedViewModel = homeFeedViewModel,
|
||||
@@ -140,15 +128,11 @@ fun AppNavigation(
|
||||
composable(route.route, route.arguments, content = {
|
||||
val scrollToTop = it.arguments?.getBoolean("scrollToTop") ?: false
|
||||
|
||||
LaunchedEffect(key1 = it) {
|
||||
if (scrollToTop) {
|
||||
launch {
|
||||
notifFeedViewModel.clear()
|
||||
notifFeedViewModel.sendToTop()
|
||||
it.arguments?.remove("scrollToTop")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NotificationScreen(
|
||||
notifFeedViewModel = notifFeedViewModel,
|
||||
|
||||
@@ -287,8 +287,6 @@ private fun AuthorPictureAndComment(
|
||||
}
|
||||
}
|
||||
|
||||
println("AAAA $content")
|
||||
|
||||
content.first?.let {
|
||||
val route by remember {
|
||||
derivedStateOf {
|
||||
|
||||
@@ -54,12 +54,14 @@ open class CardFeedViewModel(val localFilter: FeedFilter<Note>) : ViewModel() {
|
||||
val scrollToTop = _scrollToTop.asStateFlow()
|
||||
var scrolltoTopPending = false
|
||||
|
||||
suspend fun sendToTop() {
|
||||
fun sendToTop() {
|
||||
if (scrolltoTopPending) return
|
||||
|
||||
scrolltoTopPending = true
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
_scrollToTop.emit(_scrollToTop.value + 1)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun sentToTop() {
|
||||
scrolltoTopPending = false
|
||||
|
||||
@@ -123,12 +123,14 @@ abstract class FeedViewModel(val localFilter: FeedFilter<Note>) : ViewModel() {
|
||||
val scrollToTop = _scrollToTop.asStateFlow()
|
||||
var scrolltoTopPending = false
|
||||
|
||||
suspend fun sendToTop() {
|
||||
fun sendToTop() {
|
||||
if (scrolltoTopPending) return
|
||||
|
||||
scrolltoTopPending = true
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
_scrollToTop.emit(_scrollToTop.value + 1)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun sentToTop() {
|
||||
scrolltoTopPending = false
|
||||
|
||||
@@ -141,13 +141,20 @@ fun WatchAccountForHomeScreen(
|
||||
val account = remember(accountState) { accountState?.account } ?: return
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
var firstTime by remember(accountViewModel) { mutableStateOf(true) }
|
||||
|
||||
LaunchedEffect(accountViewModel, account.defaultHomeFollowList) {
|
||||
// Only invalidate when things change. Not in the first run
|
||||
if (firstTime) {
|
||||
firstTime = false
|
||||
} else {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
NostrHomeDataSource.invalidateFilters()
|
||||
homeFeedViewModel.invalidateDataAndSendToTop(true)
|
||||
repliesFeedViewModel.invalidateDataAndSendToTop(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Immutable
|
||||
|
||||
+8
-5
@@ -103,14 +103,17 @@ fun WatchAccountForNotifications(
|
||||
val accountState by accountViewModel.accountLiveData.observeAsState()
|
||||
val account = remember(accountState) { accountState?.account } ?: return
|
||||
|
||||
LaunchedEffect(accountViewModel, account.defaultNotificationFollowList) {
|
||||
NostrAccountDataSource.invalidateFilters()
|
||||
if (notifFeedViewModel.scrollToTop.value > 0) {
|
||||
notifFeedViewModel.clear()
|
||||
}
|
||||
var firstTime by remember(accountViewModel) { mutableStateOf(true) }
|
||||
|
||||
LaunchedEffect(accountViewModel, account.defaultNotificationFollowList) {
|
||||
if (firstTime) {
|
||||
firstTime = false
|
||||
} else {
|
||||
NostrAccountDataSource.invalidateFilters()
|
||||
notifFeedViewModel.clear()
|
||||
notifFeedViewModel.invalidateDataAndSendToTop(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -133,10 +133,16 @@ fun WatchAccountForVideoScreen(videoFeedView: NostrVideoFeedViewModel, accountVi
|
||||
val accountState by accountViewModel.accountLiveData.observeAsState()
|
||||
val account = remember(accountState) { accountState?.account } ?: return
|
||||
|
||||
var firstTime by remember(accountViewModel) { mutableStateOf(true) }
|
||||
|
||||
LaunchedEffect(accountViewModel, account.defaultStoriesFollowList) {
|
||||
if (firstTime) {
|
||||
firstTime = false
|
||||
} else {
|
||||
NostrVideoDataSource.resetFilters()
|
||||
videoFeedView.invalidateDataAndSendToTop(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
|
||||
Reference in New Issue
Block a user