From a2b4124cc5ffd316cd3d9d17f89cb32e2bbce9ca Mon Sep 17 00:00:00 2001 From: Leon Date: Fri, 10 Jul 2026 13:15:25 +0200 Subject: [PATCH] Hide native title when HTML is not present or blank --- .../fragments/HotwireWebFragmentDelegate.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragmentDelegate.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragmentDelegate.kt index ba9a9a8..72435b9 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragmentDelegate.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragmentDelegate.kt @@ -380,8 +380,19 @@ internal class HotwireWebFragmentDelegate( } private fun title(): String { - return webView.title ?: "" - } + val title = webView.title.orEmpty() + val url = webView.url.orEmpty() + return if (title.isEmpty() || title.asDisplayUrl() == url.asDisplayUrl()) "" else title + } + + // Android's WebView uses the URL when a page has no <title>: + // Normalize the URL and compare it to the title. If they are the same, + // return an empty string to avoid showing the URL as the title. + private fun String.asDisplayUrl(): String = + substringAfter("://") + .removePrefix("www.") + .replace("%20", " ") + .trimEnd('/') private fun registerFileChooserLauncher(): ActivityResultLauncher<Intent> { return navDestination.fragment.registerForActivityResult(StartActivityForResult()) { result ->