Filip Pavlis | 2044790 | 2019-07-01 20:34:25 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
Filip Pavlis | c2b29a4 | 2020-01-03 16:06:29 +0000 | [diff] [blame] | 17 | package androidx.ui.integration.test.foundation |
Filip Pavlis | 2044790 | 2019-07-01 20:34:25 +0100 | [diff] [blame] | 18 | |
Filip Pavlis | a5cde9d3 | 2019-08-28 17:57:39 +0100 | [diff] [blame] | 19 | import androidx.compose.Composable |
Leland Richardson | fcf76b3 | 2020-05-13 16:58:59 -0700 | [diff] [blame] | 20 | import androidx.compose.mutableStateOf |
Matvei Malkov | 75c42d0 | 2020-03-30 16:03:11 +0100 | [diff] [blame] | 21 | import androidx.ui.core.Modifier |
Louis Pullen-Freilich | ddda7be | 2020-07-17 18:28:12 +0100 | [diff] [blame] | 22 | import androidx.compose.foundation.Box |
| 23 | import androidx.compose.foundation.background |
George Mount | 842c8c1 | 2020-01-08 16:03:42 -0800 | [diff] [blame] | 24 | import androidx.ui.unit.dp |
Louis Pullen-Freilich | 4dc4dac | 2020-07-22 14:39:14 +0100 | [diff] [blame^] | 25 | import androidx.compose.ui.graphics.Color |
Louis Pullen-Freilich | 623e405 | 2020-07-19 20:24:03 +0100 | [diff] [blame] | 26 | import androidx.compose.foundation.layout.Column |
Filip Pavlis | d3f28c0 | 2019-07-16 20:42:05 +0100 | [diff] [blame] | 27 | import androidx.ui.material.MaterialTheme |
Filip Pavlis | a45848b | 2019-07-05 15:26:08 +0100 | [diff] [blame] | 28 | import androidx.ui.test.ComposeTestCase |
Filip Pavlis | c2b29a4 | 2020-01-03 16:06:29 +0000 | [diff] [blame] | 29 | import androidx.ui.integration.test.ToggleableTestCase |
Louis Pullen-Freilich | 623e405 | 2020-07-19 20:24:03 +0100 | [diff] [blame] | 30 | import androidx.compose.foundation.layout.preferredSize |
Filip Pavlis | 2044790 | 2019-07-01 20:34:25 +0100 | [diff] [blame] | 31 | |
Filip Pavlis | 2044790 | 2019-07-01 20:34:25 +0100 | [diff] [blame] | 32 | /** |
| 33 | * Test case that puts the given amount of rectangles into a column layout and makes changes by |
| 34 | * modifying the color used in the model. |
Filip Pavlis | a45848b | 2019-07-05 15:26:08 +0100 | [diff] [blame] | 35 | * |
| 36 | * Note: Rectangle are created in for loop that reference a single model. Currently it will happen |
| 37 | * that the whole loop has to be re-run when model changes. |
Filip Pavlis | 2044790 | 2019-07-01 20:34:25 +0100 | [diff] [blame] | 38 | */ |
Filip Pavlis | a45848b | 2019-07-05 15:26:08 +0100 | [diff] [blame] | 39 | class RectsInColumnSharedModelTestCase( |
Filip Pavlis | 2044790 | 2019-07-01 20:34:25 +0100 | [diff] [blame] | 40 | private val amountOfRectangles: Int |
Filip Pavlis | a5cde9d3 | 2019-08-28 17:57:39 +0100 | [diff] [blame] | 41 | ) : ComposeTestCase, ToggleableTestCase { |
Filip Pavlis | 2044790 | 2019-07-01 20:34:25 +0100 | [diff] [blame] | 42 | |
Leland Richardson | fcf76b3 | 2020-05-13 16:58:59 -0700 | [diff] [blame] | 43 | private val color = mutableStateOf(Color.Black) |
Filip Pavlis | 2044790 | 2019-07-01 20:34:25 +0100 | [diff] [blame] | 44 | |
Filip Pavlis | a5cde9d3 | 2019-08-28 17:57:39 +0100 | [diff] [blame] | 45 | @Composable |
| 46 | override fun emitContent() { |
Filip Pavlis | 67182d1 | 2019-07-31 17:42:43 +0100 | [diff] [blame] | 47 | MaterialTheme { |
| 48 | Column { |
| 49 | repeat(amountOfRectangles) { i -> |
| 50 | if (i == 0) { |
Matvei Malkov | bf014c1 | 2020-07-09 17:40:10 +0100 | [diff] [blame] | 51 | Box(Modifier.preferredSize(100.dp, 50.dp).background(color = color.value)) |
Filip Pavlis | 67182d1 | 2019-07-31 17:42:43 +0100 | [diff] [blame] | 52 | } else { |
Matvei Malkov | bf014c1 | 2020-07-09 17:40:10 +0100 | [diff] [blame] | 53 | Box(Modifier.preferredSize(100.dp, 50.dp).background(color = Color.Green)) |
Filip Pavlis | 2044790 | 2019-07-01 20:34:25 +0100 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | } |
Filip Pavlis | 67182d1 | 2019-07-31 17:42:43 +0100 | [diff] [blame] | 57 | } |
Filip Pavlis | a5cde9d3 | 2019-08-28 17:57:39 +0100 | [diff] [blame] | 58 | } |
Filip Pavlis | 2044790 | 2019-07-01 20:34:25 +0100 | [diff] [blame] | 59 | |
Filip Pavlis | c893292 | 2019-07-15 20:42:13 +0100 | [diff] [blame] | 60 | override fun toggleState() { |
Leland Richardson | fcf76b3 | 2020-05-13 16:58:59 -0700 | [diff] [blame] | 61 | if (color.value == Color.Magenta) { |
| 62 | color.value = Color.Blue |
Filip Pavlis | 2044790 | 2019-07-01 20:34:25 +0100 | [diff] [blame] | 63 | } else { |
Leland Richardson | fcf76b3 | 2020-05-13 16:58:59 -0700 | [diff] [blame] | 64 | color.value = Color.Magenta |
Filip Pavlis | 2044790 | 2019-07-01 20:34:25 +0100 | [diff] [blame] | 65 | } |
Filip Pavlis | 2044790 | 2019-07-01 20:34:25 +0100 | [diff] [blame] | 66 | } |
| 67 | } |