forge
Explore
Log in

Don't you dare go Hollow

Expose the gesture-bar height to the page as a bridge

Browse files at this commit

003c399ecf9102899727c07b4974ddd79369849fBurak BoduroğluParent: 7dba867
Pushing the value in with evaluateJavascript only reached the document that
happened to be loaded: after a reload the property was gone and the tab bar
went back under the gesture pill. A JavascriptInterface is bound to the
webview instead, so any document can read it before its first paint.
frontendmodified+1 -1
@@ -1 +1 @@
1-Subproject commit 4448c0633bc8af87f783f58976e79eae15f6fe2c
1+Subproject commit a6408c3f840031b794525bef3a525ad5fe8daab5
src-tauri/gen/android/app/src/main/java/co/hezarfen/app/MainActivity.ktmodified+18 -0
@@ -1,6 +1,7 @@
11 package co.hezarfen.app
22
33 import android.os.Bundle
4+import android.webkit.JavascriptInterface
45 import android.webkit.WebView
56 import androidx.activity.enableEdgeToEdge
67 import androidx.core.view.ViewCompat
@@ -9,6 +10,22 @@ import androidx.core.view.WindowInsetsCompat
910 class MainActivity : TauriActivity() {
1011 private var webView: WebView? = null
1112
13+ /**
14+ * What the page can ask the shell about the device it is running on. Bound to
15+ * the webview, so it survives navigations and reloads — unlike a value pushed
16+ * into a document, which dies with that document.
17+ */
18+ inner class ShellBridge {
19+ /** Height of the gesture bar in CSS pixels; 0 when there is none. */
20+ @JavascriptInterface
21+ fun bottomInsetPx(): Float {
22+ val view = webView ?: return 0f
23+ val insets = ViewCompat.getRootWindowInsets(view) ?: return 0f
24+ return insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom /
25+ view.resources.displayMetrics.density
26+ }
27+ }
28+
1229 override fun onCreate(savedInstanceState: Bundle?) {
1330 enableEdgeToEdge()
1431 super.onCreate(savedInstanceState)
@@ -29,6 +46,7 @@ class MainActivity : TauriActivity() {
2946 // webview applies the insets itself.
3047 override fun onWebViewCreate(webView: WebView) {
3148 this.webView = webView
49+ webView.addJavascriptInterface(ShellBridge(), "HezarfenShell")
3250
3351 // The page hides scrollbars in CSS, but those rules cannot reach the ones
3452 // Android draws over the webview itself, which is what still flashes down