Suggestion: allow to choose the direction of the menu
Closed this issue · 3 comments
Currently the only direction that the menu follows when it's opened is up. It would be great if the developer can choose another direction (having by default the menu going up).
In my case I want to put the button on the top of the screen and open the menu as dropdown.
It can be done just introducing a flag and changing a bit this method:
private void setSpeedDialMenuVisible(final boolean visible) {
// busy?
if (busyAnimatingSpeedDialMenu) return;
busyAnimatingSpeedDialMenu = true;
// animate, setting visibility as well to prevent phantom clicks
int distance = button.getHeight();
for (int i = 0, n = speedDialMenuItems.size(); i < n; ++i) {
final View v = speedDialMenuItems.get(i);
if (visible) v.setVisibility(VISIBLE);
v.animate()
.translationY(visible ? ((i + 1) * distance * -1) - (distance / 8) : 0F)
.alpha(visible ? 1F : 0F)
.setDuration(SPEED_DIAL_ANIMATION_DURATION)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
busyAnimatingSpeedDialMenu = false;
if (!visible) v.setVisibility(GONE);
}
});
}
}
This method is inside FloatActionButton.
I have thought in something like this:
private void setSpeedDialMenuVisible(final boolean visible, int direction) {
// busy?
if (busyAnimatingSpeedDialMenu) return;
busyAnimatingSpeedDialMenu = true;
// animate, setting visibility as well to prevent phantom clicks
int distance = button.getHeight();
for (int i = 0, n = speedDialMenuItems.size(); i < n; ++i) {
final View v = speedDialMenuItems.get(i);
if (visible) v.setVisibility(VISIBLE);
v.animate()
.alpha(visible ? 1F : 0F)
.setDuration(SPEED_DIAL_ANIMATION_DURATION)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
busyAnimatingSpeedDialMenu = false;
if (!visible) v.setVisibility(GONE);
}
});
switch(direction){
case DOWN:
v.animate().translationY(visible ? ((i + 1) * distance * -1) - (distance / 8) : 0F)
break;
case UP:
v.animate().translationY(visible ? ((i + 1) * distance * +1) - (distance / 8) : 0F)
break;
case RIGHT:
v.animate().translationX(visible ? ((i + 1) * distance * -1) - (distance / 8) : 0F)
break;
case LEFT:
v.animate().translationX(visible ? ((i + 1) * distance * +1) - (distance / 8) : 0F)
break;
}
}
}
What do you think?
Thanks for the suggestion @AyoPrez. This is actually something I've been thinking about for a while. There's a full re-write of this project on the cards in the near(ish)-future, and I will most likely be including this feature. I'll leave this open until then!
I'm going to close this as there is more info about the FR in #15.