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(android): fix infinite loop by calling setDecorFitsSystemWindows more strictly #36

Merged
merged 4 commits into from
Oct 25, 2024
Merged
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
Expand Up @@ -12,6 +12,7 @@ import androidx.core.view.WindowInsetsCompat
class SafeArea(private val activity: Activity, private val webView: WebView) {
var offset = 0
private var appearanceUpdatedInListener = false
private var decorFitsSystemWindowsNegated = false

fun enable(updateInsets: Boolean, appearanceConfig: AppearanceConfig) {
activity.window.decorView.getRootView().setOnApplyWindowInsetsListener { view, insets ->
Expand All @@ -28,6 +29,7 @@ class SafeArea(private val activity: Activity, private val webView: WebView) {
view.onApplyWindowInsets(insets)
}

resetDecorFitsSystemWindows()
updateAppearance(appearanceConfig)

if (updateInsets) {
Expand All @@ -45,6 +47,10 @@ class SafeArea(private val activity: Activity, private val webView: WebView) {
updateAppearance(appearanceConfig)
}

fun resetDecorFitsSystemWindows() {
decorFitsSystemWindowsNegated = false
}

private fun updateAppearance(appearanceConfig: AppearanceConfig) {
activity.runOnUiThread {
val windowInsetsControllerCompat =
Expand All @@ -68,7 +74,10 @@ class SafeArea(private val activity: Activity, private val webView: WebView) {

private fun updateInsets() {
activity.runOnUiThread {
WindowCompat.setDecorFitsSystemWindows(activity.window, false)
if (!decorFitsSystemWindowsNegated) {
decorFitsSystemWindowsNegated = true
WindowCompat.setDecorFitsSystemWindows(activity.window, false)
}

val windowInsets = ViewCompat.getRootWindowInsets(activity.window.decorView)
val systemBarsInsets =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class SafeAreaPlugin : Plugin() {
}
}

override fun handleOnPause() {
implementation?.resetDecorFitsSystemWindows()
super.handleOnPause()
}

@PluginMethod(returnType = PluginMethod.RETURN_NONE)
fun enable(call: PluginCall) {
val jsonObject = call.getObject("config")
Expand Down