Skip to content

Commit c2c6176

Browse files
Add traces
1 parent 7d4ee6c commit c2c6176

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Draggable.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,11 @@ private class DefaultDraggableState(val onDelta: (Float) -> Unit) : DraggableSta
570570

571571
private sealed class DragEvent {
572572
class DragStarted(val startPoint: Offset) : DragEvent()
573-
class DragStopped(val velocity: Velocity) : DragEvent()
573+
class DragStopped(val velocity: Velocity) : DragEvent() {
574+
init {
575+
println("DragStopped with velocity: $velocity")
576+
}
577+
}
574578
object DragCancelled : DragEvent()
575579
class DragDelta(val delta: Offset) : DragEvent()
576580
}

compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/pointer/util/VelocityTracker.kt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class VelocityTracker {
7171
* This can be expensive. Only call this when you need the velocity.
7272
*/
7373
fun calculateVelocity(): Velocity {
74-
return Velocity(xVelocityTracker.calculateVelocity(), yVelocityTracker.calculateVelocity())
74+
return Velocity(xVelocityTracker.calculateVelocity(), yVelocityTracker.calculateVelocity(true))
7575
}
7676

7777
/**
@@ -186,7 +186,7 @@ class VelocityTracker1D internal constructor(
186186
*
187187
* This can be expensive. Only call this when you need the velocity.
188188
*/
189-
fun calculateVelocity(): Float {
189+
fun calculateVelocity(print: Boolean = false): Float {
190190
val dataPoints = reusableDataPointsArray
191191
val time = reusableTimeArray
192192
var sampleCount = 0
@@ -224,7 +224,7 @@ class VelocityTracker1D internal constructor(
224224
calculateImpulseVelocity(dataPoints, time, sampleCount, isDataDifferential)
225225
}
226226
Strategy.Lsq2 -> {
227-
calculateLeastSquaresVelocity(dataPoints, time, sampleCount)
227+
calculateLeastSquaresVelocity(dataPoints, time, sampleCount, print)
228228
}
229229
} * 1000 // Multiply by "1000" to convert from units/ms to units/s
230230
}
@@ -250,19 +250,30 @@ class VelocityTracker1D internal constructor(
250250
private fun calculateLeastSquaresVelocity(
251251
dataPoints: FloatArray,
252252
time: FloatArray,
253-
sampleCount: Int
253+
sampleCount: Int,
254+
print: Boolean = false
254255
): Float {
255256
// The 2nd coefficient is the derivative of the quadratic polynomial at
256257
// x = 0, and that happens to be the last timestamp that we end up
257258
// passing to polyFitLeastSquares.
259+
if (print) {
260+
println("Calculating velocity:")
261+
for (i in 0 until sampleCount) {
262+
println("${dataPoints[i]} at ${time[i]}")
263+
}
264+
}
258265
return try {
259-
polyFitLeastSquares(
266+
val velocity = polyFitLeastSquares(
260267
time,
261268
dataPoints,
262269
sampleCount,
263270
2,
264271
reusableVelocityCoefficients
265272
)[1]
273+
if (print) {
274+
println("velocity: $velocity")
275+
}
276+
velocity
266277
} catch (exception: IllegalArgumentException) {
267278
0f
268279
}
@@ -317,6 +328,8 @@ fun VelocityTracker.addPointerInputChange(event: PointerInputChange) {
317328
return
318329
}
319330

331+
println("addPointerInputChange y: ${event.position.y}; pressed: ${event.pressed}")
332+
320333
// To calculate delta, for each step we want to do currentPosition - previousPosition.
321334
// Initially the previous position is the previous position of the current event
322335
var previousPointerPosition = event.previousPosition

compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/SyntheticEventSender.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ internal class SyntheticEventSender(
101101
private fun sendSyntheticMove(pointersSourceEvent: PointerInputEvent) {
102102
val previousEvent = previousEvent ?: return
103103
val idToPosition = pointersSourceEvent.pointers.associate { it.id to it.position }
104+
println("synthetic move ${pointersSourceEvent.pointers[0].position.y}")
104105
sendInternal(
105106
previousEvent.copySynthetic(
106107
type = PointerEventType.Move,

compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeWindow.uikit.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import org.jetbrains.skiko.SkikoKeyboardEvent
6262
import org.jetbrains.skiko.SkikoPointerEvent
6363
import org.jetbrains.skiko.currentNanoTime
6464
import platform.CoreGraphics.CGPoint
65+
import org.jetbrains.skiko.SkikoPointerEventKind
6566
import org.jetbrains.skiko.available
6667
import platform.CoreGraphics.CGAffineTransformIdentity
6768
import platform.CoreGraphics.CGAffineTransformInvert

0 commit comments

Comments
 (0)