Skip to content

Commit

Permalink
Don't let webview capture back events
Browse files Browse the repository at this point in the history
  • Loading branch information
jocmp committed Dec 21, 2023
1 parent 01be42b commit 02ac152
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -31,11 +29,6 @@ fun ArticleScreen(
setDestination(ListDetailPaneScaffoldRole.Detail)
}

BackHandler(viewModel.article != null) {
setDestination(ListDetailPaneScaffoldRole.List)
viewModel.clearArticle()
}

ArticleScaffold(
drawerState = drawerState,
listDetailState = scaffoldState,
Expand All @@ -47,7 +40,7 @@ fun ArticleScreen(
onFeedSelect = {
viewModel.selectFeed(it) {
coroutineScope.launch {
delay(100)
setDestination(ListDetailPaneScaffoldRole.List)
drawerState.close()
}
}
Expand All @@ -66,7 +59,13 @@ fun ArticleScreen(
} ?: EmptyView(fillSize = true)
},
detailPane = {
ArticleView(article = viewModel.article)
ArticleView(
article = viewModel.article,
onBackPressed = {
viewModel.clearArticle()
setDestination(ListDetailPaneScaffoldRole.List)
}
)
}
)
}
Original file line number Diff line number Diff line change
@@ -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 ?: "<div />")

WebView(state)

BackHandler(article != null) {
onBackPressed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {},
Expand Down

0 comments on commit 02ac152

Please sign in to comment.