Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 | |
Louis Pullen-Freilich | ddda7be | 2020-07-17 18:28:12 +0100 | [diff] [blame] | 17 | package androidx.compose.foundation |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 18 | |
| 19 | import android.os.Handler |
| 20 | import android.os.Looper |
Louis Pullen-Freilich | 5bb0c471 | 2020-07-20 22:01:15 +0100 | [diff] [blame] | 21 | import androidx.compose.animation.core.ExponentialDecay |
| 22 | import androidx.compose.animation.core.ManualAnimationClock |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 23 | import androidx.compose.Composable |
Adam Powell | 5f07ae8 | 2020-03-30 14:36:42 -0700 | [diff] [blame] | 24 | import androidx.compose.getValue |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 25 | import androidx.compose.mutableStateOf |
Adam Powell | 5f07ae8 | 2020-03-30 14:36:42 -0700 | [diff] [blame] | 26 | import androidx.compose.setValue |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 27 | import androidx.test.filters.SmallTest |
| 28 | import androidx.ui.core.Modifier |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 29 | import androidx.ui.core.gesture.scrollorientationlocking.Orientation |
Filip Pavlis | 6de64f5 | 2020-05-27 18:11:55 +0100 | [diff] [blame] | 30 | import androidx.ui.core.testTag |
Louis Pullen-Freilich | ddda7be | 2020-07-17 18:28:12 +0100 | [diff] [blame] | 31 | import androidx.compose.foundation.animation.FlingConfig |
| 32 | import androidx.compose.foundation.gestures.ScrollableController |
| 33 | import androidx.compose.foundation.gestures.scrollable |
Louis Pullen-Freilich | 623e405 | 2020-07-19 20:24:03 +0100 | [diff] [blame] | 34 | import androidx.compose.foundation.layout.Stack |
| 35 | import androidx.compose.foundation.layout.preferredSize |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 36 | import androidx.ui.test.center |
| 37 | import androidx.ui.test.createComposeRule |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 38 | import androidx.ui.test.performGesture |
| 39 | import androidx.ui.test.onNodeWithTag |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 40 | import androidx.ui.test.runOnIdle |
Filip Pavlis | 6fdb250 | 2020-04-02 14:41:32 +0100 | [diff] [blame] | 41 | import androidx.ui.test.runOnUiThread |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 42 | import androidx.ui.test.swipe |
| 43 | import androidx.ui.test.swipeWithVelocity |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 44 | import androidx.ui.geometry.Offset |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 45 | import androidx.ui.unit.dp |
| 46 | import androidx.ui.unit.milliseconds |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 47 | import com.google.common.truth.Truth |
| 48 | import com.google.common.truth.Truth.assertThat |
| 49 | import org.junit.Rule |
| 50 | import org.junit.Test |
| 51 | import org.junit.runner.RunWith |
| 52 | import org.junit.runners.JUnit4 |
| 53 | import java.util.concurrent.CountDownLatch |
| 54 | import java.util.concurrent.TimeUnit |
| 55 | |
| 56 | @SmallTest |
| 57 | @RunWith(JUnit4::class) |
| 58 | class ScrollableTest { |
| 59 | |
| 60 | @get:Rule |
| 61 | val composeTestRule = createComposeRule() |
| 62 | |
| 63 | private val scrollableBoxTag = "scrollableBox" |
| 64 | |
| 65 | @Test |
| 66 | fun scrollable_horizontalScroll() { |
| 67 | val clocks = ManualAnimationClock(0L) |
| 68 | var total = 0f |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 69 | val controller = ScrollableController( |
| 70 | consumeScrollDelta = { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 71 | total += it |
| 72 | it |
| 73 | }, |
| 74 | flingConfig = FlingConfig(decayAnimation = ExponentialDecay()), |
| 75 | animationClock = clocks |
| 76 | ) |
| 77 | setScrollableContent { |
Matvei Malkov | 4a945c3 | 2020-03-27 16:27:23 +0000 | [diff] [blame] | 78 | Modifier.scrollable( |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 79 | controller = controller, |
| 80 | orientation = Orientation.Horizontal |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 81 | ) |
| 82 | } |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 83 | onNodeWithTag(scrollableBoxTag).performGesture { |
| 84 | this.swipe( |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 85 | start = this.center, |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 86 | end = Offset(this.center.x + 100f, this.center.y), |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 87 | duration = 100.milliseconds |
| 88 | ) |
| 89 | } |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 90 | advanceClockAndAwaitAnimation(controller, clocks) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 91 | |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 92 | val lastTotal = runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 93 | assertThat(total).isGreaterThan(0) |
| 94 | total |
| 95 | } |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 96 | onNodeWithTag(scrollableBoxTag).performGesture { |
| 97 | this.swipe( |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 98 | start = this.center, |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 99 | end = Offset(this.center.x, this.center.y + 100f), |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 100 | duration = 100.milliseconds |
| 101 | ) |
| 102 | } |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 103 | advanceClockAndAwaitAnimation(controller, clocks) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 104 | |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 105 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 106 | assertThat(total).isEqualTo(lastTotal) |
| 107 | } |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 108 | onNodeWithTag(scrollableBoxTag).performGesture { |
| 109 | this.swipe( |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 110 | start = this.center, |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 111 | end = Offset(this.center.x - 100f, this.center.y), |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 112 | duration = 100.milliseconds |
| 113 | ) |
| 114 | } |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 115 | advanceClockAndAwaitAnimation(controller, clocks) |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 116 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 117 | assertThat(total).isLessThan(0.01f) |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | @Test |
| 122 | fun scrollable_verticalScroll() { |
| 123 | val clocks = ManualAnimationClock(0L) |
| 124 | var total = 0f |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 125 | val controller = ScrollableController( |
| 126 | consumeScrollDelta = { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 127 | total += it |
| 128 | it |
| 129 | }, |
| 130 | flingConfig = FlingConfig(decayAnimation = ExponentialDecay()), |
| 131 | animationClock = clocks |
| 132 | ) |
| 133 | setScrollableContent { |
Matvei Malkov | 4a945c3 | 2020-03-27 16:27:23 +0000 | [diff] [blame] | 134 | Modifier.scrollable( |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 135 | controller = controller, |
| 136 | orientation = Orientation.Vertical |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 137 | ) |
| 138 | } |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 139 | onNodeWithTag(scrollableBoxTag).performGesture { |
| 140 | this.swipe( |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 141 | start = this.center, |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 142 | end = Offset(this.center.x, this.center.y + 100f), |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 143 | duration = 100.milliseconds |
| 144 | ) |
| 145 | } |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 146 | advanceClockAndAwaitAnimation(controller, clocks) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 147 | |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 148 | val lastTotal = runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 149 | assertThat(total).isGreaterThan(0) |
| 150 | total |
| 151 | } |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 152 | onNodeWithTag(scrollableBoxTag).performGesture { |
| 153 | this.swipe( |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 154 | start = this.center, |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 155 | end = Offset(this.center.x + 100f, this.center.y), |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 156 | duration = 100.milliseconds |
| 157 | ) |
| 158 | } |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 159 | advanceClockAndAwaitAnimation(controller, clocks) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 160 | |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 161 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 162 | assertThat(total).isEqualTo(lastTotal) |
| 163 | } |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 164 | onNodeWithTag(scrollableBoxTag).performGesture { |
| 165 | this.swipe( |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 166 | start = this.center, |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 167 | end = Offset(this.center.x, this.center.y - 100f), |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 168 | duration = 100.milliseconds |
| 169 | ) |
| 170 | } |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 171 | advanceClockAndAwaitAnimation(controller, clocks) |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 172 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 173 | assertThat(total).isLessThan(0.01f) |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | @Test |
| 178 | fun scrollable_startStop_notify() { |
| 179 | var startTrigger = 0f |
| 180 | var stopTrigger = 0f |
| 181 | val clocks = ManualAnimationClock(0L) |
| 182 | var total = 0f |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 183 | val controller = ScrollableController( |
| 184 | consumeScrollDelta = { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 185 | total += it |
| 186 | it |
| 187 | }, |
| 188 | flingConfig = FlingConfig(decayAnimation = ExponentialDecay()), |
| 189 | animationClock = clocks |
| 190 | ) |
| 191 | setScrollableContent { |
Matvei Malkov | 4a945c3 | 2020-03-27 16:27:23 +0000 | [diff] [blame] | 192 | Modifier.scrollable( |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 193 | controller = controller, |
| 194 | orientation = Orientation.Horizontal, |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 195 | onScrollStarted = { startTrigger++ }, |
| 196 | onScrollStopped = { stopTrigger++ } |
| 197 | ) |
| 198 | } |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 199 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 200 | assertThat(startTrigger).isEqualTo(0) |
| 201 | assertThat(stopTrigger).isEqualTo(0) |
| 202 | } |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 203 | onNodeWithTag(scrollableBoxTag).performGesture { |
| 204 | this.swipe( |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 205 | start = this.center, |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 206 | end = Offset(this.center.x + 100f, this.center.y), |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 207 | duration = 100.milliseconds |
| 208 | ) |
| 209 | } |
| 210 | // don't wait for animation so stop is 0, as we flinging still |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 211 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 212 | assertThat(startTrigger).isEqualTo(1) |
| 213 | assertThat(stopTrigger).isEqualTo(0) |
| 214 | } |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 215 | advanceClockAndAwaitAnimation(controller, clocks) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 216 | // after wait we expect stop to trigger |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 217 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 218 | assertThat(startTrigger).isEqualTo(1) |
| 219 | assertThat(stopTrigger).isEqualTo(1) |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | @Test |
| 224 | fun scrollable_disabledWontCallLambda() { |
| 225 | var enabled = mutableStateOf(true) |
| 226 | val clocks = ManualAnimationClock(0L) |
| 227 | var total = 0f |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 228 | val controller = ScrollableController( |
| 229 | consumeScrollDelta = { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 230 | total += it |
| 231 | it |
| 232 | }, |
| 233 | flingConfig = FlingConfig(decayAnimation = ExponentialDecay()), |
| 234 | animationClock = clocks |
| 235 | ) |
| 236 | setScrollableContent { |
Matvei Malkov | 4a945c3 | 2020-03-27 16:27:23 +0000 | [diff] [blame] | 237 | Modifier.scrollable( |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 238 | controller = controller, |
| 239 | orientation = Orientation.Horizontal, |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 240 | enabled = enabled.value |
| 241 | ) |
| 242 | } |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 243 | onNodeWithTag(scrollableBoxTag).performGesture { |
| 244 | this.swipe( |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 245 | start = this.center, |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 246 | end = Offset(this.center.x + 100f, this.center.y), |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 247 | duration = 100.milliseconds |
| 248 | ) |
| 249 | } |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 250 | advanceClockAndAwaitAnimation(controller, clocks) |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 251 | val prevTotal = runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 252 | assertThat(total).isGreaterThan(0f) |
| 253 | enabled.value = false |
| 254 | total |
| 255 | } |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 256 | onNodeWithTag(scrollableBoxTag).performGesture { |
| 257 | this.swipe( |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 258 | start = this.center, |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 259 | end = Offset(this.center.x + 100f, this.center.y), |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 260 | duration = 100.milliseconds |
| 261 | ) |
| 262 | } |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 263 | advanceClockAndAwaitAnimation(controller, clocks) |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 264 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 265 | assertThat(total).isEqualTo(prevTotal) |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | @Test |
| 270 | fun scrollable_velocityProxy() { |
| 271 | var velocityTriggered = 0f |
| 272 | val clocks = ManualAnimationClock(0L) |
| 273 | var total = 0f |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 274 | val controller = ScrollableController( |
| 275 | consumeScrollDelta = { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 276 | total += it |
| 277 | it |
| 278 | }, |
| 279 | flingConfig = FlingConfig(decayAnimation = ExponentialDecay()), |
| 280 | animationClock = clocks |
| 281 | ) |
| 282 | setScrollableContent { |
Matvei Malkov | 4a945c3 | 2020-03-27 16:27:23 +0000 | [diff] [blame] | 283 | Modifier.scrollable( |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 284 | controller = controller, |
| 285 | orientation = Orientation.Horizontal, |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 286 | onScrollStopped = { velocity -> |
| 287 | velocityTriggered = velocity |
| 288 | } |
| 289 | ) |
| 290 | } |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 291 | onNodeWithTag(scrollableBoxTag).performGesture { |
| 292 | this.swipeWithVelocity( |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 293 | start = this.center, |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 294 | end = Offset(this.center.x + 100f, this.center.y), |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 295 | endVelocity = 112f, |
| 296 | duration = 100.milliseconds |
| 297 | |
| 298 | ) |
| 299 | } |
| 300 | // don't advance clocks, so animation won't trigger yet |
| 301 | // and interrupt |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 302 | onNodeWithTag(scrollableBoxTag).performGesture { |
| 303 | this.swipeWithVelocity( |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 304 | start = this.center, |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 305 | end = Offset(this.center.x - 100f, this.center.y), |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 306 | endVelocity = 312f, |
| 307 | duration = 100.milliseconds |
| 308 | |
| 309 | ) |
| 310 | } |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 311 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 312 | // should be first velocity, as fling was disrupted |
| 313 | assertThat(velocityTriggered - 112f).isLessThan(0.1f) |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | @Test |
| 318 | fun scrollable_startWithoutSlop_ifFlinging() { |
| 319 | val clocks = ManualAnimationClock(0L) |
| 320 | var total = 0f |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 321 | val controller = ScrollableController( |
| 322 | consumeScrollDelta = { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 323 | total += it |
| 324 | it |
| 325 | }, |
| 326 | flingConfig = FlingConfig(decayAnimation = ExponentialDecay()), |
| 327 | animationClock = clocks |
| 328 | ) |
| 329 | setScrollableContent { |
Matvei Malkov | 4a945c3 | 2020-03-27 16:27:23 +0000 | [diff] [blame] | 330 | Modifier.scrollable( |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 331 | controller = controller, |
| 332 | orientation = Orientation.Horizontal |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 333 | ) |
| 334 | } |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 335 | onNodeWithTag(scrollableBoxTag).performGesture { |
| 336 | this.swipe( |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 337 | start = this.center, |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 338 | end = Offset(this.center.x + 100f, this.center.y), |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 339 | duration = 100.milliseconds |
| 340 | ) |
| 341 | } |
| 342 | // don't advance clocks |
Filip Pavlis | 6fdb250 | 2020-04-02 14:41:32 +0100 | [diff] [blame] | 343 | val prevTotal = runOnUiThread { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 344 | Truth.assertThat(total).isGreaterThan(0f) |
| 345 | total |
| 346 | } |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 347 | onNodeWithTag(scrollableBoxTag).performGesture { |
| 348 | this.swipe( |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 349 | start = this.center, |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 350 | end = Offset(this.center.x + 114f, this.center.y), |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 351 | duration = 100.milliseconds |
| 352 | ) |
| 353 | } |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 354 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 355 | // last swipe should add exactly 114 as we don't advance clocks and already flinging |
| 356 | val expected = prevTotal + 114 |
| 357 | assertThat(total - expected).isLessThan(0.1f) |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | @Test |
| 362 | fun scrollable_cancel_callsDragStop() { |
| 363 | var total by mutableStateOf(0f) |
| 364 | var dragStopped = 0f |
| 365 | val clocks = ManualAnimationClock(0L) |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 366 | val controller = ScrollableController( |
| 367 | consumeScrollDelta = { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 368 | total += it |
| 369 | it |
| 370 | }, |
| 371 | flingConfig = FlingConfig(decayAnimation = ExponentialDecay()), |
| 372 | animationClock = clocks |
| 373 | ) |
| 374 | setScrollableContent { |
| 375 | if (total < 20) { |
Matvei Malkov | 4a945c3 | 2020-03-27 16:27:23 +0000 | [diff] [blame] | 376 | Modifier.scrollable( |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 377 | controller = controller, |
| 378 | orientation = Orientation.Horizontal, |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 379 | onScrollStopped = { |
| 380 | dragStopped++ |
| 381 | } |
| 382 | ) |
| 383 | } else { |
Adam Powell | b6d8db2 | 2020-04-02 12:40:03 -0700 | [diff] [blame] | 384 | Modifier |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 385 | } |
| 386 | } |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 387 | onNodeWithTag(scrollableBoxTag).performGesture { |
| 388 | this.swipe( |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 389 | start = this.center, |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 390 | end = Offset(this.center.x + 100, this.center.y), |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 391 | duration = 100.milliseconds |
| 392 | ) |
| 393 | } |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 394 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 395 | assertThat(total).isGreaterThan(0f) |
| 396 | assertThat(dragStopped).isEqualTo(1f) |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | @Test |
| 401 | fun scrollable_snappingScrolling() { |
| 402 | var total = 0f |
| 403 | val clocks = ManualAnimationClock(0L) |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 404 | val controller = ScrollableController( |
| 405 | consumeScrollDelta = { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 406 | total += it |
| 407 | it |
| 408 | }, |
| 409 | flingConfig = FlingConfig(decayAnimation = ExponentialDecay()), |
| 410 | animationClock = clocks |
| 411 | ) |
| 412 | setScrollableContent { |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 413 | Modifier.scrollable(orientation = Orientation.Vertical, controller = controller) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 414 | } |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 415 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 416 | assertThat(total).isEqualTo(0f) |
| 417 | } |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 418 | runOnIdle { |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 419 | controller.smoothScrollBy(1000f) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 420 | } |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 421 | advanceClockAndAwaitAnimation(controller, clocks) |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 422 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 423 | assertThat(total).isEqualTo(1000f) |
| 424 | } |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 425 | runOnIdle { |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 426 | controller.smoothScrollBy(-200f) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 427 | } |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 428 | advanceClockAndAwaitAnimation(controller, clocks) |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 429 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 430 | assertThat(total).isEqualTo(800f) |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | @Test |
| 435 | fun scrollable_immediateDisposal() { |
| 436 | val disposed = mutableStateOf(false) |
| 437 | var total = 0f |
| 438 | val clocks = ManualAnimationClock(0L) |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 439 | val controller = ScrollableController( |
| 440 | consumeScrollDelta = { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 441 | Truth.assertWithMessage("Animating after dispose!").that(disposed.value).isFalse() |
| 442 | total += it |
| 443 | it |
| 444 | }, |
| 445 | flingConfig = FlingConfig(decayAnimation = ExponentialDecay()), |
| 446 | animationClock = clocks |
| 447 | ) |
| 448 | setScrollableContent { |
| 449 | if (!disposed.value) { |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 450 | Modifier.scrollable(orientation = Orientation.Vertical, controller = controller) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 451 | } else { |
Adam Powell | b6d8db2 | 2020-04-02 12:40:03 -0700 | [diff] [blame] | 452 | Modifier |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 453 | } |
| 454 | } |
Filip Pavlis | 6fdb250 | 2020-04-02 14:41:32 +0100 | [diff] [blame] | 455 | runOnUiThread { |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 456 | controller.smoothScrollBy(1000f) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 457 | disposed.value = true |
| 458 | } |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 459 | advanceClockAndAwaitAnimation(controller, clocks) |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 460 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 461 | assertThat(total).isEqualTo(0f) |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | @Test |
| 466 | fun scrollable_explicitDisposal() { |
| 467 | val disposed = mutableStateOf(false) |
| 468 | var total = 0f |
| 469 | val clocks = ManualAnimationClock(0L) |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 470 | val controller = ScrollableController( |
| 471 | consumeScrollDelta = { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 472 | Truth.assertWithMessage("Animating after dispose!").that(disposed.value).isFalse() |
| 473 | total += it |
| 474 | it |
| 475 | }, |
| 476 | flingConfig = FlingConfig(decayAnimation = ExponentialDecay()), |
| 477 | animationClock = clocks |
| 478 | ) |
| 479 | setScrollableContent { |
| 480 | if (!disposed.value) { |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 481 | Modifier.scrollable(orientation = Orientation.Vertical, controller = controller) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 482 | } else { |
Adam Powell | b6d8db2 | 2020-04-02 12:40:03 -0700 | [diff] [blame] | 483 | Modifier |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 484 | } |
| 485 | } |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 486 | runOnIdle { |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 487 | controller.smoothScrollBy(300f) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 488 | } |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 489 | advanceClockAndAwaitAnimation(controller, clocks) |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 490 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 491 | assertThat(total).isEqualTo(300f) |
| 492 | } |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 493 | runOnIdle { |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 494 | controller.smoothScrollBy(200f) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 495 | } |
| 496 | // don't advance clocks yet, toggle disposed value |
Filip Pavlis | 6fdb250 | 2020-04-02 14:41:32 +0100 | [diff] [blame] | 497 | runOnUiThread { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 498 | disposed.value = true |
| 499 | } |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 500 | advanceClockAndAwaitAnimation(controller, clocks) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 501 | // still 300 and didn't fail in onScrollConsumptionRequested.. lambda |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 502 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 503 | assertThat(total).isEqualTo(300f) |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | @Test |
| 508 | fun scrollable_nestedDrag() { |
| 509 | var innerDrag = 0f |
| 510 | var outerDrag = 0f |
| 511 | val clocks = ManualAnimationClock(0L) |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 512 | val outerState = ScrollableController( |
| 513 | consumeScrollDelta = { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 514 | outerDrag += it |
| 515 | it |
| 516 | }, |
| 517 | flingConfig = FlingConfig(decayAnimation = ExponentialDecay()), |
| 518 | animationClock = clocks |
| 519 | ) |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 520 | val innerState = ScrollableController( |
| 521 | consumeScrollDelta = { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 522 | innerDrag += it / 2 |
| 523 | it / 2 |
| 524 | }, |
| 525 | flingConfig = FlingConfig(decayAnimation = ExponentialDecay()), |
| 526 | animationClock = clocks |
| 527 | ) |
| 528 | |
| 529 | composeTestRule.setContent { |
| 530 | Stack { |
Filip Pavlis | 6de64f5 | 2020-05-27 18:11:55 +0100 | [diff] [blame] | 531 | Box( |
| 532 | gravity = ContentGravity.Center, |
| 533 | modifier = Modifier |
Filip Pavlis | 6de64f5 | 2020-05-27 18:11:55 +0100 | [diff] [blame] | 534 | .testTag(scrollableBoxTag) |
| 535 | .preferredSize(300.dp) |
| 536 | .scrollable( |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 537 | controller = outerState, |
| 538 | orientation = Orientation.Horizontal |
Filip Pavlis | 6de64f5 | 2020-05-27 18:11:55 +0100 | [diff] [blame] | 539 | ) |
| 540 | ) { |
| 541 | Box( |
| 542 | modifier = Modifier.preferredSize(300.dp).scrollable( |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 543 | controller = innerState, |
| 544 | orientation = Orientation.Horizontal |
Filip Pavlis | 6de64f5 | 2020-05-27 18:11:55 +0100 | [diff] [blame] | 545 | ) |
| 546 | ) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | } |
Filip Pavlis | 659ea72 | 2020-07-13 14:14:32 +0100 | [diff] [blame] | 550 | onNodeWithTag(scrollableBoxTag).performGesture { |
| 551 | this.swipe( |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 552 | start = this.center, |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 553 | end = Offset(this.center.x + 200f, this.center.y), |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 554 | duration = 300.milliseconds |
| 555 | ) |
| 556 | } |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 557 | val lastEqualDrag = runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 558 | assertThat(innerDrag).isGreaterThan(0f) |
| 559 | assertThat(outerDrag).isGreaterThan(0f) |
| 560 | // we consumed half delta in child, so exactly half should go to the parent |
| 561 | assertThat(outerDrag).isEqualTo(innerDrag) |
| 562 | innerDrag |
| 563 | } |
| 564 | advanceClockAndAwaitAnimation(innerState, clocks) |
| 565 | advanceClockAndAwaitAnimation(outerState, clocks) |
| 566 | // and nothing should change as we don't do nested fling |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 567 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 568 | assertThat(outerDrag).isEqualTo(lastEqualDrag) |
| 569 | } |
| 570 | } |
| 571 | |
Louis Pullen-Freilich | 3a54b94 | 2020-05-07 13:23:03 +0100 | [diff] [blame] | 572 | private fun setScrollableContent(scrollableModifierFactory: @Composable () -> Modifier) { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 573 | composeTestRule.setContent { |
| 574 | Stack { |
| 575 | val scrollable = scrollableModifierFactory() |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 576 | Box( |
| 577 | modifier = Modifier |
| 578 | .testTag(scrollableBoxTag) |
| 579 | .preferredSize(100.dp) + |
| 580 | scrollable |
Filip Pavlis | 6de64f5 | 2020-05-27 18:11:55 +0100 | [diff] [blame] | 581 | ) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 582 | } |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | // TODO(b/147291885): This should not be needed in the future. |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 587 | private fun awaitScrollAnimation(controller: ScrollableController) { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 588 | val latch = CountDownLatch(1) |
| 589 | val handler = Handler(Looper.getMainLooper()) |
| 590 | handler.post(object : Runnable { |
| 591 | override fun run() { |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 592 | if (controller.isAnimationRunning) { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 593 | handler.post(this) |
| 594 | } else { |
| 595 | latch.countDown() |
| 596 | } |
| 597 | } |
| 598 | }) |
| 599 | Truth.assertWithMessage("Scroll didn't finish after 20 seconds") |
| 600 | .that(latch.await(20, TimeUnit.SECONDS)).isTrue() |
| 601 | } |
| 602 | |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 603 | private fun advanceClockAndAwaitAnimation( |
| 604 | controller: ScrollableController, |
| 605 | clock: ManualAnimationClock |
| 606 | ) { |
Filip Pavlis | a4d73a5 | 2020-07-14 11:30:00 +0100 | [diff] [blame] | 607 | runOnIdle { |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 608 | clock.clockTimeMillis += 5000 |
| 609 | } |
Matvei Malkov | 710fb4f | 2020-07-03 15:53:10 +0100 | [diff] [blame] | 610 | awaitScrollAnimation(controller) |
Matvei Malkov | 59fa63f | 2020-03-24 17:15:50 +0000 | [diff] [blame] | 611 | } |
| 612 | } |