[go: nahoru, domu]

blob: 7b25451b88e855fbbcc98fc62c1e286a70fdd8eb [file] [log] [blame]
Filip Pavlis20447902019-07-01 20:34:25 +01001/*
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 Pavlisc2b29a42020-01-03 16:06:29 +000017package androidx.ui.integration.test.foundation
Filip Pavlis20447902019-07-01 20:34:25 +010018
Filip Pavlisa5cde9d32019-08-28 17:57:39 +010019import androidx.compose.Composable
Leland Richardsonfcf76b32020-05-13 16:58:59 -070020import androidx.compose.mutableStateOf
Matvei Malkov75c42d02020-03-30 16:03:11 +010021import androidx.ui.core.Modifier
Louis Pullen-Freilichddda7be2020-07-17 18:28:12 +010022import androidx.compose.foundation.Box
23import androidx.compose.foundation.background
George Mount842c8c12020-01-08 16:03:42 -080024import androidx.ui.unit.dp
Louis Pullen-Freilich4dc4dac2020-07-22 14:39:14 +010025import androidx.compose.ui.graphics.Color
Louis Pullen-Freilich623e4052020-07-19 20:24:03 +010026import androidx.compose.foundation.layout.Column
Filip Pavlisd3f28c02019-07-16 20:42:05 +010027import androidx.ui.material.MaterialTheme
Filip Pavlisa45848b2019-07-05 15:26:08 +010028import androidx.ui.test.ComposeTestCase
Filip Pavlisc2b29a42020-01-03 16:06:29 +000029import androidx.ui.integration.test.ToggleableTestCase
Louis Pullen-Freilich623e4052020-07-19 20:24:03 +010030import androidx.compose.foundation.layout.preferredSize
Filip Pavlis20447902019-07-01 20:34:25 +010031
Filip Pavlis20447902019-07-01 20:34:25 +010032/**
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 Pavlisa45848b2019-07-05 15:26:08 +010035 *
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 Pavlis20447902019-07-01 20:34:25 +010038 */
Filip Pavlisa45848b2019-07-05 15:26:08 +010039class RectsInColumnSharedModelTestCase(
Filip Pavlis20447902019-07-01 20:34:25 +010040 private val amountOfRectangles: Int
Filip Pavlisa5cde9d32019-08-28 17:57:39 +010041) : ComposeTestCase, ToggleableTestCase {
Filip Pavlis20447902019-07-01 20:34:25 +010042
Leland Richardsonfcf76b32020-05-13 16:58:59 -070043 private val color = mutableStateOf(Color.Black)
Filip Pavlis20447902019-07-01 20:34:25 +010044
Filip Pavlisa5cde9d32019-08-28 17:57:39 +010045 @Composable
46 override fun emitContent() {
Filip Pavlis67182d12019-07-31 17:42:43 +010047 MaterialTheme {
48 Column {
49 repeat(amountOfRectangles) { i ->
50 if (i == 0) {
Matvei Malkovbf014c12020-07-09 17:40:10 +010051 Box(Modifier.preferredSize(100.dp, 50.dp).background(color = color.value))
Filip Pavlis67182d12019-07-31 17:42:43 +010052 } else {
Matvei Malkovbf014c12020-07-09 17:40:10 +010053 Box(Modifier.preferredSize(100.dp, 50.dp).background(color = Color.Green))
Filip Pavlis20447902019-07-01 20:34:25 +010054 }
55 }
56 }
Filip Pavlis67182d12019-07-31 17:42:43 +010057 }
Filip Pavlisa5cde9d32019-08-28 17:57:39 +010058 }
Filip Pavlis20447902019-07-01 20:34:25 +010059
Filip Pavlisc8932922019-07-15 20:42:13 +010060 override fun toggleState() {
Leland Richardsonfcf76b32020-05-13 16:58:59 -070061 if (color.value == Color.Magenta) {
62 color.value = Color.Blue
Filip Pavlis20447902019-07-01 20:34:25 +010063 } else {
Leland Richardsonfcf76b32020-05-13 16:58:59 -070064 color.value = Color.Magenta
Filip Pavlis20447902019-07-01 20:34:25 +010065 }
Filip Pavlis20447902019-07-01 20:34:25 +010066 }
67}