[NUI] Calculate MaxScrollDistance in Relayout (#1665)
authorneostom432 <31119276+neostom432@users.noreply.github.com>
Tue, 9 Jun 2020 08:01:27 +0000 (17:01 +0900)
committerGitHub <noreply@github.com>
Tue, 9 Jun 2020 08:01:27 +0000 (17:01 +0900)
src/Tizen.NUI.Components/Controls/ScrollableBase.cs

index 952f032..8477c37 100755 (executable)
@@ -378,7 +378,6 @@ namespace Tizen.NUI.Components
             mTapGestureDetector.Attach(this);
             mTapGestureDetector.Detected += OnTapGestureDetected;
 
-
             ClippingMode = ClippingModeType.ClipToBoundingBox;
 
             mScrollingChild = new View();
@@ -392,14 +391,16 @@ namespace Tizen.NUI.Components
                 BackgroundColor = Color.Transparent,
             };
 
-            mInterruptTouchingChild.TouchEvent += (object source, View.TouchEventArgs args) =>
-            {
-                return true;
-            };
+            mInterruptTouchingChild.TouchEvent += OnIterruptTouchingChildTouched;
 
             Layout = new ScrollableBaseCustomLayout();
         }
 
+        private bool OnIterruptTouchingChildTouched(object source, View.TouchEventArgs args)
+        {
+            return true;
+        }
+
         private void OnPropertyChanged(object source, PropertyNotification.NotifyEventArgs args)
         {
             OnScroll();
@@ -420,11 +421,13 @@ namespace Tizen.NUI.Components
                 {
                     propertyNotification.Notified -= OnPropertyChanged;
                     mScrollingChild.RemovePropertyNotification(propertyNotification);
+                    mScrollingChild.Relayout -= OnScrollingChildRelayout;
                 }
 
                 mScrollingChild = view;
                 propertyNotification = mScrollingChild?.AddPropertyNotification("position", PropertyCondition.Step(1.0f));
                 propertyNotification.Notified += OnPropertyChanged;
+                mScrollingChild.Relayout += OnScrollingChildRelayout;
             }
         }
 
@@ -441,11 +444,18 @@ namespace Tizen.NUI.Components
             {
                 propertyNotification.Notified -= OnPropertyChanged;
                 mScrollingChild.RemovePropertyNotification(propertyNotification);
+                mScrollingChild.Relayout -= OnScrollingChildRelayout;
 
                 mScrollingChild = new View();
             }
         }
 
+        private void OnScrollingChildRelayout(object source, EventArgs args)
+        {
+            // Size is changed. Calculate maxScrollDistance.
+            maxScrollDistance = CalculateMaximumScrollDistance();
+        }
+
         /// <summary>
         /// Scrolls to the item at the specified index.
         /// </summary>
@@ -465,8 +475,6 @@ namespace Tizen.NUI.Components
                 CurrentPage = index;
             }
 
-            maxScrollDistance = CalculateMaximumScrollDistance();
-
             float targetPosition = Math.Min(ScrollingDirection == Direction.Vertical ? mScrollingChild.Children[index].Position.Y : mScrollingChild.Children[index].Position.X, maxScrollDistance);
             AnimateChildTo(ScrollDuration, -targetPosition);
         }
@@ -816,7 +824,6 @@ namespace Tizen.NUI.Components
                 {
                     StopScroll();
                 }
-                maxScrollDistance = CalculateMaximumScrollDistance();
                 totalDisplacementForPan = 0.0f;
                 OnScrollDragStart();
             }