Fixed
Status Update
Comments
le...@google.com <le...@google.com> #2
Hey thanks for reporting this, the items will be automatically centered within the available viewport size after subtracting the the padding values (see attached image, the purple lines are the viewport bounds after applying the content paddings you mentioned).
I appreciate the feedback and I think it might be interesting to have the complete layout info available as well as the paddings as part of SnapPositionInLayout. In the meantime you already know the before and after content padding, you can reverse engineer and calculate the full layout size and using a custom SnapPositionInLayout you should be able to achieve your desired result.
di...@googlemail.com <di...@googlemail.com> #3
> the items will be automatically centered within the available viewport size after subtracting the the padding values
yes, but in LazyRow the content padding is not decreasing the viewport size. It is adding spacing inside the scrolling container.
In my opinion, it should not be substracted from viewport size. I guess it depends on the usecase.
> complete layout info available as well as the paddings as part of SnapPositionInLayout
Full layoutInfo would be helpfull.
In addition would be State object with snapping information helpful. Like current position in snapping position.
yes, but in LazyRow the content padding is not decreasing the viewport size. It is adding spacing inside the scrolling container.
In my opinion, it should not be substracted from viewport size. I guess it depends on the usecase.
> complete layout info available as well as the paddings as part of SnapPositionInLayout
Full layoutInfo would be helpfull.
In addition would be State object with snapping information helpful. Like current position in snapping position.
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-main
commit e8902c95627d25d07d05a66bd808562ece482571
Author: Levi Albuquerque <levima@google.com>
Date: Wed Sep 13 09:51:58 2023
Update SnapPositionInLayout to have more info about the Layout.
Make it more clear that the layout size in the position method is actually with respect to the available space (after subtracting the content paddings). Introduce content padding to the position method.
Test: N/A
Fixes: 300116110
Relnote: Update SnapPositionInLayout documentation and position method. Introduce content paddings to the position method in SnapPositionInLayout.
Change-Id: Id79383a2bc99bc7db54f716fdfd7b0aa6708cfac
M compose/foundation/foundation/api/current.txt
M compose/foundation/foundation/api/restricted_current.txt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/snapping/SnapPositionInLayout.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/pager/PagerState.kt
https://android-review.googlesource.com/2750222
Branch: androidx-main
commit e8902c95627d25d07d05a66bd808562ece482571
Author: Levi Albuquerque <levima@google.com>
Date: Wed Sep 13 09:51:58 2023
Update SnapPositionInLayout to have more info about the Layout.
Make it more clear that the layout size in the position method is actually with respect to the available space (after subtracting the content paddings). Introduce content padding to the position method.
Test: N/A
Fixes: 300116110
Relnote: Update SnapPositionInLayout documentation and position method. Introduce content paddings to the position method in SnapPositionInLayout.
Change-Id: Id79383a2bc99bc7db54f716fdfd7b0aa6708cfac
M compose/foundation/foundation/api/current.txt
M compose/foundation/foundation/api/restricted_current.txt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/snapping/SnapPositionInLayout.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/pager/PagerState.kt
di...@googlemail.com <di...@googlemail.com> #5
I Like it. It solves the issue
Description
Jetpack Compose component(s) used: foundation, material, livedata
Android Studio Build:
Kotlin version: 1.9.10
Steps to Reproduce or Code Sample to Reproduce:
val snappingLayout = remember(state) { SnapLayoutInfoProvider(state, positionInLayout = SnapPositionInLayout.CenterToCenter) }
val flingBehavior = remeberSnapFlingBehavior(snappingLayout)
LazyRow(state = state, flingBehavior = flingBehavior, contentPadding = PaddingValues(start = 100.dp, end = 200.dp))
with item that has 100.dp and 49.dp width
The layoutSize inside of positionInLayout should not subtract contentpadding from mainAxisViewPortSize?
In my usecase, the items are not centered to the container.
If it is not including content padding. It is not clear, what and how to calc the positionInLayout.