refactor(article): use CapturedAnimatedVisibility for the overlay
CapturedAnimatedVisibility keeps a snapshot of the last frame while the overlay exits, so the manual lastShownArticle fallback is no longer needed to prevent flicker on close.
This commit is contained in:
1 parent
983e28fcf4
commit
f2b90026cd
1 file changed
+6
-8
@@ -2,7 +2,7 @@ package com.example.research.ui.navigation
|
|||||||
|
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.compose.animation.AnimatedContent
|
import androidx.compose.animation.AnimatedContent
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.CapturedAnimatedVisibility
|
||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.animation.fadeIn
|
||||||
import androidx.compose.animation.fadeOut
|
import androidx.compose.animation.fadeOut
|
||||||
import androidx.compose.animation.slideInHorizontally
|
import androidx.compose.animation.slideInHorizontally
|
||||||
@@ -23,7 +23,6 @@ import com.example.research.feature.search.SearchAction
|
|||||||
import com.example.research.feature.search.SearchViewModel
|
import com.example.research.feature.search.SearchViewModel
|
||||||
import com.example.research.ui.about.AboutScreen
|
import com.example.research.ui.about.AboutScreen
|
||||||
import com.example.research.ui.article.ArticleScreen
|
import com.example.research.ui.article.ArticleScreen
|
||||||
import com.example.research.ui.article.ArticleState
|
|
||||||
import com.example.research.ui.main.MainRoute
|
import com.example.research.ui.main.MainRoute
|
||||||
import com.example.research.ui.settings.SettingsRoute
|
import com.example.research.ui.settings.SettingsRoute
|
||||||
import com.example.research.ui.settings.SettingsViewModel
|
import com.example.research.ui.settings.SettingsViewModel
|
||||||
@@ -103,10 +102,6 @@ fun AppNavigation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val articleState by searchViewModel.selectedArticle.collectAsStateWithLifecycle()
|
val articleState by searchViewModel.selectedArticle.collectAsStateWithLifecycle()
|
||||||
var lastShownArticle by remember { mutableStateOf<ArticleState?>(null) }
|
|
||||||
LaunchedEffect(articleState) {
|
|
||||||
if (articleState != null) lastShownArticle = articleState
|
|
||||||
}
|
|
||||||
|
|
||||||
val effectiveScreen = when {
|
val effectiveScreen = when {
|
||||||
currentScreen == Screen.About -> Screen.About
|
currentScreen == Screen.About -> Screen.About
|
||||||
@@ -171,18 +166,20 @@ fun AppNavigation(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimatedVisibility(
|
CapturedAnimatedVisibility(
|
||||||
visible = currentScreen == Screen.Article && articleState != null,
|
visible = currentScreen == Screen.Article && articleState != null,
|
||||||
enter = fadeIn(tween(180)) + slideInHorizontally(tween(180)) { it / 3 },
|
enter = fadeIn(tween(180)) + slideInHorizontally(tween(180)) { it / 3 },
|
||||||
exit = fadeOut(tween(180)) + slideOutHorizontally(tween(180)) { it / 3 },
|
exit = fadeOut(tween(180)) + slideOutHorizontally(tween(180)) { it / 3 },
|
||||||
label = "articleOverlay",
|
label = "articleOverlay",
|
||||||
) {
|
) {
|
||||||
|
val state = articleState
|
||||||
|
if (state != null) {
|
||||||
Surface(
|
Surface(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
color = MaterialTheme.colorScheme.surface
|
color = MaterialTheme.colorScheme.surface
|
||||||
) {
|
) {
|
||||||
ArticleScreen(
|
ArticleScreen(
|
||||||
articleState = articleState ?: lastShownArticle,
|
articleState = state,
|
||||||
onNavigateBack = {
|
onNavigateBack = {
|
||||||
if (!searchViewModel.navigateBackFromArticle()) {
|
if (!searchViewModel.navigateBackFromArticle()) {
|
||||||
searchViewModel.onAction(SearchAction.ClearArticle)
|
searchViewModel.onAction(SearchAction.ClearArticle)
|
||||||
@@ -200,3 +197,4 @@ fun AppNavigation(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user