From e47f80fe316f2a7458602e1eb3af18c6f76c2f73 Mon Sep 17 00:00:00 2001 From: Jay Ohms Date: Thu, 31 Mar 2022 19:42:22 -0400 Subject: [PATCH] Add a visitRendered() callback that web fragments can use. --- .../hotwire/turbo/delegates/TurboWebFragmentDelegate.kt | 1 + .../hotwire/turbo/fragments/TurboWebFragmentCallback.kt | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/turbo/src/main/kotlin/dev/hotwire/turbo/delegates/TurboWebFragmentDelegate.kt b/turbo/src/main/kotlin/dev/hotwire/turbo/delegates/TurboWebFragmentDelegate.kt index 9483558e..a62f14d0 100644 --- a/turbo/src/main/kotlin/dev/hotwire/turbo/delegates/TurboWebFragmentDelegate.kt +++ b/turbo/src/main/kotlin/dev/hotwire/turbo/delegates/TurboWebFragmentDelegate.kt @@ -191,6 +191,7 @@ internal class TurboWebFragmentDelegate( } override fun visitRendered() { + callback.onVisitRendered(location) navDestination.fragmentViewModel.setTitle(title()) removeTransitionalViews() } diff --git a/turbo/src/main/kotlin/dev/hotwire/turbo/fragments/TurboWebFragmentCallback.kt b/turbo/src/main/kotlin/dev/hotwire/turbo/fragments/TurboWebFragmentCallback.kt index 7ac6d92a..ecb93ccd 100644 --- a/turbo/src/main/kotlin/dev/hotwire/turbo/fragments/TurboWebFragmentCallback.kt +++ b/turbo/src/main/kotlin/dev/hotwire/turbo/fragments/TurboWebFragmentCallback.kt @@ -56,6 +56,13 @@ interface TurboWebFragmentCallback { */ fun onVisitStarted(location: String) {} + /** + * Called when a Turbo visit has rendered (from a cached snapshot or + * from a fresh network request). This may be called multiple times + * during a normal visit lifecycle. + */ + fun onVisitRendered(location: String) {} + /** * Called when a Turbo visit has completed. */