Navigation Menu

Skip to content

Commit

Permalink
[Predictive Back] Make MaterialMainContainerBackHelper collapsedView …
Browse files Browse the repository at this point in the history
…optional

PiperOrigin-RevId: 536880239
  • Loading branch information
dsn5ft authored and afohrman committed Jun 5, 2023
1 parent e69a324 commit fb56ab4
Showing 1 changed file with 19 additions and 14 deletions.
Expand Up @@ -83,26 +83,28 @@ public Rect getInitialHideFromClipBounds() {
}

@RequiresApi(VERSION_CODES.UPSIDE_DOWN_CAKE)
public void startBackProgress(@NonNull BackEvent backEvent, @NonNull View collapsedView) {
public void startBackProgress(@NonNull BackEvent backEvent, @Nullable View collapsedView) {
super.onStartBackProgress(backEvent);

startBackProgress(backEvent.getTouchY(), collapsedView);
}

@VisibleForTesting
@RequiresApi(VERSION_CODES.UPSIDE_DOWN_CAKE)
public void startBackProgress(float touchY, @NonNull View collapsedView) {
public void startBackProgress(float touchY, @Nullable View collapsedView) {
initialHideToClipBounds = ViewUtils.calculateRectFromBounds(view);
initialHideFromClipBounds = ViewUtils.calculateOffsetRectFromBounds(view, collapsedView);
if (collapsedView != null) {
initialHideFromClipBounds = ViewUtils.calculateOffsetRectFromBounds(view, collapsedView);
}
initialTouchY = touchY;
}

@RequiresApi(VERSION_CODES.UPSIDE_DOWN_CAKE)
public void updateBackProgress(
@NonNull BackEvent backEvent, @NonNull View collapsedView, float collapsedCornerSize) {
@NonNull BackEvent backEvent, @Nullable View collapsedView, float collapsedCornerSize) {
super.onUpdateBackProgress(backEvent);

if (collapsedView.getVisibility() != View.INVISIBLE) {
if (collapsedView != null && collapsedView.getVisibility() != View.INVISIBLE) {
collapsedView.setVisibility(View.INVISIBLE);
}

Expand Down Expand Up @@ -140,7 +142,7 @@ public void updateBackProgress(
}

@RequiresApi(VERSION_CODES.UPSIDE_DOWN_CAKE)
public void finishBackProgress(long duration, @NonNull View collapsedView) {
public void finishBackProgress(long duration, @Nullable View collapsedView) {
AnimatorSet resetAnimator = createResetScaleAndTranslationAnimator(collapsedView);
resetAnimator.setDuration(duration);
resetAnimator.start();
Expand All @@ -149,7 +151,7 @@ public void finishBackProgress(long duration, @NonNull View collapsedView) {
}

@RequiresApi(VERSION_CODES.UPSIDE_DOWN_CAKE)
public void cancelBackProgress(@NonNull View collapsedView) {
public void cancelBackProgress(@Nullable View collapsedView) {
super.onCancelBackProgress();

AnimatorSet cancelAnimatorSet = createResetScaleAndTranslationAnimator(collapsedView);
Expand All @@ -169,19 +171,22 @@ private void resetInitialValues() {
}

@NonNull
private AnimatorSet createResetScaleAndTranslationAnimator(@NonNull View collapsedView) {
private AnimatorSet createResetScaleAndTranslationAnimator(@Nullable View collapsedView) {
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(
ObjectAnimator.ofFloat(view, View.SCALE_X, 1),
ObjectAnimator.ofFloat(view, View.SCALE_Y, 1),
ObjectAnimator.ofFloat(view, View.TRANSLATION_X, 0),
ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, 0));
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
collapsedView.setVisibility(View.VISIBLE);
}
});
animatorSet.addListener(
new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (collapsedView != null) {
collapsedView.setVisibility(View.VISIBLE);
}
}
});
return animatorSet;
}

Expand Down

0 comments on commit fb56ab4

Please sign in to comment.