Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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('/')
Comment on lines +392 to +395

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First I had a simpler check, but the problem is that, webView.url contains the schema while webView.title doesnt':

webView.url = http://192.168.42.51:3000/dashboard
webView.title = 192.168.42.51:3000/dashboard

To also handle the case of www.domain.com sites, we we normalize both strings the same way before comparing them.


private fun registerFileChooserLauncher(): ActivityResultLauncher<Intent> {
return navDestination.fragment.registerForActivityResult(StartActivityForResult()) { result ->
Expand Down
Loading