Skip to content

Commit

Permalink
fixes #32
Browse files Browse the repository at this point in the history
  • Loading branch information
Zackratos committed Aug 16, 2021
1 parent f0c927a commit 43fc39b
Showing 1 changed file with 63 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.RelativeLayout
import androidx.annotation.RequiresApi
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.LifecycleOwner
Expand Down Expand Up @@ -263,14 +264,37 @@ private fun View.updateBackground(background: BarBackground): Boolean {
internal fun View.addStatusBarTopPadding() {
setPadding(paddingLeft, paddingTop + statusBarHeight, paddingRight, paddingBottom)
val lp = layoutParams
if (lp.height != ViewGroup.LayoutParams.MATCH_PARENT && lp.height != ViewGroup.LayoutParams.WRAP_CONTENT) {
lp.height += statusBarHeight
layoutParams = lp
return
}
post {
lp.height = height + statusBarHeight
layoutParams = lp
when (this) {
is Toolbar -> {
when (lp.height) {
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.MATCH_PARENT -> {
post {
lp.height = height + statusBarHeight
layoutParams = lp
}
}
else -> {
lp.height += statusBarHeight
layoutParams = lp
}
}
}
else -> {
when (lp.height) {
ViewGroup.LayoutParams.WRAP_CONTENT -> return
ViewGroup.LayoutParams.MATCH_PARENT -> {
post {
lp.height = height + statusBarHeight
layoutParams = lp
}
}
else -> {
lp.height += statusBarHeight
layoutParams = lp
}
}
}
}
}

Expand All @@ -286,13 +310,36 @@ internal fun View.addNavigationBarBottomPadding() {
}
setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom + navigationBarHeight)
val lp = layoutParams
if (lp.height != ViewGroup.LayoutParams.MATCH_PARENT && lp.height != ViewGroup.LayoutParams.WRAP_CONTENT) {
lp.height += navigationBarHeight
layoutParams = lp
return
}
post {
lp.height = height + navigationBarHeight
layoutParams = lp
when (this) {
is Toolbar -> {
when (lp.height) {
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.MATCH_PARENT -> {
post {
lp.height = height + navigationBarHeight
layoutParams = lp
}
}
else -> {
lp.height += navigationBarHeight
layoutParams = lp
}
}
}
else -> {
when (lp.height) {
ViewGroup.LayoutParams.WRAP_CONTENT -> return
ViewGroup.LayoutParams.MATCH_PARENT -> {
post {
lp.height = height + navigationBarHeight
layoutParams = lp
}
}
else -> {
lp.height += navigationBarHeight
layoutParams = lp
}
}
}
}
}

0 comments on commit 43fc39b

Please sign in to comment.