Skip to content

Commit

Permalink
offset helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
cgspine committed May 16, 2020
1 parent d356f06 commit 56881a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,7 @@ boolean match(@Nullable Map<String, String> scheme) {
return true;
}

public abstract boolean handle(@NonNull Activity activity, @Nullable Map<String, SchemeValue> scheme);
public abstract boolean handle(@NonNull QMUISchemeHandler handler,
@NonNull Activity activity,
@Nullable Map<String, SchemeValue> scheme);
}
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,15 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
}
}

for (int i = 0, z = getChildCount(); i < z; i++) {
getViewOffsetHelper(getChildAt(i)).onViewLayout(false);
}

// Update the collapsed bounds by getting it's transformed bounds
if (mCollapsingTitleEnabled) {
// Update the collapsed bounds
final int maxOffset = getMaxOffsetForPinChild(
mTopBarDirectChild != null ? mTopBarDirectChild : mTopBar, true);
mTopBarDirectChild != null ? mTopBarDirectChild : mTopBar);
QMUIViewHelper.getDescendantRect(this, mTopBar, mTmpRect);
// mTmpRect.top = mTmpRect.top - topBarInsetAdjustTop;
Rect rect = mTopBar.getTitleContainerRect();
Expand All @@ -446,11 +450,6 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
mCollapsingTextHelper.recalculate();
}

// Update our child view offset helpers. This needs to be done after the title has been
// setup, so that any Toolbars are in their original position
for (int i = 0, z = getChildCount(); i < z; i++) {
getViewOffsetHelper(getChildAt(i)).onViewLayout();
}

// Finally, set our minimum height to enable proper AppBarLayout collapsing
if (mTopBar != null) {
Expand All @@ -466,6 +465,10 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
}

updateScrimVisibility();

for (int i = 0, z = getChildCount(); i < z; i++) {
getViewOffsetHelper(getChildAt(i)).applyOffsets();
}
}

private static int getHeightWithMargins(@NonNull final View view) {
Expand Down Expand Up @@ -1280,25 +1283,11 @@ final void updateScrimVisibility() {
}
}

/**
* if in onLayout, the child.getTop is precise, but QMUIViewOffsetHelper.onViewLayout may not called,
* so offsetHelper.getLayoutTop() maybe wrong
*
* @param child
* @param onLayout
* @return
*/
final int getMaxOffsetForPinChild(View child, boolean onLayout) {
int layoutTop = child.getTop();
if (!onLayout) {
final QMUIViewOffsetHelper offsetHelper = getViewOffsetHelper(child);
layoutTop = offsetHelper.getLayoutTop();
}

final int getMaxOffsetForPinChild(View child) {
final QMUIViewOffsetHelper offsetHelper = getViewOffsetHelper(child);
final QMUICollapsingTopBarLayout.LayoutParams lp = (QMUICollapsingTopBarLayout.LayoutParams) child.getLayoutParams();
return getHeight()
- layoutTop
- child.getHeight()
- lp.bottomMargin;
return getHeight() - offsetHelper.getLayoutTop() - child.getHeight() - lp.bottomMargin;
}

public void addOnOffsetUpdateListener(@NonNull OnOffsetUpdateListener listener) {
Expand Down Expand Up @@ -1327,7 +1316,7 @@ public void onOffsetChanged(AppBarLayout layout, int verticalOffset) {
switch (lp.mCollapseMode) {
case QMUICollapsingTopBarLayout.LayoutParams.COLLAPSE_MODE_PIN:
offsetHelper.setTopAndBottomOffset(
QMUILangHelper.constrain(-verticalOffset, 0, getMaxOffsetForPinChild(child, false)));
QMUILangHelper.constrain(-verticalOffset, 0, getMaxOffsetForPinChild(child)));
break;
case QMUICollapsingTopBarLayout.LayoutParams.COLLAPSE_MODE_PARALLAX:
offsetHelper.setTopAndBottomOffset(
Expand Down

0 comments on commit 56881a8

Please sign in to comment.