Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pwa): inset android webview so it avoids cutouts #333

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
@@ -1,21 +1,30 @@
package org.getoutline.pwa

import android.content.res.Resources
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.coordinatorlayout.widget.CoordinatorLayout
import android.view.WindowInsets
import com.getcapacitor.BridgeActivity
import kotlin.math.max

import mobileproxy.*

import androidx.webkit.ProxyConfig
import androidx.webkit.ProxyController
import androidx.webkit.WebViewFeature

// TODO: resize webview so the web content is not occluded by the device UI
class MainActivity : BridgeActivity() {
private var proxy: Proxy? = null;

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Log.d("DIMENSIONS", this.bridge.webView.layoutParams.width.toString())
Log.d("DIMENSIONS", this.bridge.webView.layoutParams.height.toString())

if (WebViewFeature.isFeatureSupported(WebViewFeature.PROXY_OVERRIDE)) {
this.proxy = Mobileproxy.runProxy(
"127.0.0.1:0",
Expand Down Expand Up @@ -44,6 +53,34 @@ class MainActivity : BridgeActivity() {
}
}

override fun onAttachedToWindow() {
super.onAttachedToWindow()

val rootView = this.window.decorView.rootView
rootView.setBackgroundColor(Color.parseColor("#000000"))

this.bridge.webView.overScrollMode = View.OVER_SCROLL_NEVER

val rootWindowInsets = rootView.rootWindowInsets
if (rootWindowInsets != null) {
val systemBarInsets = rootWindowInsets.getInsets(WindowInsets.Type.systemBars())
val cutoutInsets = rootWindowInsets.getInsets(WindowInsets.Type.displayCutout())

val top = max(systemBarInsets.top, cutoutInsets.top)
val left = max(systemBarInsets.left, cutoutInsets.left)
val bottom = max(systemBarInsets.bottom, cutoutInsets.bottom)
val right = max(systemBarInsets.right, cutoutInsets.right)

this.bridge.webView.x = left.toFloat()
this.bridge.webView.y = top.toFloat()

this.bridge.webView.layoutParams = CoordinatorLayout.LayoutParams(
Resources.getSystem().displayMetrics.widthPixels - right - left,
Resources.getSystem().displayMetrics.heightPixels - bottom - top
)
}
}

override fun onDestroy() {
this.proxy?.stop(3000)
this.proxy = null
Expand Down
2 changes: 1 addition & 1 deletion x/examples/outline-pwa/android/variables.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ext {
minSdkVersion = 26
minSdkVersion = 30
compileSdkVersion = 35
targetSdkVersion = 35
androidxActivityVersion = '1.8.0'
Expand Down
Loading