Skip to content

Commit

Permalink
- fix elevation shadow with sticky header
Browse files Browse the repository at this point in the history
  - FIX #2689
- ensure to not apply unnecessary padding on top if a sticky header or sticky footer is used
- showcase sticky header in sample
  • Loading branch information
mikepenz committed Dec 18, 2020
1 parent 4c05067 commit 2afa22e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class MultiDrawerActivity : AppCompatActivity() {
}

binding.sliderEnd.apply {
stickyHeaderView = layoutInflater.inflate(R.layout.header, null)
itemAdapter.add(
PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home).withIdentifier(1),
PrimaryDrawerItem().withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ internal fun handleHeaderView(sliderView: MaterialDrawerSliderView) {
view.layoutParams = lps
}
}

if (Build.VERSION.SDK_INT >= 21) {
sliderView.elevation = 0f
}
//remove the padding of the recyclerView again we have the header on top of it
sliderView.recyclerView.setPadding(0, 0, 0, 0)
}
Expand All @@ -147,18 +149,18 @@ internal fun rebuildStickyFooterView(sliderView: MaterialDrawerSliderView) {
}

//fill the footer with items
fillStickyDrawerItemFooter(sliderView, it, View.OnClickListener { v ->
fillStickyDrawerItemFooter(sliderView, it) { v ->
val drawerItem = v.getTag(R.id.material_drawer_item) as IDrawerItem<*>
onFooterDrawerItemClick(sliderView, drawerItem, v, true)
})
}

it.visibility = View.VISIBLE
} ?: run {
//there was no footer yet. now just create one
handleFooterView(sliderView, View.OnClickListener { v ->
handleFooterView(sliderView) { v ->
val drawerItem = v.getTag(R.id.material_drawer_item) as IDrawerItem<*>
onFooterDrawerItemClick(sliderView, drawerItem, v, true)
})
}
}

sliderView.setStickyFooterSelection(sliderView.currentStickyFooterSelection, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ open class MaterialDrawerSliderView @JvmOverloads constructor(context: Context,
// set the footer (do this before the setAdapter because some devices will crash else
if (value != null) {
if (footerDivider) {
footerAdapter.add(ContainerDrawerItem().withView(value).withViewPosition(ContainerDrawerItem.Position.BOTTOM))
footerAdapter.add(ContainerDrawerItem().apply { view = value; viewPosition = ContainerDrawerItem.Position.BOTTOM })
} else {
footerAdapter.add(ContainerDrawerItem().withView(value).withViewPosition(ContainerDrawerItem.Position.NONE))
footerAdapter.add(ContainerDrawerItem().apply { view = value; viewPosition = ContainerDrawerItem.Position.NONE })
}
}
}
Expand Down Expand Up @@ -411,7 +411,12 @@ open class MaterialDrawerSliderView @JvmOverloads constructor(context: Context,
this.insets?.set(insets.systemWindowInsetLeft, insets.systemWindowInsetTop, insets.systemWindowInsetRight, insets.systemWindowInsetBottom)

if (headerView == null && accountHeader == null) {
recyclerView.updatePadding(top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom)
if (stickyHeaderView == null) {
recyclerView.updatePadding(top = insets.systemWindowInsetTop)
}
if (stickyFooterView == null) {
recyclerView.updatePadding(bottom = insets.systemWindowInsetBottom)
}
}

setWillNotDraw(insetForeground == null)
Expand Down

0 comments on commit 2afa22e

Please sign in to comment.