Drag a selected event straight away and keep it selected (#141)
This commit is contained in:
@@ -116,14 +116,18 @@ private fun rememberPickUpSurface(
|
|||||||
val currentDrop by rememberUpdatedState(onDrop)
|
val currentDrop by rememberUpdatedState(onDrop)
|
||||||
val currentCancel by rememberUpdatedState(onCancel)
|
val currentCancel by rememberUpdatedState(onCancel)
|
||||||
val currentRelease by rememberUpdatedState(onRelease)
|
val currentRelease by rememberUpdatedState(onRelease)
|
||||||
|
// Read per gesture rather than keyed on: the pickup itself can change it,
|
||||||
|
// and a restart would cancel the drag it just began.
|
||||||
|
val currentImmediate by rememberUpdatedState(immediate)
|
||||||
|
|
||||||
return Modifier
|
return Modifier
|
||||||
.onGloballyPositioned { coordinates[0] = it }
|
.onGloballyPositioned { coordinates[0] = it }
|
||||||
.pointerInput(key, immediate) {
|
.pointerInput(key) {
|
||||||
val slop = viewConfiguration.touchSlop
|
val slop = viewConfiguration.touchSlop
|
||||||
awaitEachGesture {
|
awaitEachGesture {
|
||||||
val down = awaitFirstDown(requireUnconsumed = false)
|
val down = awaitFirstDown(requireUnconsumed = false)
|
||||||
val origin = down.position
|
val origin = down.position
|
||||||
|
val immediate = currentImmediate
|
||||||
// Null on the timeout — held still — true once an [immediate]
|
// Null on the timeout — held still — true once an [immediate]
|
||||||
// block has been moved past slop, false when the press is
|
// block has been moved past slop, false when the press is
|
||||||
// abandoned.
|
// abandoned.
|
||||||
|
|||||||
@@ -401,9 +401,9 @@ class TimelineDragController {
|
|||||||
pointerInRoot: Offset,
|
pointerInRoot: Offset,
|
||||||
blockInRoot: Offset,
|
blockInRoot: Offset,
|
||||||
) {
|
) {
|
||||||
// A pickup ends any selection: a drop moves the event out from under
|
// Picking up another event ends the selection; the selected one keeps
|
||||||
// it, and a release without moving selects again.
|
// it through the drag, and the screen moves it along with the drop.
|
||||||
selection = null
|
if (!isSelected(block)) selection = null
|
||||||
source = block
|
source = block
|
||||||
this.clipOffsetMin = clipOffsetMin
|
this.clipOffsetMin = clipOffsetMin
|
||||||
this.titleLines = titleLines
|
this.titleLines = titleLines
|
||||||
|
|||||||
@@ -519,6 +519,14 @@ private fun WeekContent(
|
|||||||
val move = LocalEventMove.current
|
val move = LocalEventMove.current
|
||||||
val zone = remember { TimeZone.currentSystemDefault() }
|
val zone = remember { TimeZone.currentSystemDefault() }
|
||||||
val onDrop: (TimelineDrop) -> Unit = { drop ->
|
val onDrop: (TimelineDrop) -> Unit = { drop ->
|
||||||
|
// A selected event stays selected where it landed (#141).
|
||||||
|
if (dragController.selection?.event?.instanceId == drop.event.instanceId) {
|
||||||
|
val start = drop.startInstant(zone)
|
||||||
|
dragController.select(
|
||||||
|
drop.event.copy(start = start, end = start + (drop.event.end - drop.event.start)),
|
||||||
|
start.toLocalDateTime(zone).date,
|
||||||
|
)
|
||||||
|
}
|
||||||
move?.move(
|
move?.move(
|
||||||
MoveRequest(
|
MoveRequest(
|
||||||
eventId = drop.event.eventId,
|
eventId = drop.event.eventId,
|
||||||
|
|||||||
Reference in New Issue
Block a user