Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore unpressed events during velocity calculation on iOS #848

Merged
merged 6 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ private fun Array<DataPointAtTime?>.set(index: Int, time: Long, dataPoint: Float
}
}

/**
* Some platforms (e.g. iOS) velocity calculation is incorrect when end position is used in velocity calculation.
*/
internal expect val onlyPressedEventsForVelocityTracker: Boolean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: hide such details in ios-actual and use something like:

internal expect fun VelocityTracker.shouldUse(event: PointerInputChange)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.


/**
* Track the positions and timestamps inside this event change.
*
Expand All @@ -308,6 +313,10 @@ fun VelocityTracker.addPointerInputChange(event: PointerInputChange) {
resetTracking()
}

if (onlyPressedEventsForVelocityTracker && !event.pressed) {
return
}

// To calculate delta, for each step we want to do currentPosition - previousPosition.
// Initially the previous position is the previous position of the current event
var previousPointerPosition = event.previousPosition
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.ui.input.pointer.util

/**
* Some platforms (e.g. iOS) velocity calculation is incorrect when end position is used in velocity calculation.
*/
internal actual val onlyPressedEventsForVelocityTracker: Boolean
MatkovIvan marked this conversation as resolved.
Show resolved Hide resolved
get() = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.ui.input.pointer.util

/**
* Some platforms (e.g. iOS) velocity calculation is incorrect when end position is used in velocity calculation.
*/
internal actual val onlyPressedEventsForVelocityTracker: Boolean
get() = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.ui.input.pointer.util

/**
* Some platforms (e.g. iOS) velocity calculation is incorrect when end position is used in velocity calculation.
*/
internal actual val onlyPressedEventsForVelocityTracker: Boolean
get() = true