public enum Bound
{
/// <summary>
+ /// None.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ None,
+
+ /// <summary>
/// Top bound.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
}
/// <summary>
- /// Default constructor.
+ /// The direction to be touched.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public enum Direction
+ {
+ /// <summary>
+ /// None.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ None,
+
+ /// <summary>
+ /// Upwards.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ Up,
+
+ /// <summary>
+ /// Downwards.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ Down,
+ }
+
+ /// <summary>
+ /// 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(Bound bound, Direction direction, float displacement)
{
ScrollableBound = bound;
+ PanDirection = direction;
+ Displacement = displacement;
}
/// <summary>
- /// Current position of ContentContainer.
+ /// Current bound of ContentContainer.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public Bound ScrollableBound
{
get;
}
+
+ /// <summary>
+ /// Current pan direction of ContentContainer.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Direction PanDirection
+ {
+ get;
+ }
+
+ /// <summary>
+ /// Current total displacement of ContentContainer.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public float Displacement
+ {
+ get;
+ }
}
/// <summary>
isVerticalShadowShown = false;
}
- private void DragVerticalShadow(float displacement)
+ private void DragVerticalShadow(float totalPanDisplacement, float panDisplacement)
{
if (!EnableOverShootingEffect)
return;
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(ScrollOutOfBoundEventArgs.Bound.Top, 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(ScrollOutOfBoundEventArgs.Bound.Bottom, direction, totalPanDisplacement);
+
+ float newDisplacement = (int)startShowShadowDisplacement < (int)totalPanDisplacement ? 0 : startShowShadowDisplacement - totalPanDisplacement;
// scale limit of width is 60%.
float widthScale = newDisplacement / verticalShadowScaleHeightLimit;
{
// if total displacement is 0, shadow would become invisible.
isVerticalShadowShown = false;
+ OnScrollOutOfBound(ScrollOutOfBoundEventArgs.Bound.None, ScrollOutOfBoundEventArgs.Direction.None, totalPanDisplacement);
}
}
isVerticalShadowShown = false;
}
- private void OnScrollOutOfBound(ScrollOutOfBoundEventArgs.Bound bound)
+ private void OnScrollOutOfBound(ScrollOutOfBoundEventArgs.Bound bound, ScrollOutOfBoundEventArgs.Direction direction, float displacement)
{
- ScrollOutOfBoundEventArgs args = new ScrollOutOfBoundEventArgs(bound);
+ ScrollOutOfBoundEventArgs args = new ScrollOutOfBoundEventArgs(bound, 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);
}