package <%= package_name %>.features.web import android.os.Bundle import android.view.View import dev.hotwire.strada.BridgeDelegate import <%= package_name %>.base.NavDestination import <%= package_name %>.util.SIGN_IN_URL import dev.hotwire.turbo.fragments.TurboWebFragment import dev.hotwire.turbo.nav.TurboNavGraphDestination import <%= package_name %>.R import <%= package_name %>.strada.bridgeComponentFactories import dev.hotwire.turbo.views.TurboWebView import dev.hotwire.turbo.visit.TurboVisitAction.REPLACE import dev.hotwire.turbo.visit.TurboVisitOptions @TurboNavGraphDestination(uri = "turbo://fragment/web") open class WebFragment : TurboWebFragment(), NavDestination { private val bridgeDelegate by lazy { BridgeDelegate( location = location, destination = this, componentFactories = bridgeComponentFactories ) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) viewLifecycleOwner.lifecycle.addObserver(bridgeDelegate) } override fun onDestroyView() { super.onDestroyView() viewLifecycleOwner.lifecycle.removeObserver(bridgeDelegate) } override fun onColdBootPageStarted(location: String) { bridgeDelegate.onColdBootPageStarted() } override fun onColdBootPageCompleted(location: String) { bridgeDelegate.onColdBootPageCompleted() } override fun onWebViewAttached(webView: TurboWebView) { bridgeDelegate.onWebViewAttached(webView) } override fun onWebViewDetached(webView: TurboWebView) { bridgeDelegate.onWebViewDetached() } override fun onVisitErrorReceived(location: String, errorCode: Int) { when (errorCode) { 401 -> navigate(SIGN_IN_URL, TurboVisitOptions(action = REPLACE)) else -> super.onVisitErrorReceived(location, errorCode) } } override fun createErrorView(statusCode: Int): View { return layoutInflater.inflate(R.layout.error_web, null) } }