android: fix peek height animation

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>
This commit is contained in:
Arnaud Vergnet 2023-01-01 21:01:25 +01:00 committed by Viktor Govako
parent a176a548d1
commit 8b5afb461a
2 changed files with 16 additions and 12 deletions

View file

@ -73,7 +73,7 @@ public class PlacePageController implements Initializable<Activity>,
@Override
public void onSheetCollapsed()
{
setPeekHeight();
// No op.
}
@Override
@ -164,12 +164,6 @@ public class PlacePageController implements Initializable<Activity>,
@BottomSheetBehavior.State
int currentState = mPlacePageBehavior.getState();
if (PlacePageUtils.isSettlingState(currentState) || PlacePageUtils.isDraggingState(currentState))
{
Logger.d(TAG, "Sheet state inappropriate, ignore.");
return;
}
final boolean shouldAnimate = PlacePageUtils.isCollapsedState(currentState) && mPlacePageBehavior.getPeekHeight() > 0;
mPlacePageBehavior.setPeekHeight(peekHeight, shouldAnimate);
}
@ -223,7 +217,15 @@ public class PlacePageController implements Initializable<Activity>,
public void onPlacePageHeightChange(int previewHeight)
{
mPreviewHeight = previewHeight;
setPeekHeight();
// Using .post() makes sure the peek height animation plays
mPlacePage.post(() -> {
setPeekHeight();
// Only show the place page if it was hidden
@BottomSheetBehavior.State
int state = mPlacePageBehavior.getState();
if (PlacePageUtils.isHiddenState(state))
mPlacePageBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
});
}
@Override
@ -302,10 +304,12 @@ public class PlacePageController implements Initializable<Activity>,
PlacePageButtons.class, null, PLACE_PAGE_BUTTONS_FRAGMENT_TAG)
.commit();
}
mPlacePage.post(() -> {
setPeekHeight();
else
{
// Only collapse the place page if it was already open
// If we are creating it, wait for the peek height to be available
mPlacePageBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
});
}
}
}

View file

@ -294,7 +294,7 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
final int oldHeight = oldBottom - oldTop;
final int newHeight = bottom - top;
if (oldHeight != newHeight)
mPreview.post(() -> mPlacePageViewListener.onPlacePageHeightChange(newHeight));
mPlacePageViewListener.onPlacePageHeightChange(newHeight);
});
mTvTitle = mPreview.findViewById(R.id.tv__title);
mTvTitle.setOnLongClickListener(this);