From bfea10ffcd43cb34fa65ce6b984d9f42abd392d9 Mon Sep 17 00:00:00 2001 From: Evan Paterakis Date: Sat, 26 Oct 2024 18:49:18 +0300 Subject: [PATCH] fix(Home): floating button scroll gesture capture --- src/Views/ContentBase.vala | 14 ++++++++++++-- src/Views/Home.vala | 35 ++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/Views/ContentBase.vala b/src/Views/ContentBase.vala index 5768d21d..22c5d205 100644 --- a/src/Views/ContentBase.vala +++ b/src/Views/ContentBase.vala @@ -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"); @@ -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); diff --git a/src/Views/Home.vala b/src/Views/Home.vala index 8ebbf90a..ef97508b 100644 --- a/src/Views/Home.vala +++ b/src/Views/Home.vala @@ -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"); @@ -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); @@ -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); @@ -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; @@ -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; }