Fixed navbar overlapping in settings

This commit is contained in:
Prathamesh More 2021-10-22 12:14:53 +05:30
parent d8aaa5a21b
commit 65d52776f8
2 changed files with 31 additions and 8 deletions

View file

@ -27,10 +27,8 @@ import android.widget.EditText
import androidx.annotation.LayoutRes
import androidx.core.animation.doOnEnd
import androidx.core.animation.doOnStart
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.*
import androidx.core.view.WindowInsetsCompat.Type.navigationBars
import androidx.core.view.updateLayoutParams
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.retromusic.util.PreferenceUtil
@ -138,11 +136,13 @@ fun ShapeableImageView.setCircleShape(boolean: Boolean) {
* This will draw our view above the navigation bar instead of behind it by adding margins.
*/
fun View.drawAboveNavBar() {
// Create a snapshot of the view's margin state
val initialMargin = recordInitialMarginForView(this)
ViewCompat.setOnApplyWindowInsetsListener(
(this)
) { v: View, insets: WindowInsetsCompat ->
v.updateLayoutParams<MarginLayoutParams> {
bottomMargin =
bottomMargin = initialMargin.bottom +
insets.getInsets(navigationBars()).bottom
}
insets
@ -153,11 +153,13 @@ fun View.drawAboveNavBar() {
* This will draw our view above the navigation bar instead of behind it by adding padding.
*/
fun View.drawAboveNavBarWithPadding() {
val initialPadding = recordInitialPaddingForView(this)
ViewCompat.setOnApplyWindowInsetsListener(
(this)
) { v: View, insets: WindowInsetsCompat ->
val navBarHeight = insets.getInsets(navigationBars()).bottom
v.updatePadding(bottom = navBarHeight)
v.updatePadding(bottom = initialPadding.bottom + navBarHeight)
insets
}
requestApplyInsetsWhenAttached()
@ -179,4 +181,19 @@ fun View.requestApplyInsetsWhenAttached() {
override fun onViewDetachedFromWindow(v: View) = Unit
})
}
}
}
data class InitialMargin(val left: Int, val top: Int,
val right: Int, val bottom: Int)
private fun recordInitialMarginForView(view: View) = InitialMargin(
view.marginLeft, view.marginTop, view.marginRight, view.marginBottom)
data class InitialPadding(val left: Int, val top: Int,
val right: Int, val bottom: Int)
private fun recordInitialPaddingForView(view: View) = InitialMargin(
view.paddingLeft, view.paddingTop, view.paddingRight, view.paddingBottom)