Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +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 | |
| 17 | package androidx.ui.layout.test |
| 18 | |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 19 | import androidx.compose.Composable |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 20 | import androidx.compose.emptyContent |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 21 | import androidx.test.filters.SmallTest |
Mihai Popa | ca1c4b9 | 2019-10-03 19:16:06 +0100 | [diff] [blame] | 22 | import androidx.ui.core.Layout |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 23 | import androidx.ui.core.LayoutCoordinates |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 24 | import androidx.ui.core.Modifier |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 25 | import androidx.ui.core.Ref |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 26 | import androidx.ui.core.constrainHeight |
| 27 | import androidx.ui.core.constrainWidth |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 28 | import androidx.ui.core.onChildPositioned |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 29 | import androidx.ui.geometry.Offset |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 30 | import androidx.ui.layout.DpConstraints |
Mihai Popa | a22885d | 2020-05-26 18:31:21 +0100 | [diff] [blame] | 31 | import androidx.ui.layout.ExperimentalLayout |
Anastasia Soboleva | db73858 | 2020-03-27 16:06:33 +0000 | [diff] [blame] | 32 | import androidx.ui.layout.Stack |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 33 | import androidx.ui.layout.IntrinsicSize |
| 34 | import androidx.ui.layout.preferredHeight |
| 35 | import androidx.ui.layout.preferredWidth |
George Mount | 842c8c1 | 2020-01-08 16:03:42 -0800 | [diff] [blame] | 36 | import androidx.ui.unit.Dp |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 37 | import androidx.ui.unit.IntSize |
George Mount | 842c8c1 | 2020-01-08 16:03:42 -0800 | [diff] [blame] | 38 | import androidx.ui.unit.dp |
George Mount | 8baef7a | 2020-01-21 13:40:57 -0800 | [diff] [blame] | 39 | import org.junit.Assert.assertEquals |
Mihai Popa | 2554ba8 | 2020-03-13 19:03:52 +0000 | [diff] [blame] | 40 | import org.junit.Assert.assertTrue |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 41 | import org.junit.Test |
| 42 | import org.junit.runner.RunWith |
| 43 | import org.junit.runners.JUnit4 |
| 44 | import java.util.concurrent.CountDownLatch |
| 45 | import java.util.concurrent.TimeUnit |
| 46 | |
| 47 | @SmallTest |
| 48 | @RunWith(JUnit4::class) |
Mihai Popa | a22885d | 2020-05-26 18:31:21 +0100 | [diff] [blame] | 49 | @OptIn(ExperimentalLayout::class) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 50 | class IntrinsicTest : LayoutTest() { |
| 51 | @Test |
Andrey Kulikov | 47f0e1a | 2020-01-28 13:52:46 +0000 | [diff] [blame] | 52 | fun testMinIntrinsicWidth() = with(density) { |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 53 | val positionedLatch = CountDownLatch(2) |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 54 | val minIntrinsicWidthSize = Ref<IntSize>() |
| 55 | val childSize = Ref<IntSize>() |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 56 | val childPosition = Ref<Offset>() |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 57 | show { |
Anastasia Soboleva | db73858 | 2020-03-27 16:06:33 +0000 | [diff] [blame] | 58 | Stack(modifier = Modifier.onChildPositioned { coordinates: LayoutCoordinates -> |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 59 | minIntrinsicWidthSize.value = coordinates.size |
| 60 | positionedLatch.countDown() |
| 61 | } |
| 62 | ) { |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 63 | FixedIntrinsicsBox( |
| 64 | Modifier.preferredWidth(IntrinsicSize.Min).saveLayoutInfo( |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 65 | size = childSize, |
| 66 | position = childPosition, |
| 67 | positionedLatch = positionedLatch |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 68 | ), |
| 69 | 10.dp, 20.dp, 30.dp, 40.dp, 50.dp, 60.dp |
| 70 | ) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 71 | } |
| 72 | } |
Mihai Popa | 2554ba8 | 2020-03-13 19:03:52 +0000 | [diff] [blame] | 73 | assertTrue(positionedLatch.await(1, TimeUnit.SECONDS)) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 74 | |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 75 | assertEquals(IntSize(10.dp.toIntPx(), 50.dp.toIntPx()), minIntrinsicWidthSize.value) |
| 76 | assertEquals(IntSize(10.dp.toIntPx(), 50.dp.toIntPx()), childSize.value) |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 77 | assertEquals(Offset(0f, 0f), childPosition.value) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Test |
Andrey Kulikov | 47f0e1a | 2020-01-28 13:52:46 +0000 | [diff] [blame] | 81 | fun testMinIntrinsicHeight() = with(density) { |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 82 | val positionedLatch = CountDownLatch(2) |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 83 | val minIntrinsicHeightSize = Ref<IntSize>() |
| 84 | val childSize = Ref<IntSize>() |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 85 | val childPosition = Ref<Offset>() |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 86 | show { |
Anastasia Soboleva | db73858 | 2020-03-27 16:06:33 +0000 | [diff] [blame] | 87 | Stack(modifier = Modifier.onChildPositioned { coordinates: LayoutCoordinates -> |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 88 | minIntrinsicHeightSize.value = coordinates.size |
| 89 | positionedLatch.countDown() |
| 90 | } |
| 91 | ) { |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 92 | FixedIntrinsicsBox( |
| 93 | Modifier.preferredHeight(IntrinsicSize.Min).saveLayoutInfo( |
| 94 | size = childSize, |
| 95 | position = childPosition, |
| 96 | positionedLatch = positionedLatch |
| 97 | ), |
| 98 | 10.dp, 20.dp, 30.dp, 40.dp, 50.dp, 60.dp |
| 99 | ) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 100 | } |
| 101 | } |
Mihai Popa | 2554ba8 | 2020-03-13 19:03:52 +0000 | [diff] [blame] | 102 | assertTrue(positionedLatch.await(1, TimeUnit.SECONDS)) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 103 | |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 104 | assertEquals(IntSize(20.dp.toIntPx(), 40.dp.toIntPx()), minIntrinsicHeightSize.value) |
| 105 | assertEquals(IntSize(20.dp.toIntPx(), 40.dp.toIntPx()), childSize.value) |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 106 | assertEquals(Offset(0f, 0f), childPosition.value) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | @Test |
Andrey Kulikov | 47f0e1a | 2020-01-28 13:52:46 +0000 | [diff] [blame] | 110 | fun testMaxIntrinsicWidth() = with(density) { |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 111 | val positionedLatch = CountDownLatch(2) |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 112 | val maxIntrinsicWidthSize = Ref<IntSize>() |
| 113 | val childSize = Ref<IntSize>() |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 114 | val childPosition = Ref<Offset>() |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 115 | show { |
Anastasia Soboleva | db73858 | 2020-03-27 16:06:33 +0000 | [diff] [blame] | 116 | Stack(modifier = Modifier.onChildPositioned { coordinates: LayoutCoordinates -> |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 117 | maxIntrinsicWidthSize.value = coordinates.size |
| 118 | positionedLatch.countDown() |
| 119 | } |
| 120 | ) { |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 121 | FixedIntrinsicsBox( |
| 122 | Modifier.preferredWidth(IntrinsicSize.Max).saveLayoutInfo( |
| 123 | size = childSize, |
| 124 | position = childPosition, |
| 125 | positionedLatch = positionedLatch |
| 126 | ), |
| 127 | 10.dp, 20.dp, 30.dp, 40.dp, 50.dp, 60.dp |
| 128 | ) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 129 | } |
| 130 | } |
Mihai Popa | 2554ba8 | 2020-03-13 19:03:52 +0000 | [diff] [blame] | 131 | assertTrue(positionedLatch.await(1, TimeUnit.SECONDS)) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 132 | |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 133 | assertEquals(IntSize(30.dp.toIntPx(), 50.dp.toIntPx()), maxIntrinsicWidthSize.value) |
| 134 | assertEquals(IntSize(30.dp.toIntPx(), 50.dp.toIntPx()), childSize.value) |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 135 | assertEquals(Offset(0f, 0f), childPosition.value) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | @Test |
Andrey Kulikov | 47f0e1a | 2020-01-28 13:52:46 +0000 | [diff] [blame] | 139 | fun testMaxIntrinsicHeight() = with(density) { |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 140 | val positionedLatch = CountDownLatch(2) |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 141 | val maxIntrinsicHeightSize = Ref<IntSize>() |
| 142 | val childSize = Ref<IntSize>() |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 143 | val childPosition = Ref<Offset>() |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 144 | show { |
Anastasia Soboleva | db73858 | 2020-03-27 16:06:33 +0000 | [diff] [blame] | 145 | Stack(modifier = Modifier.onChildPositioned { coordinates: LayoutCoordinates -> |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 146 | maxIntrinsicHeightSize.value = coordinates.size |
| 147 | positionedLatch.countDown() |
| 148 | } |
| 149 | ) { |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 150 | FixedIntrinsicsBox( |
| 151 | Modifier.preferredHeight(IntrinsicSize.Max).saveLayoutInfo( |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 152 | size = childSize, |
| 153 | position = childPosition, |
| 154 | positionedLatch = positionedLatch |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 155 | ), |
| 156 | 10.dp, 20.dp, 30.dp, 40.dp, 50.dp, 60.dp |
| 157 | ) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 158 | } |
| 159 | } |
Mihai Popa | 2554ba8 | 2020-03-13 19:03:52 +0000 | [diff] [blame] | 160 | assertTrue(positionedLatch.await(1, TimeUnit.SECONDS)) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 161 | |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 162 | assertEquals(IntSize(20.dp.toIntPx(), 60.dp.toIntPx()), maxIntrinsicHeightSize.value) |
| 163 | assertEquals(IntSize(20.dp.toIntPx(), 60.dp.toIntPx()), childSize.value) |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 164 | assertEquals(Offset(0f, 0f), childPosition.value) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | @Test |
Andrey Kulikov | 47f0e1a | 2020-01-28 13:52:46 +0000 | [diff] [blame] | 168 | fun testMinIntrinsicWidth_respectsIncomingMaxConstraints() = with(density) { |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 169 | val positionedLatch = CountDownLatch(2) |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 170 | val minIntrinsicWidthSize = Ref<IntSize>() |
| 171 | val childSize = Ref<IntSize>() |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 172 | val childPosition = Ref<Offset>() |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 173 | show { |
Anastasia Soboleva | db73858 | 2020-03-27 16:06:33 +0000 | [diff] [blame] | 174 | Stack { |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 175 | ConstrainedBox( |
| 176 | DpConstraints(maxWidth = 5.dp), |
| 177 | modifier = Modifier.onChildPositioned { coordinates: LayoutCoordinates -> |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 178 | minIntrinsicWidthSize.value = coordinates.size |
| 179 | positionedLatch.countDown() |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 180 | } |
| 181 | ) { |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 182 | FixedIntrinsicsBox( |
| 183 | Modifier.preferredWidth(IntrinsicSize.Min).saveLayoutInfo( |
| 184 | size = childSize, |
| 185 | position = childPosition, |
| 186 | positionedLatch = positionedLatch |
| 187 | ), |
| 188 | 10.dp, 20.dp, 30.dp, 40.dp, 50.dp, 60.dp |
| 189 | ) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | } |
Mihai Popa | 2554ba8 | 2020-03-13 19:03:52 +0000 | [diff] [blame] | 193 | assertTrue(positionedLatch.await(1, TimeUnit.SECONDS)) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 194 | |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 195 | assertEquals(IntSize(5.dp.toIntPx(), 50.dp.toIntPx()), minIntrinsicWidthSize.value) |
| 196 | assertEquals(IntSize(5.dp.toIntPx(), 50.dp.toIntPx()), childSize.value) |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 197 | assertEquals(Offset(0f, 0f), childPosition.value) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | @Test |
Andrey Kulikov | 47f0e1a | 2020-01-28 13:52:46 +0000 | [diff] [blame] | 201 | fun testMinIntrinsicWidth_respectsIncomingMinConstraints() = with(density) { |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 202 | val positionedLatch = CountDownLatch(2) |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 203 | val minIntrinsicWidthSize = Ref<IntSize>() |
| 204 | val childSize = Ref<IntSize>() |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 205 | val childPosition = Ref<Offset>() |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 206 | show { |
Anastasia Soboleva | db73858 | 2020-03-27 16:06:33 +0000 | [diff] [blame] | 207 | Stack { |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 208 | ConstrainedBox( |
| 209 | DpConstraints(minWidth = 15.dp), |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 210 | modifier = Modifier.onChildPositioned { coordinates: LayoutCoordinates -> |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 211 | minIntrinsicWidthSize.value = coordinates.size |
| 212 | positionedLatch.countDown() |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 213 | } |
| 214 | ) { |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 215 | FixedIntrinsicsBox( |
| 216 | Modifier.preferredWidth(IntrinsicSize.Min).saveLayoutInfo( |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 217 | size = childSize, |
| 218 | position = childPosition, |
| 219 | positionedLatch = positionedLatch |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 220 | ), |
| 221 | 10.dp, 20.dp, 30.dp, 40.dp, 50.dp, 60.dp |
| 222 | ) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | } |
Mihai Popa | 2554ba8 | 2020-03-13 19:03:52 +0000 | [diff] [blame] | 226 | assertTrue(positionedLatch.await(1, TimeUnit.SECONDS)) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 227 | |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 228 | assertEquals(IntSize(15.dp.toIntPx(), 50.dp.toIntPx()), minIntrinsicWidthSize.value) |
| 229 | assertEquals(IntSize(15.dp.toIntPx(), 50.dp.toIntPx()), childSize.value) |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 230 | assertEquals(Offset(0f, 0f), childPosition.value) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | @Test |
Andrey Kulikov | 47f0e1a | 2020-01-28 13:52:46 +0000 | [diff] [blame] | 234 | fun testMinIntrinsicHeight_respectsMaxIncomingConstraints() = with(density) { |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 235 | val positionedLatch = CountDownLatch(2) |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 236 | val minIntrinsicHeightSize = Ref<IntSize>() |
| 237 | val childSize = Ref<IntSize>() |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 238 | val childPosition = Ref<Offset>() |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 239 | show { |
Anastasia Soboleva | db73858 | 2020-03-27 16:06:33 +0000 | [diff] [blame] | 240 | Stack(modifier = Modifier.onChildPositioned { coordinates: LayoutCoordinates -> |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 241 | minIntrinsicHeightSize.value = coordinates.size |
| 242 | positionedLatch.countDown() |
| 243 | } |
| 244 | ) { |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 245 | ConstrainedBox(DpConstraints(maxHeight = 35.dp)) { |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 246 | FixedIntrinsicsBox( |
| 247 | Modifier.preferredHeight(IntrinsicSize.Min).saveLayoutInfo( |
| 248 | size = childSize, |
| 249 | position = childPosition, |
| 250 | positionedLatch = positionedLatch |
| 251 | ), |
| 252 | 10.dp, 20.dp, 30.dp, 40.dp, 50.dp, 60.dp |
| 253 | ) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | } |
Mihai Popa | 2554ba8 | 2020-03-13 19:03:52 +0000 | [diff] [blame] | 257 | assertTrue(positionedLatch.await(1, TimeUnit.SECONDS)) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 258 | |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 259 | assertEquals(IntSize(20.dp.toIntPx(), 35.dp.toIntPx()), minIntrinsicHeightSize.value) |
| 260 | assertEquals(IntSize(20.dp.toIntPx(), 35.dp.toIntPx()), childSize.value) |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 261 | assertEquals(Offset(0f, 0f), childPosition.value) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | @Test |
Andrey Kulikov | 47f0e1a | 2020-01-28 13:52:46 +0000 | [diff] [blame] | 265 | fun testMinIntrinsicHeight_respectsMinIncomingConstraints() = with(density) { |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 266 | val positionedLatch = CountDownLatch(2) |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 267 | val minIntrinsicHeightSize = Ref<IntSize>() |
| 268 | val childSize = Ref<IntSize>() |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 269 | val childPosition = Ref<Offset>() |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 270 | show { |
Anastasia Soboleva | db73858 | 2020-03-27 16:06:33 +0000 | [diff] [blame] | 271 | Stack(modifier = Modifier.onChildPositioned { coordinates: LayoutCoordinates -> |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 272 | minIntrinsicHeightSize.value = coordinates.size |
| 273 | positionedLatch.countDown() |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 274 | } |
| 275 | ) { |
| 276 | ConstrainedBox(DpConstraints(minHeight = 45.dp)) { |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 277 | FixedIntrinsicsBox( |
| 278 | Modifier.preferredHeight(IntrinsicSize.Min).saveLayoutInfo( |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 279 | size = childSize, |
| 280 | position = childPosition, |
| 281 | positionedLatch = positionedLatch |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 282 | ), |
| 283 | 10.dp, 20.dp, 30.dp, 40.dp, 50.dp, 60.dp |
| 284 | ) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | } |
Mihai Popa | 2554ba8 | 2020-03-13 19:03:52 +0000 | [diff] [blame] | 288 | assertTrue(positionedLatch.await(1, TimeUnit.SECONDS)) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 289 | |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 290 | assertEquals(IntSize(20.dp.toIntPx(), 45.dp.toIntPx()), minIntrinsicHeightSize.value) |
| 291 | assertEquals(IntSize(20.dp.toIntPx(), 45.dp.toIntPx()), childSize.value) |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 292 | assertEquals(Offset(0f, 0f), childPosition.value) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | @Test |
Andrey Kulikov | 47f0e1a | 2020-01-28 13:52:46 +0000 | [diff] [blame] | 296 | fun testMaxIntrinsicWidth_respectsMaxIncomingConstraints() = with(density) { |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 297 | val positionedLatch = CountDownLatch(2) |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 298 | val maxIntrinsicWidthSize = Ref<IntSize>() |
| 299 | val childSize = Ref<IntSize>() |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 300 | val childPosition = Ref<Offset>() |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 301 | show { |
Anastasia Soboleva | db73858 | 2020-03-27 16:06:33 +0000 | [diff] [blame] | 302 | Stack(modifier = Modifier.onChildPositioned { coordinates: LayoutCoordinates -> |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 303 | maxIntrinsicWidthSize.value = coordinates.size |
| 304 | positionedLatch.countDown() |
| 305 | } |
| 306 | ) { |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 307 | ConstrainedBox(DpConstraints(maxWidth = 25.dp)) { |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 308 | FixedIntrinsicsBox( |
| 309 | Modifier.preferredWidth(IntrinsicSize.Max).saveLayoutInfo( |
| 310 | size = childSize, |
| 311 | position = childPosition, |
| 312 | positionedLatch = positionedLatch |
| 313 | ), |
| 314 | 10.dp, 20.dp, 30.dp, 40.dp, 50.dp, 60.dp |
| 315 | ) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | } |
Mihai Popa | 2554ba8 | 2020-03-13 19:03:52 +0000 | [diff] [blame] | 319 | assertTrue(positionedLatch.await(1, TimeUnit.SECONDS)) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 320 | |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 321 | assertEquals(IntSize(25.dp.toIntPx(), 50.dp.toIntPx()), maxIntrinsicWidthSize.value) |
| 322 | assertEquals(IntSize(25.dp.toIntPx(), 50.dp.toIntPx()), childSize.value) |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 323 | assertEquals(Offset(0f, 0f), childPosition.value) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | @Test |
Andrey Kulikov | 47f0e1a | 2020-01-28 13:52:46 +0000 | [diff] [blame] | 327 | fun testMaxIntrinsicWidth_respectsMinIncomingConstraints() = with(density) { |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 328 | val positionedLatch = CountDownLatch(2) |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 329 | val maxIntrinsicWidthSize = Ref<IntSize>() |
| 330 | val childSize = Ref<IntSize>() |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 331 | val childPosition = Ref<Offset>() |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 332 | show { |
Anastasia Soboleva | db73858 | 2020-03-27 16:06:33 +0000 | [diff] [blame] | 333 | Stack(modifier = Modifier.onChildPositioned { coordinates: LayoutCoordinates -> |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 334 | maxIntrinsicWidthSize.value = coordinates.size |
| 335 | positionedLatch.countDown() |
| 336 | } |
| 337 | ) { |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 338 | ConstrainedBox(DpConstraints(minWidth = 35.dp)) { |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 339 | FixedIntrinsicsBox( |
| 340 | Modifier.preferredWidth(IntrinsicSize.Max).saveLayoutInfo( |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 341 | size = childSize, |
| 342 | position = childPosition, |
| 343 | positionedLatch = positionedLatch |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 344 | ), |
| 345 | 10.dp, 20.dp, 30.dp, 40.dp, 50.dp, 60.dp |
| 346 | ) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | } |
Mihai Popa | 2554ba8 | 2020-03-13 19:03:52 +0000 | [diff] [blame] | 350 | assertTrue(positionedLatch.await(1, TimeUnit.SECONDS)) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 351 | |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 352 | assertEquals(IntSize(35.dp.toIntPx(), 50.dp.toIntPx()), maxIntrinsicWidthSize.value) |
| 353 | assertEquals(IntSize(35.dp.toIntPx(), 50.dp.toIntPx()), childSize.value) |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 354 | assertEquals(Offset(0f, 0f), childPosition.value) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | @Test |
Andrey Kulikov | 47f0e1a | 2020-01-28 13:52:46 +0000 | [diff] [blame] | 358 | fun testMaxIntrinsicHeight_respectsMaxIncomingConstraints() = with(density) { |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 359 | val positionedLatch = CountDownLatch(2) |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 360 | val maxIntrinsicHeightSize = Ref<IntSize>() |
| 361 | val childSize = Ref<IntSize>() |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 362 | val childPosition = Ref<Offset>() |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 363 | show { |
Anastasia Soboleva | db73858 | 2020-03-27 16:06:33 +0000 | [diff] [blame] | 364 | Stack(modifier = Modifier.onChildPositioned { coordinates: LayoutCoordinates -> |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 365 | maxIntrinsicHeightSize.value = coordinates.size |
| 366 | positionedLatch.countDown() |
| 367 | } |
| 368 | ) { |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 369 | ConstrainedBox(DpConstraints(maxHeight = 55.dp)) { |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 370 | FixedIntrinsicsBox( |
| 371 | Modifier.preferredHeight(IntrinsicSize.Max).saveLayoutInfo( |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 372 | size = childSize, |
| 373 | position = childPosition, |
| 374 | positionedLatch = positionedLatch |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 375 | ), |
| 376 | 10.dp, 20.dp, 30.dp, 40.dp, 50.dp, 60.dp |
| 377 | ) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | } |
Mihai Popa | 2554ba8 | 2020-03-13 19:03:52 +0000 | [diff] [blame] | 381 | assertTrue(positionedLatch.await(1, TimeUnit.SECONDS)) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 382 | |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 383 | assertEquals(IntSize(20.dp.toIntPx(), 55.dp.toIntPx()), maxIntrinsicHeightSize.value) |
| 384 | assertEquals(IntSize(20.dp.toIntPx(), 55.dp.toIntPx()), childSize.value) |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 385 | assertEquals(Offset(0f, 0f), childPosition.value) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | @Test |
Andrey Kulikov | 47f0e1a | 2020-01-28 13:52:46 +0000 | [diff] [blame] | 389 | fun testMaxIntrinsicHeight_respectsMinIncomingConstraints() = with(density) { |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 390 | val positionedLatch = CountDownLatch(2) |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 391 | val maxIntrinsicHeightSize = Ref<IntSize>() |
| 392 | val childSize = Ref<IntSize>() |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 393 | val childPosition = Ref<Offset>() |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 394 | show { |
Anastasia Soboleva | db73858 | 2020-03-27 16:06:33 +0000 | [diff] [blame] | 395 | Stack(modifier = Modifier.onChildPositioned { coordinates: LayoutCoordinates -> |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 396 | maxIntrinsicHeightSize.value = coordinates.size |
| 397 | positionedLatch.countDown() |
| 398 | } |
| 399 | ) { |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 400 | ConstrainedBox(DpConstraints(minHeight = 65.dp)) { |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 401 | FixedIntrinsicsBox( |
| 402 | Modifier.preferredHeight(IntrinsicSize.Max).saveLayoutInfo( |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 403 | size = childSize, |
| 404 | position = childPosition, |
| 405 | positionedLatch = positionedLatch |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 406 | ), |
| 407 | 10.dp, 20.dp, 30.dp, 40.dp, 50.dp, 60.dp |
| 408 | ) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | } |
Mihai Popa | 2554ba8 | 2020-03-13 19:03:52 +0000 | [diff] [blame] | 412 | assertTrue(positionedLatch.await(1, TimeUnit.SECONDS)) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 413 | |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 414 | assertEquals(IntSize(20.dp.toIntPx(), 65.dp.toIntPx()), maxIntrinsicHeightSize.value) |
| 415 | assertEquals(IntSize(20.dp.toIntPx(), 65.dp.toIntPx()), childSize.value) |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 416 | assertEquals(Offset(0f, 0f), childPosition.value) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | @Test |
Andrey Kulikov | 47f0e1a | 2020-01-28 13:52:46 +0000 | [diff] [blame] | 420 | fun testMinIntrinsicWidth_intrinsicMeasurements() = with(density) { |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 421 | testIntrinsics({ |
| 422 | FixedIntrinsicsBox( |
| 423 | Modifier.preferredWidth(IntrinsicSize.Min), 10.dp, 20.dp, 30.dp, 40.dp, 50.dp, 60.dp |
| 424 | ) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 425 | }) { minIntrinsicWidth, minIntrinsicHeight, maxIntrinsicWidth, maxIntrinsicHeight -> |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 426 | assertEquals(10.dp.toIntPx(), minIntrinsicWidth(0)) |
| 427 | assertEquals(40.dp.toIntPx(), minIntrinsicHeight(0)) |
| 428 | assertEquals(10.dp.toIntPx(), maxIntrinsicWidth(0)) |
| 429 | assertEquals(60.dp.toIntPx(), maxIntrinsicHeight(0)) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 430 | } |
| 431 | } |
| 432 | |
| 433 | @Test |
Andrey Kulikov | 47f0e1a | 2020-01-28 13:52:46 +0000 | [diff] [blame] | 434 | fun testMinIntrinsicHeight_intrinsicMeasurements() = with(density) { |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 435 | testIntrinsics({ |
| 436 | FixedIntrinsicsBox( |
| 437 | Modifier.preferredHeight(IntrinsicSize.Min), |
| 438 | 10.dp, 20.dp, 30.dp, 40.dp, 50.dp, 60.dp |
| 439 | ) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 440 | }) { minIntrinsicWidth, minIntrinsicHeight, maxIntrinsicWidth, maxIntrinsicHeight -> |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 441 | assertEquals(10.dp.toIntPx(), minIntrinsicWidth(0)) |
| 442 | assertEquals(40.dp.toIntPx(), minIntrinsicHeight(0)) |
| 443 | assertEquals(30.dp.toIntPx(), maxIntrinsicWidth(0)) |
| 444 | assertEquals(40.dp.toIntPx(), maxIntrinsicHeight(0)) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | |
| 448 | @Test |
Andrey Kulikov | 47f0e1a | 2020-01-28 13:52:46 +0000 | [diff] [blame] | 449 | fun testMaxIntrinsicWidth_intrinsicMeasurements() = with(density) { |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 450 | testIntrinsics({ |
| 451 | FixedIntrinsicsBox( |
| 452 | Modifier.preferredWidth(IntrinsicSize.Max), 10.dp, 20.dp, 30.dp, 40.dp, 50.dp, 60.dp |
| 453 | ) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 454 | }) { minIntrinsicWidth, minIntrinsicHeight, maxIntrinsicWidth, maxIntrinsicHeight -> |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 455 | assertEquals(30.dp.toIntPx(), minIntrinsicWidth(0)) |
| 456 | assertEquals(40.dp.toIntPx(), minIntrinsicHeight(0)) |
| 457 | assertEquals(30.dp.toIntPx(), maxIntrinsicWidth(0)) |
| 458 | assertEquals(60.dp.toIntPx(), maxIntrinsicHeight(0)) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
| 462 | @Test |
Andrey Kulikov | 47f0e1a | 2020-01-28 13:52:46 +0000 | [diff] [blame] | 463 | fun testMaxIntrinsicHeight_intrinsicMeasurements() = with(density) { |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 464 | testIntrinsics({ |
| 465 | FixedIntrinsicsBox( |
| 466 | Modifier.preferredHeight(IntrinsicSize.Max), |
| 467 | 10.dp, 20.dp, 30.dp, 40.dp, 50.dp, 60.dp |
| 468 | ) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 469 | }) { minIntrinsicWidth, minIntrinsicHeight, maxIntrinsicWidth, maxIntrinsicHeight -> |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 470 | assertEquals(10.dp.toIntPx(), minIntrinsicWidth(0)) |
| 471 | assertEquals(60.dp.toIntPx(), minIntrinsicHeight(0)) |
| 472 | assertEquals(30.dp.toIntPx(), maxIntrinsicWidth(0)) |
| 473 | assertEquals(60.dp.toIntPx(), maxIntrinsicHeight(0)) |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | @Composable |
| 479 | private fun FixedIntrinsicsBox( |
Adam Powell | b6d8db2 | 2020-04-02 12:40:03 -0700 | [diff] [blame] | 480 | modifier: Modifier = Modifier, |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 481 | minIntrinsicWidth: Dp, |
| 482 | width: Dp, |
| 483 | maxIntrinsicWidth: Dp, |
| 484 | minIntrinsicHeight: Dp, |
George Mount | ec81f52 | 2019-08-14 15:30:26 -0700 | [diff] [blame] | 485 | height: Dp, |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 486 | maxIntrinsicHeight: Dp |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 487 | ) { |
Mihai Popa | ca1c4b9 | 2019-10-03 19:16:06 +0100 | [diff] [blame] | 488 | Layout( |
Mihai Popa | 8b5b06b | 2020-03-27 14:34:39 +0000 | [diff] [blame] | 489 | emptyContent(), |
Anastasia Soboleva | 5e382dd | 2020-06-17 21:51:38 +0100 | [diff] [blame] | 490 | minIntrinsicWidthMeasureBlock = { _, _ -> minIntrinsicWidth.toIntPx() }, |
| 491 | minIntrinsicHeightMeasureBlock = { _, _ -> minIntrinsicHeight.toIntPx() }, |
| 492 | maxIntrinsicWidthMeasureBlock = { _, _ -> maxIntrinsicWidth.toIntPx() }, |
| 493 | maxIntrinsicHeightMeasureBlock = { _, _ -> maxIntrinsicHeight.toIntPx() }, |
George Mount | 5e1d3f1 | 2020-03-09 17:28:35 -0700 | [diff] [blame] | 494 | modifier = modifier |
Anastasia Soboleva | 5e382dd | 2020-06-17 21:51:38 +0100 | [diff] [blame] | 495 | ) { _, constraints -> |
Mihai Popa | ca1c4b9 | 2019-10-03 19:16:06 +0100 | [diff] [blame] | 496 | layout( |
George Mount | 8f23757 | 2020-04-30 12:08:30 -0700 | [diff] [blame] | 497 | constraints.constrainWidth(width.toIntPx()), |
| 498 | constraints.constrainHeight(height.toIntPx()) |
Mihai Popa | ca1c4b9 | 2019-10-03 19:16:06 +0100 | [diff] [blame] | 499 | ) {} |
Mihai Popa | 1257df2 | 2019-07-01 21:30:22 +0100 | [diff] [blame] | 500 | } |
| 501 | } |