SnapLayoutInfoProvider


Provides information about the layout that is using a SnapFlingBehavior. The provider should give the following information:

  1. Snapping offset: The next snap position offset.

  2. Approach offset: An optional offset to be consumed before snapping to a defined bound.

In snapping, the approach offset and the snapping offset can be used to control how a snapping animation will look in a given SnappingLayout. The complete snapping animation can be split into 2 phases: Approach and Snapping. In the Approach phase, we'll use an animation to consume all of the offset provided by calculateApproachOffset, if Float.NaN is provided, we'll naturally decay if possible. In the snapping phase, SnapFlingBehavior will use an animation to consume all of the offset provided by calculateSnappingOffset.

Summary

Public functions

open Float
calculateApproachOffset(initialVelocity: Float)

Calculate the distance to navigate before settling into the next snapping bound.

Cmn
Float
calculateSnappingOffset(currentVelocity: Float)

Given a target placement in a layout, the snapping offset is the next snapping position this layout can be placed in.

Cmn

Public functions

calculateApproachOffset

open fun calculateApproachOffset(initialVelocity: Float): Float

Calculate the distance to navigate before settling into the next snapping bound. If Float.NaN (the default value) is returned and the velocity is high enough to decay, SnapFlingBehavior will decay before snapping. If zero is specified, that means there won't be an approach phase and there will only be snapping.

Parameters
initialVelocity: Float

The current fling movement velocity. You can use this to calculate a velocity based offset.

calculateSnappingOffset

fun calculateSnappingOffset(currentVelocity: Float): Float

Given a target placement in a layout, the snapping offset is the next snapping position this layout can be placed in. The target placement should be in the direction of currentVelocity.

Parameters
currentVelocity: Float

The current fling movement velocity. This may change throughout the fling animation.