onPullDistance
A view should call this when content is pulled away from an edge by the user. This will update the state of the current visual effect and its associated animation. The host view should always invalidate after this and draw the results accordingly. This works similarly to onPull, but returns the amount of deltaDistance
that has been consumed. For API level 31 and above, if the getDistance is currently 0 and deltaDistance
is negative, this function will return 0 and the drawn value will remain unchanged. For API level 30 and below, this will consume all of the provided value and return deltaDistance
. This method can be used to reverse the effect from a pull or absorb and partially consume some of a motion:
if (deltaY < 0 && EdgeEffectCompat.getDistance(edgeEffect) != 0) {
float displacement = x / getWidth();
float dist = deltaY / getHeight();
float consumed = EdgeEffectCompat.onPullDistance(edgeEffect, dist, displacement);
deltaY -= consumed * getHeight();
if (edgeEffect.getDistance() == 0f) edgeEffect.onRelease();
}
Return
The amount of deltaDistance
that was consumed, a number between 0 and deltaDistance
.
Parameters
EdgeEffect to use.
Change in distance since the last call. Values may be 0 (no change) to 1.f (full length of the view) or negative values to express change back toward the edge reached to initiate the effect.
The displacement from the starting side of the effect of the point initiating the pull. In the case of touch this is the finger position. Values may be from 0-1.