Merge "Update the internal impl naming from postLookahead to approach" into androidx-main
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyList.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyList.kt
index 81a09257..bc592cc 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyList.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyList.kt
@@ -199,7 +199,7 @@
{ containerConstraints ->
state.measurementScopeInvalidator.attachToScope()
// Tracks if the lookahead pass has occurred
- val hasLookaheadPassOccurred = state.hasLookaheadPassOccurred || isLookingAhead
+ val hasLookaheadOccurred = state.hasLookaheadOccurred || isLookingAhead
checkScrollableContainerConstraints(
containerConstraints,
if (isVertical) Orientation.Vertical else Orientation.Horizontal
@@ -340,7 +340,7 @@
)
val scrollToBeConsumed =
- if (isLookingAhead || !hasLookaheadPassOccurred) {
+ if (isLookingAhead || !hasLookaheadOccurred) {
state.scrollToBeConsumed
} else {
state.scrollDeltaBetweenPasses
@@ -367,9 +367,9 @@
itemAnimator = state.itemAnimator,
beyondBoundsItemCount = beyondBoundsItemCount,
pinnedItems = pinnedItems,
- hasLookaheadPassOccurred = hasLookaheadPassOccurred,
+ hasLookaheadOccurred = hasLookaheadOccurred,
isLookingAhead = isLookingAhead,
- postLookaheadLayoutInfo = state.postLookaheadLayoutInfo,
+ approachLayoutInfo = state.approachLayoutInfo,
coroutineScope = coroutineScope,
placementScopeInvalidator = state.placementScopeInvalidator,
graphicsContext = graphicsContext,
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyListMeasure.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyListMeasure.kt
index f69394e..b22bce8 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyListMeasure.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyListMeasure.kt
@@ -67,9 +67,9 @@
itemAnimator: LazyLayoutItemAnimator<LazyListMeasuredItem>,
beyondBoundsItemCount: Int,
pinnedItems: List<Int>,
- hasLookaheadPassOccurred: Boolean,
+ hasLookaheadOccurred: Boolean,
isLookingAhead: Boolean,
- postLookaheadLayoutInfo: LazyListLayoutInfo?,
+ approachLayoutInfo: LazyListLayoutInfo?,
coroutineScope: CoroutineScope,
placementScopeInvalidator: ObservableScopeInvalidator,
graphicsContext: GraphicsContext,
@@ -93,7 +93,7 @@
isVertical = isVertical,
laneCount = 1,
isLookingAhead = isLookingAhead,
- hasLookaheadOccurred = hasLookaheadPassOccurred,
+ hasLookaheadOccurred = hasLookaheadOccurred,
layoutMinOffset = 0,
layoutMaxOffset = 0,
coroutineScope = coroutineScope,
@@ -330,7 +330,7 @@
pinnedItems = pinnedItems,
consumedScroll = consumedScroll,
isLookingAhead = isLookingAhead,
- lastPostLookaheadLayoutInfo = postLookaheadLayoutInfo
+ lastApproachLayoutInfo = approachLayoutInfo
)
// Update maxCrossAxis with extra items
@@ -373,7 +373,7 @@
isVertical = isVertical,
laneCount = 1,
isLookingAhead = isLookingAhead,
- hasLookaheadOccurred = hasLookaheadPassOccurred,
+ hasLookaheadOccurred = hasLookaheadOccurred,
coroutineScope = coroutineScope,
layoutMinOffset = currentFirstItemScrollOffset,
layoutMaxOffset = currentMainAxisOffset,
@@ -468,7 +468,7 @@
pinnedItems: List<Int>,
consumedScroll: Float,
isLookingAhead: Boolean,
- lastPostLookaheadLayoutInfo: LazyListLayoutInfo?
+ lastApproachLayoutInfo: LazyListLayoutInfo?
): List<LazyListMeasuredItem> {
var list: MutableList<LazyListMeasuredItem>? = null
@@ -482,15 +482,14 @@
}
if (isLookingAhead) {
- // Check if there's any item that needs to be composed based on last postLookaheadLayoutInfo
+ // Check if there's any item that needs to be composed based on last approachLayoutInfo
if (
- lastPostLookaheadLayoutInfo != null &&
- lastPostLookaheadLayoutInfo.visibleItemsInfo.isNotEmpty()
+ lastApproachLayoutInfo != null && lastApproachLayoutInfo.visibleItemsInfo.isNotEmpty()
) {
// Find first item with index > end. Note that `visibleItemsInfo.last()` may not have
// the largest index as the last few items could be added to animate item placement.
val firstItem =
- lastPostLookaheadLayoutInfo.visibleItemsInfo.run {
+ lastApproachLayoutInfo.visibleItemsInfo.run {
var found: LazyListItemInfo? = null
for (i in size - 1 downTo 0) {
if (this[i].index > end && (i == 0 || this[i - 1].index <= end)) {
@@ -500,7 +499,7 @@
}
found
}
- val lastVisibleItem = lastPostLookaheadLayoutInfo.visibleItemsInfo.last()
+ val lastVisibleItem = lastApproachLayoutInfo.visibleItemsInfo.last()
if (firstItem != null) {
for (i in firstItem.index..min(lastVisibleItem.index, itemsCount - 1)) {
// Only add to the list items that are _not_ already in the list.
@@ -514,7 +513,7 @@
// Calculate the additional offset to subcompose based on what was shown in the
// previous post-loookahead pass and the scroll consumed.
val additionalOffset =
- lastPostLookaheadLayoutInfo.viewportEndOffset -
+ lastApproachLayoutInfo.viewportEndOffset -
lastVisibleItem.offset -
lastVisibleItem.size -
consumedScroll
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyListState.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyListState.kt
index 4713db4..d43a656 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyListState.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyListState.kt
@@ -144,10 +144,10 @@
firstVisibleItemScrollOffset: Int = 0
) : this(firstVisibleItemIndex, firstVisibleItemScrollOffset, LazyListPrefetchStrategy())
- internal var hasLookaheadPassOccurred: Boolean = false
+ internal var hasLookaheadOccurred: Boolean = false
private set
- internal var postLookaheadLayoutInfo: LazyListMeasureResult? = null
+ internal var approachLayoutInfo: LazyListMeasureResult? = null
private set
/** The holder class for the current scroll position. */
@@ -416,21 +416,21 @@
var scrolledLayoutInfo =
layoutInfoState.value.copyWithScrollDeltaWithoutRemeasure(
delta = intDelta,
- updateAnimations = !hasLookaheadPassOccurred
+ updateAnimations = !hasLookaheadOccurred
)
- if (scrolledLayoutInfo != null && this.postLookaheadLayoutInfo != null) {
+ if (scrolledLayoutInfo != null && this.approachLayoutInfo != null) {
// if we were able to scroll the lookahead layout info without remeasure, lets
- // try to do the same for post lookahead layout info (sometimes they diverge).
- val scrolledPostLookaheadLayoutInfo =
- postLookaheadLayoutInfo?.copyWithScrollDeltaWithoutRemeasure(
+ // try to do the same for approach layout info (sometimes they diverge).
+ val scrolledApproachLayoutInfo =
+ approachLayoutInfo?.copyWithScrollDeltaWithoutRemeasure(
delta = intDelta,
updateAnimations = true
)
- if (scrolledPostLookaheadLayoutInfo != null) {
+ if (scrolledApproachLayoutInfo != null) {
// we can apply scroll delta for both phases without remeasure
- postLookaheadLayoutInfo = scrolledPostLookaheadLayoutInfo
+ approachLayoutInfo = scrolledApproachLayoutInfo
} else {
- // we can't apply scroll delta for post lookahead, so we have to remeasure
+ // we can't apply scroll delta for approach, so we have to remeasure
scrolledLayoutInfo = null
}
}
@@ -438,7 +438,7 @@
if (scrolledLayoutInfo != null) {
applyMeasureResult(
result = scrolledLayoutInfo,
- isLookingAhead = hasLookaheadPassOccurred,
+ isLookingAhead = hasLookaheadOccurred,
visibleItemsStayedTheSame = true
)
// we don't need to remeasure, so we only trigger re-placement:
@@ -495,12 +495,12 @@
isLookingAhead: Boolean,
visibleItemsStayedTheSame: Boolean = false
) {
- if (!isLookingAhead && hasLookaheadPassOccurred) {
- // If there was already a lookahead pass, record this result as postLookahead result
- postLookaheadLayoutInfo = result
+ if (!isLookingAhead && hasLookaheadOccurred) {
+ // If there was already a lookahead pass, record this result as approach result
+ approachLayoutInfo = result
} else {
if (isLookingAhead) {
- hasLookaheadPassOccurred = true
+ hasLookaheadOccurred = true
}
canScrollBackward = result.canScrollBackward
@@ -518,7 +518,7 @@
}
if (isLookingAhead) {
- updateScrollDeltaForPostLookahead(
+ updateScrollDeltaForApproach(
result.scrollBackAmount,
result.density,
result.coroutineScope
@@ -535,7 +535,7 @@
AnimationState(Float.VectorConverter, 0f, 0f)
// Updates the scroll delta between lookahead & post-lookahead pass
- private fun updateScrollDeltaForPostLookahead(
+ private fun updateScrollDeltaForApproach(
delta: Float,
density: Density,
coroutineScope: CoroutineScope
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/SubcomposeLayout.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/SubcomposeLayout.kt
index 2edc023..b3f8d71 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/SubcomposeLayout.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/SubcomposeLayout.kt
@@ -408,23 +408,22 @@
}
private var currentIndex = 0
- private var currentPostLookaheadIndex = 0
+ private var currentApproachIndex = 0
private val nodeToNodeState = mutableScatterMapOf<LayoutNode, NodeState>()
// this map contains active slotIds (without precomposed or reusable nodes)
private val slotIdToNode = mutableScatterMapOf<Any?, LayoutNode>()
private val scope = Scope()
- private val postLookaheadMeasureScope = PostLookaheadMeasureScopeImpl()
+ private val approachMeasureScope = ApproachMeasureScopeImpl()
private val precomposeMap = mutableScatterMapOf<Any?, LayoutNode>()
private val reusableSlotIdsSet = SubcomposeSlotReusePolicy.SlotIdsSet()
// SlotHandles precomposed in the post-lookahead pass.
- private val postLookaheadPrecomposeSlotHandleMap =
- mutableScatterMapOf<Any?, PrecomposedSlotHandle>()
+ private val approachPrecomposeSlotHandleMap = mutableScatterMapOf<Any?, PrecomposedSlotHandle>()
// Slot ids _composed_ in post-lookahead. The valid slot ids are stored between 0 and
- // currentPostLookaheadIndex - 1, beyond index currentPostLookaheadIndex are obsolete ids.
- private val postLookaheadComposedSlotIds = mutableVectorOf<Any?>()
+ // currentApproachIndex - 1, beyond index currentApproachIndex are obsolete ids.
+ private val approachComposedSlotIds = mutableVectorOf<Any?>()
/**
* `root.foldedChildren` list consist of:
@@ -739,14 +738,14 @@
scope.fontScale = fontScale
if (!isLookingAhead && root.lookaheadRoot != null) {
// Approach pass
- currentPostLookaheadIndex = 0
- val result = postLookaheadMeasureScope.block(constraints)
- val indexAfterMeasure = currentPostLookaheadIndex
+ currentApproachIndex = 0
+ val result = approachMeasureScope.block(constraints)
+ val indexAfterMeasure = currentApproachIndex
return createMeasureResult(result) {
- currentPostLookaheadIndex = indexAfterMeasure
+ currentApproachIndex = indexAfterMeasure
result.placeChildren()
// dispose
- disposeUnusedSlotsInPostLookahead()
+ disposeUnusedSlotsInApproach()
}
} else {
// Lookahead pass, or the main pass if not in a lookahead scope.
@@ -763,10 +762,10 @@
}
}
- private fun disposeUnusedSlotsInPostLookahead() {
- postLookaheadPrecomposeSlotHandleMap.removeIf { slotId, handle ->
- val id = postLookaheadComposedSlotIds.indexOf(slotId)
- if (id < 0 || id >= currentPostLookaheadIndex) {
+ private fun disposeUnusedSlotsInApproach() {
+ approachPrecomposeSlotHandleMap.removeIf { slotId, handle ->
+ val id = approachComposedSlotIds.indexOf(slotId)
+ if (id < 0 || id >= currentApproachIndex) {
// Slot was not used in the latest pass of post-lookahead.
handle.dispose()
true
@@ -805,8 +804,8 @@
}
makeSureStateIsConsistent()
if (!slotIdToNode.containsKey(slotId)) {
- // Yield ownership of PrecomposedHandle from postLookahead to the caller of precompose
- postLookaheadPrecomposeSlotHandleMap.remove(slotId)
+ // Yield ownership of PrecomposedHandle from approach to the caller of precompose
+ approachPrecomposeSlotHandleMap.remove(slotId)
val node =
precomposeMap.getOrPut(slotId) {
val reusedNode = takeNodeFromReusables(slotId)
@@ -959,8 +958,7 @@
}
}
- private inner class PostLookaheadMeasureScopeImpl :
- SubcomposeMeasureScope, MeasureScope by scope {
+ private inner class ApproachMeasureScopeImpl : SubcomposeMeasureScope, MeasureScope by scope {
/**
* This function retrieves [Measurable]s created for [slotId] based on the subcomposition
* that happened in the lookahead pass. If [slotId] was not subcomposed in the lookahead
@@ -970,31 +968,31 @@
val nodeInSlot = slotIdToNode[slotId]
if (nodeInSlot != null && root.foldedChildren.indexOf(nodeInSlot) < currentIndex) {
// Check that the node has been composed in lookahead. Otherwise, we need to
- // compose the node in approach pass via postLookaheadSubcompose.
+ // compose the node in approach pass via approachSubcompose.
return nodeInSlot.childMeasurables
} else {
- return postLookaheadSubcompose(slotId, content)
+ return approachSubcompose(slotId, content)
}
}
}
- private fun postLookaheadSubcompose(
+ private fun approachSubcompose(
slotId: Any?,
content: @Composable () -> Unit
): List<Measurable> {
- requirePrecondition(postLookaheadComposedSlotIds.size >= currentPostLookaheadIndex) {
- "Error: currentPostLookaheadIndex cannot be greater than the size of the" +
- "postLookaheadComposedSlotIds list."
+ requirePrecondition(approachComposedSlotIds.size >= currentApproachIndex) {
+ "Error: currentApproachIndex cannot be greater than the size of the" +
+ "approachComposedSlotIds list."
}
- if (postLookaheadComposedSlotIds.size == currentPostLookaheadIndex) {
- postLookaheadComposedSlotIds.add(slotId)
+ if (approachComposedSlotIds.size == currentApproachIndex) {
+ approachComposedSlotIds.add(slotId)
} else {
- postLookaheadComposedSlotIds[currentPostLookaheadIndex] = slotId
+ approachComposedSlotIds[currentApproachIndex] = slotId
}
- currentPostLookaheadIndex++
+ currentApproachIndex++
if (!precomposeMap.contains(slotId)) {
// Not composed yet
- precompose(slotId, content).also { postLookaheadPrecomposeSlotHandleMap[slotId] = it }
+ precompose(slotId, content).also { approachPrecomposeSlotHandleMap[slotId] = it }
if (root.layoutState == LayoutState.LayingOut) {
root.requestLookaheadRelayout(true)
} else {