From ebdf5c4478283d0f117245a64b0df3399fa55fdb Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Wed, 30 Nov 2016 01:35:04 +0000 Subject: [PATCH] am cf5c5110: am 93219e8b: Merge "Ensure that CoL\'s sorted children is invalidated" into mnc-ub-dev * commit 'cf5c511054fec2ae00f1b7803bbfb9d023bdee90': Ensure that CoL's sorted children is invalidated GitOrigin-RevId=447767d261382dce84853b67a02c5e13e3d0eda2 PiperOrigin-RevId: 140550402 --- .../design/widget/CoordinatorLayout.java | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/src/android/support/design/widget/CoordinatorLayout.java b/src/android/support/design/widget/CoordinatorLayout.java index a5d6a9685..165a07681 100644 --- a/src/android/support/design/widget/CoordinatorLayout.java +++ b/src/android/support/design/widget/CoordinatorLayout.java @@ -550,28 +550,18 @@ public class CoordinatorLayout extends ViewGroup implements NestedScrollingParen } private void prepareChildren() { - final int childCount = getChildCount(); - - boolean resortRequired = mDependencySortedChildren.size() != childCount; - - for (int i = 0; i < childCount; i++) { + mDependencySortedChildren.clear(); + for (int i = 0, count = getChildCount(); i < count; i++) { final View child = getChildAt(i); - final LayoutParams lp = getResolvedLayoutParams(child); - if (!resortRequired && lp.isDirty(this, child)) { - resortRequired = true; - } - lp.findAnchorView(this, child); - } - if (resortRequired) { - mDependencySortedChildren.clear(); - for (int i = 0; i < childCount; i++) { - mDependencySortedChildren.add(getChildAt(i)); - } - // We need to use a selection sort here to make sure that every item is compared - // against each other - selectionSort(mDependencySortedChildren, mLayoutDependencyComparator); + final LayoutParams lp = getResolvedLayoutParams(child); + lp.findAnchorView(this, child); + + mDependencySortedChildren.add(child); } + // We need to use a selection sort here to make sure that every item is compared + // against each other + selectionSort(mDependencySortedChildren, mLayoutDependencyComparator); } /** @@ -1149,15 +1139,23 @@ public class CoordinatorLayout extends ViewGroup implements NestedScrollingParen } } - void dispatchDependentViewRemoved(View removedChild) { - final int childCount = getChildCount(); + void dispatchDependentViewRemoved(View view) { + final int childCount = mDependencySortedChildren.size(); + boolean viewSeen = false; for (int i = 0; i < childCount; i++) { - final View child = getChildAt(i); - final LayoutParams lp = (LayoutParams) child.getLayoutParams(); - final Behavior b = lp.getBehavior(); - - if (b != null && b.layoutDependsOn(this, child, removedChild)) { - b.onDependentViewRemoved(this, child, removedChild); + final View child = mDependencySortedChildren.get(i); + if (child == view) { + // We've seen our view, which means that any Views after this could be dependent + viewSeen = true; + continue; + } + if (viewSeen) { + CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) + child.getLayoutParams(); + CoordinatorLayout.Behavior b = lp.getBehavior(); + if (b != null && lp.dependsOn(this, child, view)) { + b.onDependentViewRemoved(this, child, view); + } } } }