Skip to content

Commit

Permalink
fix: spinners should spin only when visible (#146)
Browse files Browse the repository at this point in the history
* fix: spinners should spin only when visible

* fix: init spinners with spinning false

* fix(media_viewer): set spinning to false on clear
  • Loading branch information
GeopJr authored Apr 3, 2023
1 parent 073a386 commit d5d3468
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
1 change: 0 additions & 1 deletion data/ui/views/base.ui
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
<property name="child">
<object class="GtkSpinner" id="status_spinner">
<property name="height_request">32</property>
<property name="spinning">True</property>
</object>
</property>
</object>
Expand Down
6 changes: 4 additions & 2 deletions src/Dialogs/Composer/AttachmentsPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Tuba.AttachmentsPage : ComposerPage {
"video/x-ms-asf"
};

private Gtk.Spinner spinner;
public GLib.ListStore attachments;
public Adw.ToastOverlay toast_overlay;
public bool can_publish { get; set; default = false; }
Expand Down Expand Up @@ -117,8 +118,8 @@ public class Tuba.AttachmentsPage : ComposerPage {
stack.add_named (list, "list");
stack.add_named (empty_state, "empty");

var spinner = new Gtk.Spinner() {
spinning = true,
spinner = new Gtk.Spinner() {
spinning = false,
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER,
vexpand = true,
Expand Down Expand Up @@ -161,6 +162,7 @@ public class Tuba.AttachmentsPage : ComposerPage {
var is_empty = attachments_size < 1;
if (is_empty || uploading) {
stack.visible_child_name = uploading ? "spinner" : "empty";
spinner.spinning = uploading;
bottom_bar.hide ();
can_publish = false;
} else {
Expand Down
10 changes: 9 additions & 1 deletion src/Views/Base.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class Tuba.Views.Base : Box {
[GtkChild] unowned Stack status_stack;
[GtkChild] unowned Label status_title_label;
[GtkChild] unowned Label status_message_label;
[GtkChild] unowned Spinner status_spinner;

public string state { get; set; default = "status"; }
public string status_title { get; set; default = STATUS_EMPTY; }
Expand All @@ -41,9 +42,16 @@ public class Tuba.Views.Base : Box {
build_header ();

status_button.label = _("Reload");
bind_property ("state", states, "visible-child-name", BindingFlags.SYNC_CREATE);
bind_property ("state", states, "visible-child-name", BindingFlags.SYNC_CREATE, (b, src, ref target) => {
target.set_string (src.get_string ());
if (src.get_string () != "status") status_spinner.spinning = false;

return true;
});
bind_property ("status-loading", status_stack, "visible-child-name", BindingFlags.SYNC_CREATE, (b, src, ref target) => {
target.set_string (src.get_boolean () ? "spinner" : "message");
status_spinner.spinning = src.get_boolean ();

return true;
});
bind_property ("status-message", status_message_label, "label", BindingFlags.SYNC_CREATE, (b, src, ref target) => {
Expand Down
8 changes: 5 additions & 3 deletions src/Views/MediaViewer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Tuba.Views.MediaViewer : Gtk.Box {
public bool spinning {
set {
stack.visible_child_name = value ? "spinner" : _type;
spinner.spinning = value;
}
get { return stack.visible_child_name == "spinner"; }
}
Expand All @@ -38,6 +39,7 @@ public class Tuba.Views.MediaViewer : Gtk.Box {
protected Gtk.Button fullscreen_btn;
protected Adw.HeaderBar headerbar;
protected ImageCache image_cache;
private Gtk.Spinner spinner;
public Gdk.Paintable paintable {
set {
_type = "image";
Expand Down Expand Up @@ -88,8 +90,8 @@ public class Tuba.Views.MediaViewer : Gtk.Box {
};
stack.add_named(pic, "image");

var spinner = new Gtk.Spinner() {
spinning = true,
spinner = new Gtk.Spinner() {
spinning = false,
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER,
vexpand = true,
Expand Down Expand Up @@ -213,7 +215,7 @@ public class Tuba.Views.MediaViewer : Gtk.Box {
this.paintable = null;
this.set_video(null);
this.url = "";
this.spinning = true;
this.spinning = false;
}

private void on_media_viewer_cache_response(bool is_loaded, owned Gdk.Paintable? data) {
Expand Down

0 comments on commit d5d3468

Please sign in to comment.