Add wheelEvent and WheelScrollDistance property on ScrollableBase (#4717)
authorSangHyeon Jade Lee <sh10233.lee@samsung.com>
Tue, 8 Nov 2022 06:50:26 +0000 (15:50 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Thu, 10 Nov 2022 01:25:11 +0000 (10:25 +0900)
* [NUI] add AutomationId on NavigationContent for automation support.

* Add wheelEvent and WheelScrollDistance property on ScrollableBase

* [NUI] update scrollableBase to call OnWheel in the OnWheelEvent

* [NUI] Update OnWheel xaml comments.

* Revert "[NUI] add AutomationId on NavigationContent for automation support."

This reverts commit 857e07d9b1fdc4661f8249bb4e6fba3264c856b6.

src/Tizen.NUI.Components/Controls/ScrollableBase.cs
src/Tizen.NUI.Components/Controls/ScrollableBaseBindableProperty.cs

index 398cfad..7a90695 100755 (executable)
@@ -848,6 +848,25 @@ namespace Tizen.NUI.Components
         }
         private float stepScrollDistance = 0f;
 
+        /// <summary>
+        /// Wheel scroll move distance.
+        /// This value decide how long distance will it moves in wheel event.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public float WheelScrollDistance
+        {
+            get
+            {
+                return (float)GetValue(WheelScrollDistanceProperty);
+            }
+            set
+            {
+                SetValue(WheelScrollDistanceProperty, value);
+                NotifyPropertyChanged();
+            }
+        }
+        private float wheelScrollDistance = 50f;
+
 
         // Let's consider more whether this needs to be set as protected.
         private float finalTargetPosition;
@@ -942,6 +961,8 @@ namespace Tizen.NUI.Components
                 PivotPoint = NUI.PivotPoint.CenterRight,
             };
 
+            WheelEvent += OnWheelEvent;
+
             AccessibilityManager.Instance.SetAccessibilityAttribute(this, AccessibilityManager.AccessibilityAttribute.Trait, "ScrollableBase");
 
             SetKeyboardNavigationSupport(true);
@@ -1363,6 +1384,8 @@ namespace Tizen.NUI.Components
                 propertyNotification = null;
             }
 
+            WheelEvent -= OnWheelEvent;
+
             if (type == DisposeTypes.Explicit)
             {
 
@@ -2148,6 +2171,26 @@ namespace Tizen.NUI.Components
 
             return true;
         }
+
+        /// <inheritdoc/>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override bool OnWheel(Wheel wheel)
+        {
+            if (wheel == null)
+            {
+                return false;
+            }
+
+            float currentScrollPosition = -(ScrollingDirection == Direction.Horizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y);
+            ScrollTo(currentScrollPosition + (wheelScrollDistance * wheel.Z), false);
+
+            return true;
+        }
+
+        private bool OnWheelEvent(object o, WheelEventArgs e)
+        {
+            return OnWheel(e?.Wheel);
+        }
     }
 
 } // namespace
index 9ceb2f1..a601003 100755 (executable)
@@ -312,6 +312,24 @@ namespace Tizen.NUI.Components
         });
 
         /// <summary>
+        /// WheelScrollDistanceProperty
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static readonly BindableProperty WheelScrollDistanceProperty = BindableProperty.Create(nameof(WheelScrollDistance), typeof(float), typeof(ScrollableBase), default(float), propertyChanged: (bindable, oldValue, newValue) =>
+        {
+            var instance = (ScrollableBase)bindable;
+            if (newValue != null)
+            {
+                instance.wheelScrollDistance = (float)newValue;
+            }
+        },
+        defaultValueCreator: (bindable) =>
+        {
+            var instance = (ScrollableBase)bindable;
+            return instance.stepScrollDistance;
+        });
+
+        /// <summary>
         /// FadeScrollbarProperty
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]