diff --git a/app/src/main/java/com/jocmp/basilreader/ui/articles/ArticleScreen.kt b/app/src/main/java/com/jocmp/basilreader/ui/articles/ArticleScreen.kt index 94dc96b9..6c5e85f5 100644 --- a/app/src/main/java/com/jocmp/basilreader/ui/articles/ArticleScreen.kt +++ b/app/src/main/java/com/jocmp/basilreader/ui/articles/ArticleScreen.kt @@ -1,6 +1,5 @@ package com.jocmp.basilreader.ui.articles -import androidx.activity.compose.BackHandler import androidx.compose.material3.DrawerValue import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi import androidx.compose.material3.adaptive.ListDetailPaneScaffoldRole @@ -12,7 +11,6 @@ import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.saveable.rememberSaveable import com.jocmp.basilreader.ui.accounts.AccountViewModel import com.jocmp.basilreader.ui.components.EmptyView -import kotlinx.coroutines.delay import kotlinx.coroutines.launch import org.koin.androidx.compose.koinViewModel @@ -31,11 +29,6 @@ fun ArticleScreen( setDestination(ListDetailPaneScaffoldRole.Detail) } - BackHandler(viewModel.article != null) { - setDestination(ListDetailPaneScaffoldRole.List) - viewModel.clearArticle() - } - ArticleScaffold( drawerState = drawerState, listDetailState = scaffoldState, @@ -47,7 +40,7 @@ fun ArticleScreen( onFeedSelect = { viewModel.selectFeed(it) { coroutineScope.launch { - delay(100) + setDestination(ListDetailPaneScaffoldRole.List) drawerState.close() } } @@ -66,7 +59,13 @@ fun ArticleScreen( } ?: EmptyView(fillSize = true) }, detailPane = { - ArticleView(article = viewModel.article) + ArticleView( + article = viewModel.article, + onBackPressed = { + viewModel.clearArticle() + setDestination(ListDetailPaneScaffoldRole.List) + } + ) } ) } diff --git a/app/src/main/java/com/jocmp/basilreader/ui/articles/ArticleView.kt b/app/src/main/java/com/jocmp/basilreader/ui/articles/ArticleView.kt index e563f142..db24c791 100644 --- a/app/src/main/java/com/jocmp/basilreader/ui/articles/ArticleView.kt +++ b/app/src/main/java/com/jocmp/basilreader/ui/articles/ArticleView.kt @@ -1,13 +1,21 @@ package com.jocmp.basilreader.ui.articles +import androidx.activity.compose.BackHandler import androidx.compose.runtime.Composable import com.jocmp.basil.db.Articles import com.jocmp.basilreader.ui.components.WebView import com.jocmp.basilreader.ui.components.rememberWebViewStateWithHTMLData @Composable -fun ArticleView(article: Articles?) { +fun ArticleView( + article: Articles?, + onBackPressed: () -> Unit +) { val state = rememberWebViewStateWithHTMLData(article?.content_html ?: "
") WebView(state) + + BackHandler(article != null) { + onBackPressed() + } } diff --git a/app/src/main/java/com/jocmp/basilreader/ui/components/WebView.kt b/app/src/main/java/com/jocmp/basilreader/ui/components/WebView.kt index e634b775..77c833d2 100644 --- a/app/src/main/java/com/jocmp/basilreader/ui/components/WebView.kt +++ b/app/src/main/java/com/jocmp/basilreader/ui/components/WebView.kt @@ -64,7 +64,7 @@ import kotlinx.coroutines.withContext public fun WebView( state: WebViewState, modifier: Modifier = Modifier, - captureBackPresses: Boolean = true, + captureBackPresses: Boolean = false, navigator: WebViewNavigator = rememberWebViewNavigator(), onCreated: (WebView) -> Unit = {}, onDispose: (WebView) -> Unit = {},