[gnome-games/wip/exalm/libhandy: 8/8] ui: Implement back swipe for collection subviews



commit c186cfe7f76c5cb47038efda30940597182c13f0
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Wed Feb 26 20:21:47 2020 +0500

    ui: Implement back swipe for collection subviews

 data/ui/collection-header-bar.ui  |  8 +++-----
 data/ui/platforms-view.ui         |  8 ++++++--
 src/ui/collection-box.vala        | 11 ++++++-----
 src/ui/collection-header-bar.vala | 30 +++++++++++++++++++++---------
 src/ui/collection-view.vala       | 11 +++++------
 src/ui/platforms-view.vala        | 26 ++++++++++++++++----------
 6 files changed, 57 insertions(+), 37 deletions(-)
---
diff --git a/data/ui/collection-header-bar.ui b/data/ui/collection-header-bar.ui
index a0293583..4ef36d4f 100644
--- a/data/ui/collection-header-bar.ui
+++ b/data/ui/collection-header-bar.ui
@@ -4,12 +4,10 @@
   <template class="GamesCollectionHeaderBar" parent="GtkBin">
     <property name="visible">True</property>
     <signal name="notify::is-collection-empty" handler="update_adaptive_state"/>
-    <signal name="notify::is-folded" handler="update_subview"/>
-    <signal name="notify::is-subview-open" handler="update_subview"/>
+    <signal name="notify::is-folded" handler="on_folded_changed"/>
     <child>
-      <object class="GtkStack" id="stack">
+      <object class="HdyDeck" id="deck">
         <property name="visible">True</property>
-        <property name="transition-type">slide-left-right</property>
         <child>
           <object class="HdyHeaderBar" id="header_bar">
             <property name="visible">True</property>
@@ -113,7 +111,7 @@
           </object>
         </child>
         <child>
-          <object class="GtkHeaderBar" id="subview_header_bar">
+          <object class="HdyHeaderBar" id="subview_header_bar">
             <property name="visible">True</property>
             <property name="show_close_button">True</property>
             <property name="title" bind-source="GamesCollectionHeaderBar" bind-property="subview-title" 
bind-flags="bidirectional"/>
diff --git a/data/ui/platforms-view.ui b/data/ui/platforms-view.ui
index 15c78e8c..318d67f9 100644
--- a/data/ui/platforms-view.ui
+++ b/data/ui/platforms-view.ui
@@ -7,12 +7,13 @@
     <signal name="map" after="yes" handler="on_map"/>
     <signal name="unmap" after="no" handler="on_unmap"/>
     <signal name="notify::is-folded" handler="update_selection_mode"/>
-    <signal name="notify::is-subview-open" handler="update_subview"/>
     <child>
       <object class="HdyLeaflet" id="leaflet">
         <property name="visible">True</property>
-        <property name="transition-type">slide</property>
+        <property name="can-swipe-back">True</property>
+        <property name="mode-transition-duration">200</property>
         <signal name="notify::folded" handler="on_leaflet_folded_changed"/>
+        <signal name="notify::visible-child" handler="on_visible_child_changed"/>
         <child>
           <object class="GtkScrolledWindow" id="scrolled_window">
             <property name="visible">True</property>
@@ -45,6 +46,9 @@
               <class name="sidebar"/>
             </style>
           </object>
+          <packing>
+            <property name="allow-visible">False</property>
+          </packing>
         </child>
         <child>
           <object class="GamesCollectionIconView" id="collection_view">
