swipeWithVelocity
fun IndirectPointerInjectionScope.swipeWithVelocity(
start: Offset,
end: Offset,
@FloatRange(from = 0.0) endVelocity: Float,
durationMillis: Long = VelocityPathFinder.calculateDefaultDuration(start, end, endVelocity),
)
Performs a swipe gesture on nodes in the focus path such that it ends with the given endVelocity.
The swipe will go through start at t=0 and through end at t=durationMillis. In between, the swipe will go monotonically from start and end, but not strictly. Due to imprecision, no guarantees can be made for the actual velocity at the end of the gesture, but generally it is within 0.1 of the desired velocity.
When a swipe cannot be created that results in the desired velocity (because the input is too restrictive), an exception will be thrown with suggestions to fix the input.
The coordinates are NOT in the node's local coordinate system and is usually used for focused movement (that is, a focused node would move to the next focusable node in the hierarchy with a swipe).
The default duration is calculated such that a feasible swipe can be created that ends in the given velocity.
Parameters
| start | The position of the pointer starting the swipe gesture, in the indirect pointer input device's coordinate system. |
| end | The position of the pointer ending the swipe gesture, in the indirect pointer input device's coordinate system. |
| endVelocity | The velocity of the swipe gesture at the moment it ends in px/second. Must be positive. |
| durationMillis | The duration of the swipe gesture in milliseconds. Must be long enough that at least 3 input events are generated, which happens with a duration of 40ms or more. If omitted, a duration is calculated such that a valid swipe with velocity can be created. |
swipeWithVelocity
Deprecated
Replaced by TouchInjectionScope. Use performTouchInput instead of performGesture
fun GestureScope.swipeWithVelocity(
start: Offset,
end: Offset,
/*@FloatRange(from = 0.0)*/
endVelocity: Float,
durationMillis: Long = 200,
) = delegateScope.touch { swipeWithVelocity(start, end, endVelocity, durationMillis) }
Performs the swipe gesture on the associated node, such that the velocity when the gesture is finished is roughly equal to endVelocity. The MotionEvents are linearly interpolated between start and end. The coordinates are in the node's local coordinate system, where (0, 0) is the top left corner of the node. The default duration is 200 milliseconds.
Note that due to imprecisions, no guarantees can be made on the precision of the actual velocity at the end of the gesture, but generally it is within 0.1% of the desired velocity.
Parameters
| start | The start position of the gesture, in the node's local coordinate system |
| end | The end position of the gesture, in the node's local coordinate system |
| endVelocity | The velocity of the gesture at the moment it ends. Must be positive. |
| durationMillis | The duration of the gesture in milliseconds. Must be long enough that at least 3 input events are generated, which happens with a duration of 25ms or more. |
swipeWithVelocity
fun TouchInjectionScope.swipeWithVelocity(
start: Offset,
end: Offset,
/*@FloatRange(from = 0.0)*/
endVelocity: Float,
durationMillis: Long = VelocityPathFinder.calculateDefaultDuration(start, end, endVelocity),
)
Performs a swipe gesture on the associated node such that it ends with the given endVelocity.
The swipe will go through start at t=0 and through end at t=durationMillis. In between, the swipe will go monotonically from start and end, but not strictly. Due to imprecision, no guarantees can be made for the actual velocity at the end of the gesture, but generally it is within 0.1 of the desired velocity.
When a swipe cannot be created that results in the desired velocity (because the input is too restrictive), an exception will be thrown with suggestions to fix the input.
The coordinates are in the node's local coordinate system, where (0, 0) is the top left corner of the node. The default duration is calculated such that a feasible swipe can be created that ends in the given velocity.
Parameters
| start | The start position of the gesture, in the node's local coordinate system |
| end | The end position of the gesture, in the node's local coordinate system |
| endVelocity | The velocity of the gesture at the moment it ends in px/second. Must be positive. |
| durationMillis | The duration of the gesture in milliseconds. Must be long enough that at least 3 input events are generated, which happens with a duration of 40ms or more. If omitted, a duration is calculated such that a valid swipe with velocity can be created. |