using Tizen.NUI.BaseComponents;
using System.ComponentModel;
using System.Diagnostics;
+
namespace Tizen.NUI.Components
{
/// <summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class ScrollEventArgs : EventArgs
{
+ Position position;
+
+ /// <summary>
+ /// Default constructor.
+ /// </summary>
+ /// <param name="position">Current scroll position</param>
+ /// <since_tizen> 6 </since_tizen>
+ /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
+ public ScrollEventArgs(Position position)
+ {
+ this.position = position;
+ }
+
+ /// <summary>
+ /// [Draft] Current scroll position.
+ /// </summary>
+ /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Position Position
+ {
+ get
+ {
+ return position;
+ }
+ }
}
/// <summary>
public event EventHandler<ScrollEventArgs> ScrollAnimationEndEvent;
+ /// <summary>
+ /// An event emitted when scrolling, user can subscribe or unsubscribe to this event handler.<br />
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public event EventHandler<ScrollEventArgs> ScrollEvent;
private Animation scrollAnimation;
private float maxScrollDistance;
// If false then can only flick pages when the current animation/scroll as ended.
private bool flickWhenAnimating = false;
+ private PropertyNotification propertyNotification;
/// <summary>
/// [Draft] Constructor
mTapGestureDetector.Attach(this);
mTapGestureDetector.Detected += OnTapGestureDetected;
+
ClippingMode = ClippingModeType.ClipToBoundingBox;
mScrollingChild = new View();
+ mScrollingChild.Name = "DefaultScrollingChild";
Layout = new ScrollableBaseCustomLayout();
}
+ private void OnPropertyChanged(object source, PropertyNotification.NotifyEventArgs args)
+ {
+ OnScroll();
+ }
+
/// <summary>
/// Called after a child has been added to the owning view.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public override void OnChildAdd(View view)
{
+ if(mScrollingChild.Name != "DefaultScrollingChild")
+ {
+ propertyNotification.Notified -= OnPropertyChanged;
+ mScrollingChild.RemovePropertyNotification(propertyNotification);
+ }
+
mScrollingChild = view;
+ propertyNotification = mScrollingChild?.AddPropertyNotification("position", PropertyCondition.Step(1.0f));
+ propertyNotification.Notified += OnPropertyChanged;
+
{
- if (Children.Count > 1)
- Log.Error("ScrollableBase", $"Only 1 child should be added to ScrollableBase.");
+ if (Children.Count > 1)
+ Log.Error("ScrollableBase", $"Only 1 child should be added to ScrollableBase.");
}
}
[EditorBrowsable(EditorBrowsableState.Never)]
public override void OnChildRemove(View view)
{
+ propertyNotification.Notified -= OnPropertyChanged;
+ mScrollingChild.RemovePropertyNotification(propertyNotification);
+
mScrollingChild = new View();
}
private void OnScrollDragStart()
{
- ScrollEventArgs eventArgs = new ScrollEventArgs();
+ ScrollEventArgs eventArgs = new ScrollEventArgs(mScrollingChild.CurrentPosition);
ScrollDragStartEvent?.Invoke(this, eventArgs);
}
private void OnScrollDragEnd()
{
- ScrollEventArgs eventArgs = new ScrollEventArgs();
+ ScrollEventArgs eventArgs = new ScrollEventArgs(mScrollingChild.CurrentPosition);
ScrollDragEndEvent?.Invoke(this, eventArgs);
}
private void OnScrollAnimationStart()
{
- ScrollEventArgs eventArgs = new ScrollEventArgs();
+ ScrollEventArgs eventArgs = new ScrollEventArgs(mScrollingChild.CurrentPosition);
ScrollAnimationStartEvent?.Invoke(this, eventArgs);
}
private void OnScrollAnimationEnd()
{
- ScrollEventArgs eventArgs = new ScrollEventArgs();
+ ScrollEventArgs eventArgs = new ScrollEventArgs(mScrollingChild.CurrentPosition);
ScrollAnimationEndEvent?.Invoke(this, eventArgs);
}
+ private void OnScroll()
+ {
+ ScrollEventArgs eventArgs = new ScrollEventArgs(mScrollingChild.CurrentPosition);
+ ScrollEvent?.Invoke(this, eventArgs);
+ }
+
private void StopScroll()
{
if (scrollAnimation != null)
totalDisplacementForPan += e.PanGesture.Displacement.Y;
}
Debug.WriteLineIf(LayoutDebugScrollableBase, "OnPanGestureDetected Continue totalDisplacementForPan:" + totalDisplacementForPan);
-
}
else if (e.PanGesture.State == Gesture.StateType.Finished)
{
scrolling = false;
OnScrollAnimationEnd();
}
-
}
} // namespace