Is there a way to show preview of the left and rig...
# compose
s
Is there a way to show preview of the left and right pages of a fixed size with accompanist
Pager
without parent measuring with BoxWithConstraints/SubcomposeLayout?
Copy code
HorizontalPager(
  modifier = modifier.fillMaxWidth(),
  itemSpacing = 8.dp,
  state = pagerState,
) { pageIndex ->
  BoxWithConstraints {
    MyItem(
      modifier = Modifier.width(maxWidth - 32.dp),
    )
  }
}
z
Idk about the
Pager
component, but that looks like you’re re-implementing the
padding
modifier using subcomposition, which is a bad idea for a host of reasons. Why not just use a proper layout modifier?
c
This isn't really about padding or Pager. There's no built in way to do what you're asking, but it's pretty simple to implement your own
LayoutModifier
which does this without subcomposition. Its basically a
fillMaxWidth(minus = 32.dp)
The alternative way is to do
fillMaxWidth(0.9f)
, but that obviously won’t always be 32dp
s
Ok, thank you!
c
@Stanislav Pestov let me know what you come up with.
s
@Colton Idle I have implemented modifier
Modifier.fillMaxWidth(offset: Dp)
c
Oooh. Thanks!