Reputation: 493
I got a bottomsheet upon which, while swiping i need to animate arrow button indicating weather user swiping up or down?
Here is my Sample Test one, while swiping the bottom sheet as you can see in the image, the arrow button at the bottom should rotate downward while swiping up, and on swiping down button should rotate upwards.
Thanks, Jay
Upvotes: 3
Views: 3221
Reputation: 39
Sachin's answer is great.
Here's another solution, by maintaining the previous state of the bottomsheet.
int previousBottomSheetState = BottomSheetBehavior.STATE_COLLAPSED
bottom_sheet.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
//to prevent rotation of the arrow if the users swipes down or up again, even when its already collapsed or expanded.
if (newState == BottomSheetBehavior.STATE_EXPANDED && newState != previousBottomSheetState) {
//update my bottomsheet state.
previousBottomSheetState = BottomSheetBehavior.STATE_EXPANDED;
(yourView).animate().rotationXBy(180).start();
} else if (newState == BottomSheetBehavior.STATE_COLLAPSED && newState != previousBottomSheetState) {
previousBottomSheetState = BottomSheetBehavior.STATE_COLLAPSED;
(yourView).animate().rotationXBy(180).start();
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
Upvotes: 0
Reputation: 726
it is achievable using BottomSheetCallback
. You just need to rotate the view by offset provided by the callback. For Example :-
// set callback for changes
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
yourView.setRotation(slideOffset * 180);
}
});
Upvotes: 18