Skip to content

Commit

Permalink
fix: list items do not get reset when InboxRecyclerView's size is cha…
Browse files Browse the repository at this point in the history
…nged
  • Loading branch information
saket committed Sep 12, 2019
1 parent c211831 commit 7654e48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ internal class PageLocationChangeDetector(
private val changeListener: () -> Unit
) : ViewTreeObserver.OnPreDrawListener, ViewTreeObserver.OnGlobalLayoutListener {

private var lastTranslationX = 0F
private var lastTranslationY = 0F
private var lastWidth = 0
private var lastHeight = 0
private var lastClippedDimens = Rect()
private var lastState = page.currentState

Expand All @@ -24,15 +27,20 @@ internal class PageLocationChangeDetector(
}

private fun dispatchCallbackIfNeeded() {
val moved = lastTranslationY != page.translationY
val dimensionsChanged = lastClippedDimens != page.clippedDimens
val moved = lastTranslationX != page.translationX || lastTranslationY != page.translationY
val stateChanged = lastState != page.currentState
val dimensionsChanged = lastWidth != page.width
|| lastHeight != page.height
|| lastClippedDimens != page.clippedDimens

if (moved || dimensionsChanged || stateChanged) {
changeListener()
}

lastTranslationX = page.translationX
lastTranslationY = page.translationY
lastWidth = page.width
lastHeight = page.height
lastClippedDimens = page.clippedDimens
lastState = page.currentState
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ abstract class BaseExpandablePageLayout @JvmOverloads constructor(
) : RelativeLayout(context, attrs) {

/** The visible portion of this layout. */
// TODO: This creates a new Rect internally everytime. Optimize this.
val clippedDimens: Rect
get() = clipBounds

Expand Down

0 comments on commit 7654e48

Please sign in to comment.