Skip to content

Commit

Permalink
Fix corners scrolling issues
Browse files Browse the repository at this point in the history
  • Loading branch information
André Sousa committed Oct 31, 2018
1 parent b61190c commit 430a073
Showing 1 changed file with 51 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import android.view.*

abstract class SuperBottomSheetFragment : BottomSheetDialogFragment() {

private lateinit var sheetTouchOutsideContainer: View
private lateinit var sheetContainer: CornerRadiusFrameLayout
private lateinit var behavior: BottomSheetBehavior<*>

Expand Down Expand Up @@ -120,7 +121,7 @@ abstract class SuperBottomSheetFragment : BottomSheetDialogFragment() {
private fun iniBottomSheetUiComponents() {
// Store views references
sheetContainer = dialog.findViewById(R.id.super_bottom_sheet)
val touchOutsideView = dialog.findViewById<View>(R.id.touch_outside)
sheetTouchOutsideContainer = dialog.findViewById(R.id.touch_outside)

// Set the bottom sheet radius
sheetContainer.setBackgroundColor(getBackgroundColor())
Expand Down Expand Up @@ -165,7 +166,7 @@ abstract class SuperBottomSheetFragment : BottomSheetDialogFragment() {
sheetContainer.viewTreeObserver.removeOnPreDrawListener(this)

// If the content sheet is expanded set the background and status bar properties
if (sheetContainer.height == touchOutsideView.height) {
if (sheetContainer.height == sheetTouchOutsideContainer.height) {
setStatusBarColor(0f)

if (propertyAnimateCornerRadius) {
Expand All @@ -189,33 +190,34 @@ abstract class SuperBottomSheetFragment : BottomSheetDialogFragment() {
}

override fun onSlide(bottomSheet: View, slideOffset: Float) {
if (propertyAnimateCornerRadius) {
val radius = propertyCornerRadius - (propertyCornerRadius * slideOffset)
sheetContainer.setCornerRadius(radius)
}

if (!canSetStatusBarColor) {
return
}

if (bottomSheet.height != touchOutsideView.height) {
canSetStatusBarColor = false
return
}

if (slideOffset.isNaN() || slideOffset <= 0) {
setStatusBarColor(Color.TRANSPARENT)
return
}

val invertOffset = 1 - (1 * slideOffset)
setStatusBarColor(invertOffset)
setRoundedCornersOnScroll(bottomSheet, slideOffset)
setStatusBarColorOnScroll(bottomSheet, slideOffset)
}
})
}

//region STATUS BAR

@UiThread
private fun setStatusBarColorOnScroll(bottomSheet: View, slideOffset: Float) {
if (!canSetStatusBarColor) {
return
}

if (bottomSheet.height != sheetTouchOutsideContainer.height) {
canSetStatusBarColor = false
return
}

if (slideOffset.isNaN() || slideOffset <= 0) {
setStatusBarColor(Color.TRANSPARENT)
return
}

val invertOffset = 1 - (1 * slideOffset)
setStatusBarColor(invertOffset)
}

@UiThread
private fun setStatusBarColor(dim: Float) = setStatusBarColor(calculateColor(propertyStatusBarColor, dim))

Expand All @@ -231,6 +233,32 @@ abstract class SuperBottomSheetFragment : BottomSheetDialogFragment() {

//endregion

//region CORNERS

@UiThread
private fun setRoundedCornersOnScroll(bottomSheet: View, slideOffset: Float) {
if (!propertyAnimateCornerRadius) {
return
}

if (bottomSheet.height != sheetTouchOutsideContainer.height) {
propertyAnimateCornerRadius = false
return
}

if (slideOffset.isNaN() || slideOffset <= 0) {
sheetContainer.setCornerRadius(propertyCornerRadius)
return
}

if (propertyAnimateCornerRadius) {
val radius = propertyCornerRadius - (propertyCornerRadius * slideOffset)
sheetContainer.setCornerRadius(radius)
}
}

//endregion

//region PUBLIC

@Dimension
Expand Down

0 comments on commit 430a073

Please sign in to comment.