-
public final class RotaryKt
-
-
Method Summary
Modifier and Type Method Description final static ModifierrotaryWithFling(Modifier $self, FocusRequester focusRequester, ScrollableState scrollableState, FlingBehavior flingBehavior, RotaryHapticFeedback rotaryHaptics, Boolean reverseDirection)A modifier which connects rotary events with scrollable. final static ModifierrotaryWithScroll(Modifier $self, FocusRequester focusRequester, ScrollableState scrollableState, RotaryHapticFeedback rotaryHaptics, Boolean reverseDirection)A modifier which connects rotary events with scrollable. final static ModifierrotaryWithSnap(Modifier $self, FocusRequester focusRequester, RotaryScrollAdapter rotaryScrollAdapter, RotaryHapticFeedback rotaryHaptics, Boolean reverseDirection)A modifier which connects rotary events with scrollable. final static RotaryScrollAdaptertoRotaryScrollAdapter(ScalingLazyListState $self)An extension function for creating RotaryScrollAdapter from ScalingLazyListState final static ModifierrotaryHandler(Modifier $self, RotaryScrollHandler rotaryScrollHandler, Long batchTimeframe, Boolean reverseDirection, RotaryHapticFeedback rotaryHaptics)A modifier which handles rotary events. final static Flow<TimestampedDelta>batchRequestsWithinTimeframe(Flow<TimestampedDelta> $self, Long timeframe)Batching requests for scrolling events. -
-
Method Detail
-
rotaryWithFling
@Composable() final static Modifier rotaryWithFling(Modifier $self, FocusRequester focusRequester, ScrollableState scrollableState, FlingBehavior flingBehavior, RotaryHapticFeedback rotaryHaptics, Boolean reverseDirection)
A modifier which connects rotary events with scrollable. This modifier supports fling.
Fling algorithm:
A scroll with RSB/ Bezel happens.
If this is a first rotary event after the threshold ( by default 200ms), a new scroll session starts by resetting all necessary parameters
A delta value is added into VelocityTracker and a new speed is calculated.
If the current speed is bigger than the previous one, this value is remembered as a latest fling speed with a timestamp
After each scroll event a fling countdown starts ( by default 70ms) which resets if new scroll event is received
If fling countdown is finished - it means that the finger was probably raised from RSB, there will be no other events and probably this is the last event during this session. After it a fling is triggered.
Fling is stopped when a new scroll event happens
The screen containing the scrollable item should request the focus by calling requestFocus method
LaunchedEffect(Unit) { focusRequester.requestFocus() }- Parameters:
focusRequester- Requests the focus for rotary inputscrollableState- Scrollable state which will be scrolled while receiving rotary eventsflingBehavior- Logic describing fling behavior.rotaryHaptics- Class which will handle haptic feedbackreverseDirection- Reverse the direction of scrolling.
-
rotaryWithScroll
@Composable() final static Modifier rotaryWithScroll(Modifier $self, FocusRequester focusRequester, ScrollableState scrollableState, RotaryHapticFeedback rotaryHaptics, Boolean reverseDirection)
A modifier which connects rotary events with scrollable. This modifier only supports scroll without fling or snap. The screen containing the scrollable item should request the focus by calling requestFocus method
LaunchedEffect(Unit) { focusRequester.requestFocus() }- Parameters:
focusRequester- Requests the focus for rotary inputscrollableState- Scrollable state which will be scrolled while receiving rotary eventsrotaryHaptics- Class which will handle haptic feedbackreverseDirection- Reverse the direction of scrolling.
-
rotaryWithSnap
@Composable() final static Modifier rotaryWithSnap(Modifier $self, FocusRequester focusRequester, RotaryScrollAdapter rotaryScrollAdapter, RotaryHapticFeedback rotaryHaptics, Boolean reverseDirection)
A modifier which connects rotary events with scrollable. This modifier supports snap.
The screen containing the scrollable item should request the focus by calling requestFocus method
LaunchedEffect(Unit) { focusRequester.requestFocus() }- Parameters:
focusRequester- Requests the focus for rotary inputrotaryScrollAdapter- A connection between scrollable objects and rotary eventsrotaryHaptics- Class which will handle haptic feedbackreverseDirection- Reverse the direction of scrolling.
-
toRotaryScrollAdapter
final static RotaryScrollAdapter toRotaryScrollAdapter(ScalingLazyListState $self)
An extension function for creating RotaryScrollAdapter from ScalingLazyListState
-
rotaryHandler
final static Modifier rotaryHandler(Modifier $self, RotaryScrollHandler rotaryScrollHandler, Long batchTimeframe, Boolean reverseDirection, RotaryHapticFeedback rotaryHaptics)
A modifier which handles rotary events. It accepts ScrollHandler as the input - a class where main logic about how scroll should be handled is lying
-
batchRequestsWithinTimeframe
final static Flow<TimestampedDelta> batchRequestsWithinTimeframe(Flow<TimestampedDelta> $self, Long timeframe)
Batching requests for scrolling events. This function combines all events together (except first) within specified timeframe. Should help with performance on high-res devices.
-
-
-
-