mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-09 08:04:45 +00:00
fix(napplets): remove the stray white band at the bottom of the applet WebView
Two edge-to-edge issues on the napplet/nsite host, both surfacing as a white strip below the applet on a light page: - Double bottom inset. The root inset listener turned the system-bar/cutout insets into padding but returned them un-consumed, so the child WebView (which on targetSdk 35+ auto-applies any insets it receives to its web content) padded the bottom a SECOND time. Zero those types before they reach the WebView, keeping IME flowing so keyboard resize still works. - Over-scroll reveal. Forcing a scroll past the content edge stretched the view and exposed the shell document's background behind the applet iframe. WebView.overScrollMode only governs the outer frame, so also inject `overscroll-behavior: none` into the applet document (alongside the shim) to kill the stretch at the source, theme-independently. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
c7d876096f
commit
d0d1577bfe
+7
-1
@@ -169,9 +169,15 @@ class NappletContentServer(
|
||||
/** Inserts the `window.napplet` client shim into the applet's HTML document. */
|
||||
private fun injectShim(html: ByteArray): ByteArray {
|
||||
val text = html.decodeToString()
|
||||
// Disable the document's overscroll affordance (the bounce/stretch): the Android-level
|
||||
// WebView.overScrollMode only governs the outer frame, so an applet whose own root background is
|
||||
// transparent stretched on over-scroll and exposed the shell's background behind it (a stray
|
||||
// white band at the bottom). `overscroll-behavior: none` removes the stretch at the source,
|
||||
// theme-independently. Allowed by the app CSP's `style-src 'unsafe-inline'`.
|
||||
val style = "<style>html,body{overscroll-behavior:none !important}</style>"
|
||||
// In website mode, set the NIP-07 flag synchronously *before* the shim so window.nostr installs.
|
||||
val nip07Flag = if (websiteMode) "<script>window.__nappletNip07=true;</script>" else ""
|
||||
val script = "$nip07Flag<script>$shimJs</script>"
|
||||
val script = "$style$nip07Flag<script>$shimJs</script>"
|
||||
val headIdx = text.indexOf("<head", ignoreCase = true)
|
||||
val injected =
|
||||
when {
|
||||
|
||||
+13
-2
@@ -51,6 +51,7 @@ import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.Insets
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.webkit.JavaScriptReplyProxy
|
||||
@@ -229,9 +230,15 @@ class NappletHostActivity : ComponentActivity() {
|
||||
// Activities are edge-to-edge by default on recent Android; pad by the system bar and
|
||||
// display-cutout insets so neither the chrome nor the applet draws under the system bars.
|
||||
ViewCompat.setOnApplyWindowInsetsListener(root) { view, insets ->
|
||||
val bars = insets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
|
||||
val applied = WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
|
||||
val bars = insets.getInsets(applied)
|
||||
view.setPadding(bars.left, bars.top, bars.right, bars.bottom)
|
||||
insets
|
||||
// Zero the insets we just turned into padding before they reach the child WebView: on
|
||||
// targetSdk 35+ the WebView auto-applies any insets it receives to its own web content, so
|
||||
// leaving them un-consumed padded the bottom a SECOND time — a band of the page's own
|
||||
// background above the navigation bar. Keep the other types (notably IME) flowing so the
|
||||
// applet's keyboard-aware resize still works.
|
||||
WindowInsetsCompat.Builder(insets).setInsets(applied, Insets.NONE).build()
|
||||
}
|
||||
|
||||
probeAndMount()
|
||||
@@ -375,6 +382,10 @@ class NappletHostActivity : ComponentActivity() {
|
||||
safeBrowsingEnabled = true
|
||||
}
|
||||
}
|
||||
// Disable the overscroll stretch/glow: forcing a scroll past the content edge stretched the
|
||||
// WebView's output and exposed the shell document's background behind the applet iframe at the
|
||||
// seam (a stray white band at the bottom). The applet's own content still scrolls normally.
|
||||
webView.overScrollMode = View.OVER_SCROLL_NEVER
|
||||
WebView.setWebContentsDebuggingEnabled(false)
|
||||
webView.webViewClient = NappletWebViewClient()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user