Skip to content

Fix FAB position not persisting and resetting on control panel visibility changes - #804

Open
khanhtrancc wants to merge 1 commit into
AndreyPavlenko:masterfrom
khanhtrancc:fab
Open

Fix FAB position not persisting and resetting on control panel visibility changes#804
khanhtrancc wants to merge 1 commit into
AndreyPavlenko:masterfrom
khanhtrancc:fab

Conversation

@khanhtrancc

Copy link
Copy Markdown

Problem

The Menu/Back floating action button (FAB) has two positioning bugs:

  • Dragging it to a custom spot doesn't persist — the position is lost on
    app restart / view recreation, always reverting to the XML-defined
    default (bottom-end, above the control panel).
  • The position also resets mid-session whenever the media control panel
    (control_panel) shows or hides during playback. The FAB is
    constrained via app:layout_constraintBottom_toTopOf="@id/control_panel",
    so toggling that view's visibility makes ConstraintLayout re-solve all
    constraints and snap the FAB back to its anchor position, discarding
    the drag offset (which was only ever applied via setX/setY, never
    reflected in layout params).

Fix

Save the dragged position as a fraction (0–1) of the available drag
range, rather than raw pixels, and restore it on every layout pass:

  • Persist posX/posY fractions via a small dedicated
    SharedPreferenceStore, using the same PreferenceStore/Pref
    abstraction already used elsewhere in the codebase (e.g.
    MainActivityPrefs's percentage-based prefs).
  • Factor the drag-bounds calculation (previously inline in
    ACTION_MOVE) into a shared getDragBounds() helper, reused for
    clamping, saving, and restoring.
  • Save the fraction on ACTION_UP after a real drag.
  • Restore it from a new onLayout() override, which fires both on view
    recreation and on control-panel visibility changes — and is skipped
    while a drag is in progress so it can't fight the user's finger.

If the button was never dragged, the fraction stays unset and behavior
is unchanged (default constraint-defined position).

Scope

Change is fully contained to
depends/utils/src/main/java/me/aap/utils/ui/view/FloatingButton.java.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant