Skip to content

Commit 3739989

Browse files
committed
[minibrowser] Apply system bar insets to main view
Add an insets listener to apply the system bar insets to the browser main view, ensuring that the main view will not cover the bars. While at it, opt-in to edge-to-edge mode explicitly to ensure the same behaviour also on older Android releases. In Android 15 applications targeting SDK 35 are opted in to edge-to-edge mode, which makes applications cover as much of the screen as possible but may result in undesired overlaps if unhandled. For now the handling is as simple as possible to get the existing behaviour back. Fixes #189
1 parent 37c58e4 commit 3739989

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ kotlin = "2.1.0"
1313
vanniktech = "0.30.0"
1414
androidx-navigation-safeargs = "2.8.5"
1515

16+
androidx-activity = "1.10.1"
1617
androidx-annotation = "1.9.1"
1718
androidx-test-runner = "1.6.2"
1819
androidx-test-rules = "1.6.1"
@@ -36,6 +37,7 @@ vanniktech-maven-publish = { id = "com.vanniktech.maven.publish", version.ref =
3637
androidx-navigation-safeargs = { id = "androidx.navigation.safeargs", version.ref = "androidx-navigation-safeargs" }
3738

3839
[libraries]
40+
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "androidx-activity" }
3941
androidx-annotation = { group = "androidx.annotation", name = "annotation", version.ref = "androidx-annotation" }
4042
androidx-test-runner = { group = "androidx.test", name = "runner", version.ref = "androidx-test-runner" }
4143
androidx-test-rules = { group = "androidx.test", name = "rules", version.ref = "androidx-test-rules" }

tools/minibrowser/src/main/java/org/wpewebkit/tools/minibrowser/BrowserFragment.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import android.view.*
2727
import android.view.inputmethod.EditorInfo
2828
import android.view.inputmethod.InputMethodManager
2929
import android.widget.FrameLayout
30+
import androidx.core.view.ViewCompat
31+
import androidx.core.view.WindowInsetsCompat
32+
import androidx.core.view.updatePadding
3033
import androidx.fragment.app.Fragment
3134
import androidx.fragment.app.activityViewModels
3235
import androidx.navigation.fragment.findNavController
@@ -97,6 +100,12 @@ class BrowserFragment : Fragment(R.layout.fragment_browser) {
97100
Log.i(TAG, "onViewCreated")
98101
super.onViewCreated(view, savedInstanceState)
99102

103+
ViewCompat.setOnApplyWindowInsetsListener(binding.main) { v, insets ->
104+
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
105+
v.updatePadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
106+
WindowInsetsCompat.CONSUMED
107+
}
108+
100109
val currentState = browserViewModel.browserState.value
101110
currentState.selectedTabId?.let { selectedTabId ->
102111
val tab = browserViewModel.findTab(selectedTabId)

tools/minibrowser/src/main/java/org/wpewebkit/tools/minibrowser/MainActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ package org.wpewebkit.tools.minibrowser
2626
import android.content.res.Configuration
2727
import android.os.Bundle
2828
import android.util.Log
29+
import androidx.activity.enableEdgeToEdge
2930
import androidx.appcompat.app.AppCompatActivity
3031
import androidx.navigation.fragment.NavHostFragment
3132
import org.wpewebkit.tools.minibrowser.databinding.ActivityMainBinding
@@ -44,6 +45,7 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
4445
override fun onCreate(savedInstanceState: Bundle?) {
4546
super.onCreate(savedInstanceState)
4647
Log.d(TAG, "onCreate")
48+
enableEdgeToEdge();
4749
binding = ActivityMainBinding.inflate(layoutInflater)
4850
}
4951

0 commit comments

Comments
 (0)