Skip to content

Instantly share code, notes, and snippets.

View vilgotf's full-sized avatar

Tim Vilgot Mikael Fredenberg vilgotf

View GitHub Profile
@vilgotf
vilgotf / Selection.kt
Last active July 16, 2025 11:30
Compose UI selection with drag support
/**
* Selects items with drag gestures after a long press.
*
* After long pressing on an initial item, other items may be selected when dragging away from the
* initial element and unselected when dragging towards the initial element. The initial element
* remains selected during the drag. The pointer input handling will be cancelled and **re-started**
* when [selectableWithDrag] is recomposed with a different [key].
*
* @param itemAtPosition finds the item index at the given position.
* @param selectedItems items that are currently selected.
@vilgotf
vilgotf / Time.kt
Last active August 25, 2025 08:06
Compose time state
/** State update interval. */
sealed class Interval {
/** Update the state every [duration]. */
data class Delay(val duration: Duration) : Interval()
/** Update the state every frame. */
data object Frame : Interval()
}
/** Returns a state of the elapsed time since this composable first entered composition. */