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.ui.test 18 19 /** 20 * The receiver scope of rotary input injection lambda from [performRotaryScrollInput]. 21 * 22 * A rotary event can be sent with [rotateToScrollVertically] or [rotateToScrollHorizontally]. All 23 * events sent by these methods are batched together and sent as a whole after 24 * [performRotaryScrollInput] has executed its code block. 25 * 26 * Example of performing a scroll with three events: 27 * 28 * @sample androidx.compose.ui.test.samples.rotaryInputScroll 29 */ 30 @ExperimentalTestApi 31 interface RotaryInjectionScope : InjectionScope { 32 /** 33 * Sends a scroll event that represents a rotation that will result in a scroll distance of 34 * [horizontalScrollPixels]. The event will be sent at the current event time. Positive 35 * [horizontalScrollPixels] values will correspond to rotating the scroll wheel clockwise, 36 * negative values correspond to rotating the scroll wheel anticlockwise. 37 * 38 * @param horizontalScrollPixels The amount of scroll, in pixels 39 */ rotateToScrollHorizontallynull40 fun rotateToScrollHorizontally(horizontalScrollPixels: Float) 41 42 /** 43 * Sends a scroll event that represents a rotation that will result in a scroll distance of 44 * [verticalScrollPixels]. The event will be sent at the current event time. Positive 45 * [verticalScrollPixels] values will correspond to rotating the scroll wheel clockwise, 46 * negative values correspond to rotating the scroll wheel anticlockwise. 47 * 48 * @param verticalScrollPixels The amount of scroll, in pixels 49 */ 50 fun rotateToScrollVertically(verticalScrollPixels: Float) 51 } 52 53 @ExperimentalTestApi 54 internal class RotaryInjectionScopeImpl(private val baseScope: MultiModalInjectionScopeImpl) : 55 RotaryInjectionScope, InjectionScope by baseScope { 56 private val inputDispatcher 57 get() = baseScope.inputDispatcher 58 59 override fun rotateToScrollHorizontally(horizontalScrollPixels: Float) { 60 inputDispatcher.enqueueRotaryScrollHorizontally(horizontalScrollPixels) 61 } 62 63 override fun rotateToScrollVertically(verticalScrollPixels: Float) { 64 inputDispatcher.enqueueRotaryScrollVertically(verticalScrollPixels) 65 } 66 } 67