|
| 1 | +/* |
| 2 | + * Copyright 2022 The Android Open Source Project |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package androidx.compose.foundation.gestures |
| 18 | + |
| 19 | +import androidx.compose.ui.geometry.Offset |
| 20 | +import androidx.compose.ui.input.pointer.PointerEvent |
| 21 | +import androidx.compose.ui.node.CompositionLocalConsumerModifierNode |
| 22 | +import androidx.compose.ui.unit.Density |
| 23 | +import androidx.compose.ui.unit.IntSize |
| 24 | +import androidx.compose.ui.unit.dp |
| 25 | +import androidx.compose.ui.util.fastFold |
| 26 | +import kotlin.math.sqrt |
| 27 | + |
| 28 | +internal actual fun CompositionLocalConsumerModifierNode.platformScrollConfig(): ScrollConfig = |
| 29 | + LinuxScrollConfig |
| 30 | + |
| 31 | +private object LinuxScrollConfig : ScrollConfig { |
| 32 | + // See https://developer.apple.com/documentation/appkit/nsevent/1535387-scrollingdeltay |
| 33 | + override fun Density.calculateMouseWheelScroll(event: PointerEvent, bounds: IntSize): Offset { |
| 34 | + // 64 dp value is taken from ViewConfiguration.java, replace with better solution |
| 35 | + |
| 36 | + val verticalScrollFactor = -64.dp.toPx() |
| 37 | + |
| 38 | + val horizontalScrollFactor = -64.dp.toPx() |
| 39 | + |
| 40 | + return event.changes |
| 41 | + .fastFold(Offset.Zero) { acc, c -> acc + c.scrollDelta } |
| 42 | + .let { Offset(it.x * horizontalScrollFactor, it.y * verticalScrollFactor) } |
| 43 | + } |
| 44 | +} |
0 commit comments