Expose the gesture-bar height to the page as a bridge
Browse files at this commit003c399ecf9102899727c07b4974ddd79369849fParent: 7dba8672 changed files +19 -1
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 @@ | ||
| 1 | 1 | package co.hezarfen.app |
| 2 | 2 | |
| 3 | 3 | import android.os.Bundle |
| 4 | +import android.webkit.JavascriptInterface | |
| 4 | 5 | import android.webkit.WebView |
| 5 | 6 | import androidx.activity.enableEdgeToEdge |
| 6 | 7 | import androidx.core.view.ViewCompat |
| @@ -9,6 +10,22 @@ import androidx.core.view.WindowInsetsCompat | ||
| 9 | 10 | class MainActivity : TauriActivity() { |
| 10 | 11 | private var webView: WebView? = null |
| 11 | 12 | |
| 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 | + | |
| 12 | 29 | override fun onCreate(savedInstanceState: Bundle?) { |
| 13 | 30 | enableEdgeToEdge() |
| 14 | 31 | super.onCreate(savedInstanceState) |
| @@ -29,6 +46,7 @@ class MainActivity : TauriActivity() { | ||
| 29 | 46 | // webview applies the insets itself. |
| 30 | 47 | override fun onWebViewCreate(webView: WebView) { |
| 31 | 48 | this.webView = webView |
| 49 | + webView.addJavascriptInterface(ShellBridge(), "HezarfenShell") | |
| 32 | 50 | |
| 33 | 51 | // The page hides scrollbars in CSS, but those rules cannot reach the ones |
| 34 | 52 | // Android draws over the webview itself, which is what still flashes down |