Yingding Wang
01/13/2022, 7:45 PMoffset
of ScalingLazyListItemInfo
are ScalingLazyListAnchorType.ItemCenter
or ItemStart
while initialising the ScalingLazyColumn, the option of offset to its initial position of Alpha 13 are now gone.
How can I detect that the ScalingLazyColumn has been scrolled up e.g. 15dp?Yingding Wang
01/13/2022, 7:59 PMval listState = rememberScalingLazyListState()
Scaffold(
timeText = {
val itemInfoList = listState.layoutInfo.visibleItemsInfo
// the first element is scrolled up more than 15dp, deactivate the Time Text
if (itemInfoList.isNotEmpty()
&& itemInfoList[0].index == 0 // the first visible index is the first element
&& itemInfoList[0].offset >= -15 // the first element is scrolled up less than 15dp
) {
// show time text
TimeText()
}
},
and with Alpha 14, I would need to cache or copy the first listState.centerItemScrollOffset
which is a lazy property. Any hint of this would be grateful.Yingding Wang
01/13/2022, 9:02 PMScalingLazyListState
with initial values and test centerItemScrollOffset
against the initial offset value. But still I am not quite happy with this solution, since I will need to compute these initial value by myself according to Layout Dimension to get whether a ScalingLazyColumn
has been scrolled up 15dp.
val initCenterItemOffset = -21
val initCenterItemIdx = 1
val listState: ScalingLazyListState = rememberScalingLazyListState(
initialCenterItemIndex = initCenterItemIdx,
initialCenterItemScrollOffset = initCenterItemOffset
)
Scaffold(
timeText = {
if (listState.centerItemIndex == initCenterItemIdx
&& listState.centerItemScrollOffset <= initCenterItemOffset + 15) { // scroll up 15dp and deactivate Time
TimeText()
}
Yingding Wang
01/13/2022, 9:14 PMJohn Nichol
01/13/2022, 10:14 PMJohn Nichol
01/13/2022, 10:24 PMJohn Nichol
01/13/2022, 10:26 PMYingding Wang
01/14/2022, 8:42 AMThe Edge anchor type is about whether the Edge or Center of the list items is aligned to the center of the viewport
I didn’t know this, now the number of offset makes sense.
A generic collision detection seems really difficult at this point. Can you give me a hint of how to get the list item dimensions from the ScalingLazyListItemInfo
, I thought of doing some calculation with screenHeights and the dimensions (height and width) of list items. The anchor type controls whether the Edge or Center of the list items is aligned to the center of the viewport, the list item dimension should be available right?yschimke
01/14/2022, 9:50 AMyschimke
01/14/2022, 9:52 AMJohn Nichol
01/14/2022, 12:00 PMScalingLazyList
is taking the whole screen (which I think will usually be the case) then I think all you need to know if the list height/screen height and then you can easily convert offsets to absolute values - offset + height /2f. If you are taking up part of the screen then you might need onGloballyPositioned on the list instead and do some slighly more interesting but still really simple maths instead. I think I would avoid onGloballyPositioned() on the list items - better to observe the state than have callbacks.Yingding Wang
01/14/2022, 12:45 PMItemStart
for `anchorType`and then use offset + screenHeight /2f
to get the absolute value will work for this first item with TimeText example. But we have also the item expansion via click event for text message. This means the view dimension of an item can change in run time. It would be great also be able to get the view dimension info from the State? But I don’t know how to get this item view dimension in runtime.John Nichol
01/14/2022, 1:01 PMYingding Wang
01/14/2022, 1:02 PM