public class ScrollOutOfBoundEventArgs : EventArgs
{
/// <summary>
- /// The bound to be scrolled out of.
+ /// The direction to be touched.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public enum Bound
+ public enum Direction
{
/// <summary>
- /// Top bound.
+ /// Upwards.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- Top,
+ Up,
/// <summary>
- /// Bottom bound.
+ /// Downwards.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- Bottom
+ Down,
}
/// <summary>
- /// Default constructor.
+ /// Constructor.
/// </summary>
- /// <param name="bound">Current scrollable bound</param>
+ /// <param name="direction">Current pan direction</param>
+ /// <param name="displacement">Current total displacement</param>
[EditorBrowsable(EditorBrowsableState.Never)]
- public ScrollOutOfBoundEventArgs(Bound bound)
+ public ScrollOutOfBoundEventArgs(Direction direction, float displacement)
{
- ScrollableBound = bound;
+ PanDirection = direction;
+ Displacement = displacement;
}
/// <summary>
- /// Current position of ContentContainer.
+ /// Current pan direction of ContentContainer.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Direction PanDirection
+ {
+ get;
+ }
+
+ /// <summary>
+ /// Current total displacement of ContentContainer.
+ /// if its value is greater than 0, it is at the top/left;
+ /// if less than 0, it is at the bottom/right.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public Bound ScrollableBound
+ public float Displacement
{
get;
}
isVerticalShadowShown = false;
}
- private void DragVerticalShadow(float displacement)
+ private void DragVerticalShadow(float totalPanDisplacement, float panDisplacement)
{
if (ScrollingDirection != Direction.Vertical)
return;
- if ((int)displacement > 0) // downwards
+ if (totalPanDisplacement > 0) // downwards
{
// check if reaching at the top.
if ((int)finalTargetPosition != 0)
// save start displacement, and re-calculate displacement.
if (!isVerticalShadowShown)
{
- startShowShadowDisplacement = displacement;
- OnScrollOutOfBound(ScrollOutOfBoundEventArgs.Bound.Top);
+ startShowShadowDisplacement = totalPanDisplacement;
}
isVerticalShadowShown = true;
- float newDisplacement = (int)displacement < (int)startShowShadowDisplacement ? 0 : displacement - startShowShadowDisplacement;
+ // trigger event
+ ScrollOutOfBoundEventArgs.Direction direction = panDisplacement > 0 ?
+ ScrollOutOfBoundEventArgs.Direction.Down : ScrollOutOfBoundEventArgs.Direction.Up;
+ OnScrollOutOfBound(direction, totalPanDisplacement);
+
+ float newDisplacement = (int)totalPanDisplacement < (int)startShowShadowDisplacement ? 0 : totalPanDisplacement - startShowShadowDisplacement;
// scale limit of width is 60%.
float widthScale = newDisplacement / verticalShadowScaleHeightLimit;
// scale limit of height is 300%.
verticalTopShadowView.SizeHeight = newDisplacement > verticalShadowScaleHeightLimit ? verticalShadowScaleHeightLimit : newDisplacement;
}
- else if ((int)displacement < 0) // upwards
+ else if (totalPanDisplacement < 0) // upwards
{
// check if reaching at the bottom.
if (-(int)finalTargetPosition != (int)maxScrollDistance)
// save start displacement, and re-calculate displacement.
if (!isVerticalShadowShown)
{
- startShowShadowDisplacement = displacement;
- OnScrollOutOfBound(ScrollOutOfBoundEventArgs.Bound.Bottom);
+ startShowShadowDisplacement = totalPanDisplacement;
}
isVerticalShadowShown = true;
- float newDisplacement = (int)startShowShadowDisplacement < (int)displacement ? 0 : startShowShadowDisplacement - displacement;
+ // trigger event
+ ScrollOutOfBoundEventArgs.Direction direction = panDisplacement > 0 ?
+ ScrollOutOfBoundEventArgs.Direction.Down : ScrollOutOfBoundEventArgs.Direction.Up;
+ OnScrollOutOfBound(direction, totalPanDisplacement);
+
+ float newDisplacement = (int)startShowShadowDisplacement < (int)totalPanDisplacement ? 0 : startShowShadowDisplacement - totalPanDisplacement;
// scale limit of width is 60%.
float widthScale = newDisplacement / verticalShadowScaleHeightLimit;
isVerticalShadowShown = false;
}
- private void OnScrollOutOfBound(ScrollOutOfBoundEventArgs.Bound bound)
+ private void OnScrollOutOfBound(ScrollOutOfBoundEventArgs.Direction direction, float displacement)
{
- ScrollOutOfBoundEventArgs args = new ScrollOutOfBoundEventArgs(bound);
+ ScrollOutOfBoundEventArgs args = new ScrollOutOfBoundEventArgs(direction, displacement);
ScrollOutOfBound?.Invoke(this, args);
}
ScrollBy(panGesture.Displacement.Y, false);
}
totalDisplacementForPan += panGesture.Displacement.Y;
- DragVerticalShadow(totalDisplacementForPan);
+ DragVerticalShadow(totalDisplacementForPan, panGesture.Displacement.Y);
}
Debug.WriteLineIf(LayoutDebugScrollableBase, "OnPanGestureDetected Continue totalDisplacementForPan:" + totalDisplacementForPan);
}
Position = new Position(300, 100),
Size = new Size(400, 300),
ScrollingDirection = Components.ScrollableBase.Direction.Vertical,
+ EnableOverShootingEffect = true,
};
mScrollableBase.ScrollOutOfBound += OnScrollOutOfBound;
private void OnScrollOutOfBound(object sender, Components.ScrollOutOfBoundEventArgs e)
{
- if (e.ScrollableBound == Components.ScrollOutOfBoundEventArgs.Bound.Top)
+ if (e.Displacement > 100)
{
- items[0].Text = "Reached at the top.";
+ if (e.PanDirection == Components.ScrollOutOfBoundEventArgs.Direction.Down)
+ {
+ items[0].Text = $"Reached at the top, panned displacement is {e.Displacement}.";
+ }
}
- else
+ else if (0 - e.Displacement > 100)
{
- items[4].Text = "Reached at the bottom.";
+ if (e.PanDirection == Components.ScrollOutOfBoundEventArgs.Direction.Up)
+ {
+ items[4].Text = $"Reached at the bottom, panned displacement is {e.Displacement}.";
+ }
}
}