[go: nahoru, domu]

blob: 815a84c426e86414545a5d9c29692ef72ec07b9c [file] [log] [blame]
shepshapardf8860d22019-01-31 11:09:48 -08001/*
2 * Copyright 2019 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
17package androidx.ui.core.gesture
18
George Mount842c8c12020-01-08 16:03:42 -080019import androidx.ui.unit.Duration
20import androidx.ui.unit.dp
21import androidx.ui.unit.milliseconds
shepshapardf8860d22019-01-31 11:09:48 -080022
23/**
24 * Modeled after Android's ViewConfiguration:
25 * https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/ViewConfiguration.java
26 */
27
28/**
29 * The time that must elapse before a tap gesture sends onTapDown, if there's
30 * any doubt that the gesture is a tap.
31 */
32val PressTimeout: Duration = 100.milliseconds
33
34/**
35 * Maximum length of time between a tap down and a tap up for the gesture to be
Shep Shapardad4e8152020-04-03 13:22:08 -070036 * considered a tap. (Currently not honored by the TapGestureFilter.)
shepshapardf8860d22019-01-31 11:09:48 -080037 */
Shep Shapardad4e8152020-04-03 13:22:08 -070038// TODO(shepshapard): Remove this, or implement a hover-tap gesture filter which
shepshapardf8860d22019-01-31 11:09:48 -080039// uses this.
40val HoverTapTimeout: Duration = 150.milliseconds
41
42/**
43 * Maximum distance between the down and up pointers for a tap. (Currently not
Shep Shapardad4e8152020-04-03 13:22:08 -070044 * honored by the [TapGestureFilter].
shepshapardf8860d22019-01-31 11:09:48 -080045 */
46// TODO(shepshapard): Remove this or implement it correctly.
47val HoverTapSlop = 20.dp
48
49/** The time before a long press gesture attempts to win. */
50val LongPressTimeout: Duration = 500.milliseconds
51
52/**
53 * The maximum time from the start of the first tap to the start of the second
54 * tap in a double-tap gesture.
55 */
56// TODO(shepshapard): In Android, this is actually the time from the first's up event
57// to the second's down event, according to the ViewConfiguration docs.
58val DoubleTapTimeout: Duration = 300.milliseconds
59
60/**
61 * The minimum time from the end of the first tap to the start of the second
62 * tap in a double-tap gesture. (Currently not honored by the
Shep Shapardad4e8152020-04-03 13:22:08 -070063 * DoubleTapGestureFilter.)
shepshapardf8860d22019-01-31 11:09:48 -080064 */
65// TODO(shepshapard): Either implement this or remove the constant.
66val DoubleTapMinTime: Duration = 40.milliseconds
67
68/**
69 * The distance a touch has to travel for the framework to be confident that
70 * the gesture is a scroll gesture, or, inversely, the maximum distance that a
71 * touch can travel before the framework becomes confident that it is not a
72 * tap.
73 */
74// This value was empirically derived. We started at 8.0 and increased it to
75// 18.0 after getting complaints that it was too difficult to hit targets.
76val TouchSlop = 18.dp
77
78/**
79 * The maximum distance that the first touch in a double-tap gesture can travel
80 * before deciding that it is not part of a double-tap gesture.
Shep Shapardad4e8152020-04-03 13:22:08 -070081 * DoubleTapGestureFilter also restricts the second touch to this distance.
shepshapardf8860d22019-01-31 11:09:48 -080082 */
83val DoubleTapTouchSlop = TouchSlop
84
85/**
86 * Distance between the initial position of the first touch and the start
87 * position of a potential second touch for the second touch to be considered
88 * the second touch of a double-tap gesture.
89 */
90val DoubleTapSlop = 100.dp
91
92/**
93 * The time for which zoom controls (e.g. in a map interface) are to be
94 * displayed on the screen, from the moment they were last requested.
95 */
96val ZoomControlsTimeout: Duration = 3000.milliseconds
97
98/**
99 * The distance a touch has to travel for the framework to be confident that
100 * the gesture is a paging gesture. (Currently not used, because paging uses a
101 * regular drag gesture, which uses kTouchSlop.)
102 */
Shep Shapardad4e8152020-04-03 13:22:08 -0700103// TODO(shepshapard): Create variants of HorizontalDragGestureFilter et al for
shepshapardf8860d22019-01-31 11:09:48 -0800104// paging, which use this constant.
105val PagingTouchSlop = TouchSlop * 2.dp
106
107/**
108 * The distance a touch has to travel for the framework to be confident that
109 * the gesture is a panning gesture.
110 */
111val PanSlop = TouchSlop * 2.dp
112
113/**
shepshapardb14d6432019-08-05 17:13:22 -0700114 * The absolute cumulative average change in distance of all pointers from the
115 * average pointer over time that must be surpassed to indicate the user is trying to scale.
116 *
117 * For example, if [ScaleSlop] is 5 DP and 2 pointers were 1 DP away from each
118 * other and now are 11.00001 DP away from each other, the gesture will be interpreted to include
119 * scaling (both pointers are slightly more than 5 pixels away from the average of the pointers
120 * than they were).
shepshapardf8860d22019-01-31 11:09:48 -0800121 */
122val ScaleSlop = TouchSlop
123
124/**
Louis Pullen-Freilich5da28bd2019-10-15 17:05:07 +0100125 * The margin around a dialog, popup menu, or other window-like composable inside
126 * which we do not consider a tap to dismiss the composable. (Not currently used.)
shepshapardf8860d22019-01-31 11:09:48 -0800127 */
128// TODO(shepshapard): Make ModalBarrier support this.
129val WindowTouchSlop = 16.dp
130
131/**
132 * The minimum velocity for a touch to consider that touch to trigger a fling
133 * gesture.
134 */
135// TODO(shepshapard): Make sure nobody has their own version of this.
136val MinFlingVelocity = 50.dp // Logical pixels / second
137
138/** Drag gesture fling velocities are clipped to this value. */
139// TODO(shepshapard): Make sure nobody has their own version of this.
140val MaxFlingVelocity = 8000.dp // Logical pixels / second
141
142/**
143 * The maximum time from the start of the first tap to the start of the second
144 * tap in a jump-tap gesture.
145 */
146// TODO(shepshapard): Implement jump-tap gestures.
147val JumpTapTimeout: Duration = 500.milliseconds