diff --git a/src/ui/collection-box.vala b/src/ui/collection-box.vala
index ecc23789..48e8f50f 100644
--- a/src/ui/collection-box.vala
+++ b/src/ui/collection-box.vala
@@ -5,6 +5,7 @@ private class Games.CollectionBox : Gtk.Box {
        public signal void game_activated (Game game);
 
        public GameModel game_model { get; construct; }
+       public Hdy.SwipeGroup swipe_group { get; construct; }
        public bool search_mode { get; set; }
        public bool loading_notification { get; set; }
 
@@ -67,10 +68,12 @@ private class Games.CollectionBox : Gtk.Box {
 
                collection_view.game_model = game_model;
                platform_view.game_model = game_model;
+
+               swipe_group.add_swipeable (platform_view.get_leaflet ());
        }
 
-       public CollectionBox (GameModel game_model) {
-               Object (game_model: game_model);
+       public CollectionBox (GameModel game_model, Hdy.SwipeGroup swipe_group) {
+               Object (game_model: game_model, swipe_group: swipe_group);
        }
 
        public void show_error (string error_message) {
@@ -163,9 +166,7 @@ private class Games.CollectionBox : Gtk.Box {
                if (viewstack.visible_child == collection_view)
                        collection_view.reset_scroll_position ();
                else
-                       platform_view.select_first_visible_row ();
-
-               is_subview_open = false;
+                       platform_view.reset ();
        }
 
        [GtkCallback]
diff --git a/src/ui/collection-header-bar.vala b/src/ui/collection-header-bar.vala
index b4f487f4..0351b10e 100644
--- a/src/ui/collection-header-bar.vala
+++ b/src/ui/collection-header-bar.vala
@@ -30,13 +30,14 @@ private class Games.CollectionHeaderBar : Gtk.Bin {
        public bool is_showing_bottom_bar { get; set; }
        public bool is_subview_open { get; set; }
        public string subview_title { get; set; }
+       public Hdy.SwipeGroup swipe_group { get; construct; }
 
        [GtkChild]
-       private Gtk.Stack stack;
+       private Hdy.Deck deck;
        [GtkChild]
        private Hdy.HeaderBar header_bar;
        [GtkChild]
-       private Gtk.HeaderBar subview_header_bar;
+       private Hdy.HeaderBar subview_header_bar;
        [GtkChild]
        private Hdy.Squeezer title_squeezer;
        [GtkChild]
@@ -44,6 +45,10 @@ private class Games.CollectionHeaderBar : Gtk.Bin {
 
        private ulong viewstack_child_changed_id;
 
+       public CollectionHeaderBar (Hdy.SwipeGroup swipe_group) {
+               Object (swipe_group: swipe_group);
+       }
+
        [GtkCallback]
        private void update_adaptive_state () {
                bool showing_title = title_squeezer.visible_child != view_switcher;
@@ -51,15 +56,22 @@ private class Games.CollectionHeaderBar : Gtk.Bin {
        }
 
        [GtkCallback]
-       private void update_subview () {
-               if (is_subview_open && is_folded)
-                       stack.visible_child = subview_header_bar;
-               else
-                       stack.visible_child = header_bar;
+       private void on_subview_back_clicked () {
+               back ();
        }
 
        [GtkCallback]
-       private void on_subview_back_clicked () {
-               is_subview_open = false;
+       private void on_folded_changed () {
+               if (is_folded) {
+                       deck.visible_child = is_subview_open ? subview_header_bar : header_bar;
+                       swipe_group.add_swipeable (deck);
+               } else {
+                       swipe_group.remove_swipeable (deck);
+                       deck.visible_child = header_bar;
+               }
+       }
+
+       public bool back () {
+               return deck.navigate (Hdy.NavigationDirection.BACK);
        }
 }
diff --git a/src/ui/collection-view.vala b/src/ui/collection-view.vala
index 63bfa1d5..ee872bec 100644
--- a/src/ui/collection-view.vala
+++ b/src/ui/collection-view.vala
@@ -47,8 +47,10 @@ private class Games.CollectionView : Object, UiView {
        private KonamiCode konami_code;
 
        construct {
-               box = new CollectionBox (game_model);
-               header_bar = new CollectionHeaderBar ();
+               var swipe_group = new Hdy.SwipeGroup ();
+
+               box = new CollectionBox (game_model, swipe_group);
+               header_bar = new CollectionHeaderBar (swipe_group);
                box.game_activated.connect (game => {
                        game_activated (game);
                });
@@ -120,11 +122,8 @@ private class Games.CollectionView : Object, UiView {
                if (((event.state & default_modifiers) == Gdk.ModifierType.MOD1_MASK) &&
                    (((window.get_direction () == Gtk.TextDirection.LTR) && keyval == Gdk.Key.Left) ||
                     ((window.get_direction () == Gtk.TextDirection.RTL) && keyval == Gdk.Key.Right)) &&
-                    is_subview_open) {
-                       is_subview_open = false;
-
+                    header_bar.back ())
                        return true;
-               }
 
                if ((keyval == Gdk.Key.f || keyval == Gdk.Key.F) &&
                    (event.state & default_modifiers) == Gdk.ModifierType.CONTROL_MASK &&
diff --git a/src/ui/platforms-view.vala b/src/ui/platforms-view.vala
index 4eecf973..03f20ecf 100644
--- a/src/ui/platforms-view.vala
+++ b/src/ui/platforms-view.vala
@@ -174,7 +174,7 @@ private class Games.PlatformsView : Gtk.Bin {
 
                        return true;
                case Gtk.DirectionType.RIGHT:
-                       is_subview_open = true;
+                       leaflet.navigate (Hdy.NavigationDirection.FORWARD);
                        collection_view.select_default_game (Gtk.DirectionType.RIGHT);
 
                        return true;
@@ -185,7 +185,7 @@ private class Games.PlatformsView : Gtk.Bin {
 
        [GtkCallback]
        private bool on_gamepad_accept () {
-               is_subview_open = true;
+               leaflet.navigate (Hdy.NavigationDirection.FORWARD);
                collection_view.select_default_game (Gtk.DirectionType.RIGHT);
 
                return true;
@@ -194,7 +194,7 @@ private class Games.PlatformsView : Gtk.Bin {
        [GtkCallback]
        private bool on_gamepad_cancel () {
                collection_view.unselect_game ();
-               is_subview_open = false;
+               leaflet.navigate (Hdy.NavigationDirection.BACK);
 
                return true;
        }
@@ -203,7 +203,7 @@ private class Games.PlatformsView : Gtk.Bin {
        private void on_list_box_row_activated (Gtk.ListBoxRow row_item) {
                select_platform_for_row (row_item);
 
-               is_subview_open = true;
+               leaflet.navigate (Hdy.NavigationDirection.FORWARD);
        }
 
        private void select_platform_for_row (Gtk.ListBoxRow row_item) {
@@ -215,7 +215,12 @@ private class Games.PlatformsView : Gtk.Bin {
                collection_view.reset_scroll_position ();
        }
 
-       public void select_first_visible_row () {
+       public void reset () {
+               select_first_visible_row ();
+               leaflet.navigate (Hdy.NavigationDirection.BACK);
+       }
+
+       private void select_first_visible_row () {
                foreach (var child in list_box.get_children ()) {
                        var row = child as Gtk.ListBoxRow;
 
@@ -271,10 +276,11 @@ private class Games.PlatformsView : Gtk.Bin {
        }
 
        [GtkCallback]
-       private void update_subview () {
-               if (is_subview_open)
-                       leaflet.visible_child = collection_view;
-               else
-                       leaflet.visible_child = scrolled_window;
+       private void on_visible_child_changed () {
+               is_subview_open = (leaflet.visible_child == collection_view);
+       }
+
+       public Hdy.Leaflet get_leaflet () {
+               return leaflet;
        }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]