public class ScrollOutOfBoundEventArgs : EventArgs
{
/// <summary>
- /// The direction to be touched.
+ /// The bound to be scrolled out of.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public enum Direction
+ public enum Bound
{
/// <summary>
- /// Upwards.
+ /// Top bound.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- Up,
+ Top,
/// <summary>
- /// Downwards.
+ /// Bottom bound.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- Down,
- }
-
- /// <summary>
- /// Constructor.
- /// </summary>
- /// <param name="direction">Current pan direction</param>
- /// <param name="displacement">Current total displacement</param>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public ScrollOutOfBoundEventArgs(Direction direction, float displacement)
- {
- PanDirection = direction;
- Displacement = displacement;
+ Bottom
}
/// <summary>
- /// Current pan direction of ContentContainer.
+ /// Default constructor.
/// </summary>
+ /// <param name="bound">Current scrollable bound</param>
[EditorBrowsable(EditorBrowsableState.Never)]
- public Direction PanDirection
+ public ScrollOutOfBoundEventArgs(Bound bound)
{
- get;
+ ScrollableBound = bound;
}
/// <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.
+ /// Current position of ContentContainer.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public float Displacement
+ public Bound ScrollableBound
{
get;
}
isVerticalShadowShown = false;
}
- private void DragVerticalShadow(float totalPanDisplacement, float panDisplacement)
+ private void DragVerticalShadow(float displacement)
{
if (ScrollingDirection != Direction.Vertical)
return;
- if (totalPanDisplacement > 0) // downwards
+ if ((int)displacement > 0) // downwards
{
// check if reaching at the top.
if ((int)finalTargetPosition != 0)
// save start displacement, and re-calculate displacement.
if (!isVerticalShadowShown)
{
- startShowShadowDisplacement = totalPanDisplacement;
+ startShowShadowDisplacement = displacement;
+ OnScrollOutOfBound(ScrollOutOfBoundEventArgs.Bound.Top);
}
isVerticalShadowShown = true;
- // 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;
+ float newDisplacement = (int)displacement < (int)startShowShadowDisplacement ? 0 : displacement - 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 (totalPanDisplacement < 0) // upwards
+ else if ((int)displacement < 0) // upwards
{
// check if reaching at the bottom.
if (-(int)finalTargetPosition != (int)maxScrollDistance)
// save start displacement, and re-calculate displacement.
if (!isVerticalShadowShown)
{
- startShowShadowDisplacement = totalPanDisplacement;
+ startShowShadowDisplacement = displacement;
+ OnScrollOutOfBound(ScrollOutOfBoundEventArgs.Bound.Bottom);
}
isVerticalShadowShown = true;
- // 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;
+ float newDisplacement = (int)startShowShadowDisplacement < (int)displacement ? 0 : startShowShadowDisplacement - displacement;
// scale limit of width is 60%.
float widthScale = newDisplacement / verticalShadowScaleHeightLimit;
isVerticalShadowShown = false;
}
- private void OnScrollOutOfBound(ScrollOutOfBoundEventArgs.Direction direction, float displacement)
+ private void OnScrollOutOfBound(ScrollOutOfBoundEventArgs.Bound bound)
{
- ScrollOutOfBoundEventArgs args = new ScrollOutOfBoundEventArgs(direction, displacement);
+ ScrollOutOfBoundEventArgs args = new ScrollOutOfBoundEventArgs(bound);
ScrollOutOfBound?.Invoke(this, args);
}
ScrollBy(panGesture.Displacement.Y, false);
}
totalDisplacementForPan += panGesture.Displacement.Y;
- DragVerticalShadow(totalDisplacementForPan, panGesture.Displacement.Y);
+ DragVerticalShadow(totalDisplacementForPan);
}
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.Displacement > 100)
+ if (e.ScrollableBound == Components.ScrollOutOfBoundEventArgs.Bound.Top)
{
- if (e.PanDirection == Components.ScrollOutOfBoundEventArgs.Direction.Down)
- {
- items[0].Text = $"Reached at the top, panned displacement is {e.Displacement}.";
- }
+ items[0].Text = "Reached at the top.";
}
- else if (0 - e.Displacement > 100)
+ else
{
- if (e.PanDirection == Components.ScrollOutOfBoundEventArgs.Direction.Up)
- {
- items[4].Text = $"Reached at the bottom, panned displacement is {e.Displacement}.";
- }
+ items[4].Text = "Reached at the bottom.";
}
}