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.node 18 19 import androidx.compose.ui.layout.IntrinsicMeasureScope 20 import androidx.compose.ui.layout.Measurable 21 import androidx.compose.ui.layout.MeasureScope 22 import androidx.compose.ui.node.LayoutNode.LayoutState 23 import androidx.compose.ui.util.fastMap 24 25 internal interface MeasureScopeWithLayoutNode : MeasureScope { 26 val layoutNode: LayoutNode 27 } 28 getChildrenOfVirtualChildrennull29internal fun getChildrenOfVirtualChildren(scope: IntrinsicMeasureScope): List<List<Measurable>> { 30 val layoutNode = (scope as MeasureScopeWithLayoutNode).layoutNode 31 val lookahead = layoutNode.isInLookaheadPass() 32 return layoutNode.foldedChildren.fastMap { 33 if (lookahead) it.childLookaheadMeasurables else it.childMeasurables 34 } 35 } 36 LayoutNodenull37private fun LayoutNode.isInLookaheadPass(): Boolean { 38 return when (layoutState) { 39 LayoutState.LookaheadMeasuring, 40 LayoutState.LookaheadLayingOut -> true 41 LayoutState.Measuring, 42 LayoutState.LayingOut -> false 43 LayoutState.Idle -> { 44 // idle means intrinsics are being asked, we need to check the parent 45 requireNotNull(parent) { "no parent for idle node" }.isInLookaheadPass() 46 } 47 } 48 } 49