Fixed insets not being implicitly asked for by the framework resulting in no coverage for other than main fragments

This commit is contained in:
Viktor De Pasquale 2019-10-18 16:39:08 +02:00
parent 28fcbbcf7b
commit 96ef9cdbee

View File

@ -1,6 +1,7 @@
package com.topjohnwu.magisk.redesign.compat package com.topjohnwu.magisk.redesign.compat
import android.graphics.Insets import android.graphics.Insets
import android.view.View
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
@ -11,6 +12,7 @@ import com.topjohnwu.magisk.model.events.FragmentExecutor
import com.topjohnwu.magisk.model.events.ViewEvent import com.topjohnwu.magisk.model.events.ViewEvent
import timber.log.Timber import timber.log.Timber
class CompatDelegate internal constructor( class CompatDelegate internal constructor(
private val view: CompatView<*> private val view: CompatView<*>
) { ) {
@ -43,8 +45,18 @@ class CompatDelegate internal constructor(
insets.asInsets() insets.asInsets()
.also { view.peekSystemWindowInsets(it) } .also { view.peekSystemWindowInsets(it) }
.let { view.consumeSystemWindowInsets(it) } .let { view.consumeSystemWindowInsets(it) }
.also { if (it != Insets.NONE) view.viewModel.insets.value = it } ?.also { view.viewModel.insets.value = it }
.subtractBy(insets) ?.subtractBy(insets) ?: insets
}
if (ViewCompat.isAttachedToWindow(view.viewRoot)) {
ViewCompat.requestApplyInsets(view.viewRoot)
} else {
view.viewRoot.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
override fun onViewDetachedFromWindow(v: View) = Unit
override fun onViewAttachedToWindow(v: View) {
ViewCompat.requestApplyInsets(v)
}
})
} }
} }