Skip to content

Commit

Permalink
fix(Home): floating button scroll gesture capture (#1180)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr authored Oct 29, 2024
1 parent 3b0e1ca commit c1c4269
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
14 changes: 12 additions & 2 deletions src/Views/ContentBase.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class Tuba.Views.ContentBase : Views.Base {
content_box.child = content;

scrolled.vadjustment.value_changed.connect (on_scrolled_vadjustment_value_change);
scroll_to_top_rev.bind_property ("child-revealed", scroll_to_top_rev, "visible", GLib.BindingFlags.SYNC_CREATE);
}
~ContentBase () {
debug ("Destroying ContentBase");
Expand All @@ -55,14 +56,23 @@ public class Tuba.Views.ContentBase : Views.Base {
}

var is_close_to_top = scrolled.vadjustment.value <= 1000;
scroll_to_top_rev.reveal_child = !is_close_to_top
&& scrolled.vadjustment.value + scrolled.vadjustment.page_size + 100 < scrolled.vadjustment.upper;
set_scroll_to_top_reveal_child (
!is_close_to_top
&& scrolled.vadjustment.value + scrolled.vadjustment.page_size + 100 < scrolled.vadjustment.upper
);

#if !USE_LISTVIEW
if (is_close_to_top) reached_close_to_top ();
#endif
}

protected void set_scroll_to_top_reveal_child (bool reveal) {
if (reveal == scroll_to_top_rev.reveal_child) return;
if (reveal) scroll_to_top_rev.visible = true;

scroll_to_top_rev.reveal_child = reveal;
}

#if USE_LISTVIEW
protected virtual void bind_listitem_cb (GLib.Object item) {
((Gtk.ListItem) item).child = on_create_model_widget (((Gtk.ListItem) item).item);
Expand Down
35 changes: 26 additions & 9 deletions src/Views/Home.vala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
public class Tuba.Views.Home : Views.Timeline {
Gtk.Revealer compose_button_rev;
Gtk.Button compose_button;
construct {
url = "/api/v1/timelines/home";
label = _("Home");
Expand All @@ -11,21 +12,23 @@ public class Tuba.Views.Home : Views.Timeline {
scroll_to_top_rev.margin_bottom = 24;
scroll_to_top_rev.add_css_class ("scroll-to-top-btn");

compose_button = new Gtk.Button.from_icon_name ("document-edit-symbolic") {
action_name = "app.compose",
tooltip_text = _("Compose"),
css_classes = { "circular", "compose-button", "suggested-action" }
};
compose_button_rev = new Gtk.Revealer () {
transition_type = Gtk.RevealerTransitionType.SLIDE_UP,
valign = halign = Gtk.Align.END,
margin_end = 24,
margin_bottom = 24,
reveal_child = true,
overflow = Gtk.Overflow.VISIBLE,
child = new Gtk.Button.from_icon_name ("document-edit-symbolic") {
action_name = "app.compose",
tooltip_text = _("Compose"),
css_classes = { "circular", "compose-button", "suggested-action" },
margin_bottom = 24
}
child = compose_button
};

compose_button_rev.notify["reveal-child"].connect (toggle_scroll_to_top_margin);
compose_button_rev.notify["child-revealed"].connect (on_child_revealed);
toggle_scroll_to_top_margin ();

scrolled_overlay.add_overlay (compose_button_rev);
Expand All @@ -42,7 +45,7 @@ public class Tuba.Views.Home : Views.Timeline {

app.notify["is-mobile"].connect (() => {
if (!app.is_mobile)
compose_button_rev.reveal_child = true;
set_compose_button_reveal_child (true);
});

this.bind_property ("entity-queue-size", this, "badge-number", BindingFlags.SYNC_CREATE);
Expand All @@ -57,6 +60,20 @@ public class Tuba.Views.Home : Views.Timeline {
Tuba.toggle_css (scroll_to_top_rev, compose_button_rev.reveal_child, "composer-btn-revealed");
}

void set_compose_button_reveal_child (bool reveal) {
if (compose_button_rev.reveal_child == reveal) return;

compose_button.margin_bottom = 24;
compose_button_rev.margin_bottom = 0;

compose_button_rev.reveal_child = reveal;
}

void on_child_revealed () {
compose_button.margin_bottom = 0;
compose_button_rev.margin_bottom = 24;
}

double last_adjustment = 0;
double show_on_adjustment = -1;
bool last_direction_down = false;
Expand All @@ -76,9 +93,9 @@ public class Tuba.Views.Home : Views.Timeline {
}

if (compose_button_rev.reveal_child && direction_down)
compose_button_rev.reveal_child = false;
set_compose_button_reveal_child (false);
else if (!compose_button_rev.reveal_child && !direction_down && trunced <= show_on_adjustment)
compose_button_rev.reveal_child = true;
set_compose_button_reveal_child (true);

last_adjustment = trunced;
}
Expand Down

0 comments on commit c1c4269

Please sign in to comment.