diff --git a/src/Dialogs/MainWindow.vala b/src/Dialogs/MainWindow.vala index 113b2a913..1b5259374 100644 --- a/src/Dialogs/MainWindow.vala +++ b/src/Dialogs/MainWindow.vala @@ -79,7 +79,7 @@ public class Tuba.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable { ) { if (as_is && preview == null) return; - media_viewer.add_media (url, media_type, preview, pos, as_is, alt_text, user_friendly_url, stream); + media_viewer.add_media (url, media_type, preview, pos, as_is, alt_text, user_friendly_url, stream, source_widget); if (!is_media_viewer_visible) { media_viewer.reveal (source_widget); diff --git a/src/Views/MediaViewer.vala b/src/Views/MediaViewer.vala index 2215a8647..d7c63715f 100644 --- a/src/Views/MediaViewer.vala +++ b/src/Views/MediaViewer.vala @@ -373,10 +373,15 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable { enabled = true, allow_mouse_drag = true }; + swipe_tracker.prepare.connect (on_swipe_tracker_prepare); swipe_tracker.update_swipe.connect (on_update_swipe); swipe_tracker.end_swipe.connect (on_end_swipe); } + private void on_swipe_tracker_prepare (Adw.NavigationDirection direction) { + update_revealer_widget (); + } + private void on_update_swipe (double progress) { this.swipe_children_opacity = 0.0; this.swipe_progress = progress; @@ -673,6 +678,7 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable { } private void reset_media_viewer () { + revealer_widgets.clear (); this.fullscreen = false; todo_items.clear (); @@ -686,6 +692,11 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable { revealed = false; } + private void update_revealer_widget () { + if (revealed && revealer_widgets.has_key ((int) carousel.position)) + scale_revealer.source_widget = revealer_widgets.get ((int) carousel.position); + } + private async string download_video (string url) throws Error { return yield Host.download (url); } @@ -702,6 +713,7 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable { do_todo_items (); } + public Gee.HashMap revealer_widgets = new Gee.HashMap (); public void add_media ( string url, Tuba.Attachment.MediaType media_type, @@ -710,11 +722,14 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable { bool as_is = false, string? alt_text = null, string? user_friendly_url = null, - bool stream = false + bool stream = false, + Gtk.Widget? revealer_widget = null ) { Item item; string final_friendly_url = user_friendly_url == null ? url : user_friendly_url; Gdk.Paintable? final_preview = as_is ? null : preview; + if (revealer_widget != null) + revealer_widgets.set (pos == null ? items.size : pos, revealer_widget); if (media_type.is_video ()) { var video = new Gtk.Video (); diff --git a/src/Widgets/ScaleRevealer.vala b/src/Widgets/ScaleRevealer.vala index 03118cb13..131e2bc1f 100644 --- a/src/Widgets/ScaleRevealer.vala +++ b/src/Widgets/ScaleRevealer.vala @@ -6,9 +6,29 @@ public class Tuba.Widgets.ScaleRevealer : Adw.Bin { public signal void transition_done (); public Adw.TimedAnimation animation { get; construct set; } - public Gtk.Widget? source_widget { get; set; } + private Gtk.Widget? _source_widget = null; + public Gtk.Widget? source_widget { + get { + return _source_widget; + } + set { + if (_source_widget != null) + _source_widget.opacity = 1.0; + _source_widget = value; + update_source_widget (); + } + } public Gdk.Texture? source_widget_texture { get; set; } + private void update_source_widget () { + if (this.source_widget == null) { + source_widget_texture = null; + } else { + source_widget_texture = render_widget_to_texture (this.source_widget); + this.source_widget.opacity = 0.0; + } + } + private bool _reveal_child = false; public bool reveal_child { get { @@ -22,13 +42,7 @@ public class Tuba.Widgets.ScaleRevealer : Adw.Bin { if (value) { animation.value_to = 1.0; this.visible = true; - - if (source_widget == null) { - source_widget_texture = null; - } else { - source_widget_texture = render_widget_to_texture (this.source_widget); - source_widget.opacity = 0.0; - } + update_source_widget (); } else { animation.value_to = 0.0; } @@ -119,7 +133,7 @@ public class Tuba.Widgets.ScaleRevealer : Adw.Bin { if (source_widget == null) return; if (source_widget_texture == null) { - warning ("The source widget texture is None, using child snapshot as fallback"); + // The source widget texture is None, using child snapshot as fallback this.snapshot_child (this.child, snapshot); } else { if (progress > 0.0) {