I have a custom class with a web view inside.

class CustomClassWebView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr),
    JavaScriptInterfaceCallback {



    @SuppressLint("SetJavaScriptEnabled")
    fun startWebView(
        params: RemoteComponentParams,
        callback: RemoteComponentCallback? = null
    ) {
        remoteComponentParams = params
        remoteComponentCallback = callback

        WebView.setWebContentsDebuggingEnabled(true)

        var userAgent = getWebViewUserAgent()

        binding.webView.settings.apply {
            javaScriptEnabled = true
            cacheMode = WebSettings.LOAD_NO_CACHE
          
                userAgent = getWebViewUserAgent()
                userAgentString = userAgent
           
        }

        val webClient = RemoteWebViewClient(userAgent).apply {
            webViewClientCallback = object : RemoteWebViewClientCallback {
                override fun onLoadFinished() {
                   
                }

                override fun sendJSONEvent() {
                 
                }

                override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest) {
                   
                }

                override fun onExternalUriIntercepted(uri: Uri) {
                    remoteComponentCallback?.openExternalUri(uri)
                }
            }
        }
          
            addJavascriptInterface(JavaScriptInterface(this@CustomClassWebView), ANDROID)
            visibility = INVISIBLE

            params.url?.let {
                setProgressBarVisibility(View.VISIBLE)
                loadUrl(it)
            }
        
    }

And this is the XML

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent" />

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Once I have this component loaded in a fragment, I want to send it to another activity without having to reload it. Is it possible?

I have tried the Android Activity transition, but isn't working. https://guides.codepath.com/android/shared-element-activity-transition

0

There are 0 best solutions below