Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backpress in Screen #336

Closed
CodeWithAthari opened this issue Feb 17, 2024 · 1 comment
Closed

Backpress in Screen #336

CodeWithAthari opened this issue Feb 17, 2024 · 1 comment

Comments

@CodeWithAthari
Copy link

How can i handle backPress in each screen individually.
I'm using WebView as AndroidView

AndroidView(
                modifier = Modifier
                    .fillMaxSize(),
                factory = { context ->
                    WebView(context).apply {
                        layoutParams = ViewGroup.LayoutParams(
                            ViewGroup.LayoutParams.MATCH_PARENT,
                            ViewGroup.LayoutParams.MATCH_PARENT
                        )
                        webView = this
                        WebViewManager(
                            webView = this,
                            webModel = webModel,
                            viewModel = viewModel
                        )
                    }
                }, update = {
                    webView = it
                })

How can i handle it's backpress??

@CodeWithAthari
Copy link
Author

CodeWithAthari commented Feb 17, 2024

Okie so i used BackHandler

    BackHandler(enabled = state.canGoBack) {
            webView?.goBack()
        }

Btw anyone wants full code here it is:

    @Composable
    override fun Content() {
        val viewModel = rememberScreenModel {
            WebViewModel()
        }
        val state = viewModel.state.collectAsState().value
        val navigator = LocalNavigator.currentOrThrow


        var webView: WebView? = null

        Box {
            AndroidView(
                modifier = Modifier
                    .fillMaxSize(),
                factory = { context ->
                    WebView(context).apply {
                        layoutParams = ViewGroup.LayoutParams(
                            ViewGroup.LayoutParams.MATCH_PARENT,
                            ViewGroup.LayoutParams.MATCH_PARENT
                        )
                        webView = this
                        WebViewManager(
                            webView = this,
                            webModel = webModel,
                            viewModel = viewModel
                        )
                    }
                }, update = {
                    webView = it
                })

            AnimatedVisibility(
                visible = state.isLoading,
                enter = slideInVertically() + fadeIn(),
                exit = slideOutVertically() + fadeOut()
            ) {
                Loading()
            }

        }


        BackHandler(enabled = state.canGoBack) {
            webView?.goBack()
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant