Does anybody know whether LazyColumn can be used i...
# compose
a
Does anybody know whether LazyColumn can be used inside
androidx.swiperefreshlayout.widget.SwipeRefreshLayout
? There are examples here with a fix using
Modifier.nestedScroll(rememberNestedScrollInteropConnection())
for bottom sheet but it seems like it doesn’t work with hierarchy like:
Copy code
<SwipeRefreshLayout>
   <ComposeView> // LazyColumn with Modifier.nestedScroll(rememberNestedScrollInteropConnection()) here
</SwipeRefreshLayout>
scrolling up immediately triggers the swipe refresh.
e
Copy code
val state = rememberLazyListState()
LaunchedEffect(listState) {
    swipeRefreshLayout.setOnChildScrollUpCallback { _, _ -> listState.firstVisibleItemScrollOffset > 0 }
}
LazyColumn(state = state, ...)
a
First of all, thanks for the code snippet - that works for the sample but do you know why it doesn’t work out of the box similar to other
NestedScrollingParent3
ViewGroups
CoordinatorLayout
for example? In more real-world complex scenario, such as when compose code is encapsulated within a fragment, there is not way to propagate
SwipeRefreshLayout
reference to the compose code, as far as I understand,
NestedScrollingParent3
abstraction should solve this issue
e
there's multiple different things happening here
SwipeRefreshLayout
is a
NestedScrollingParent3
, but
ComposeView
is not a
NestedScrollingChild3
a
I thought that
NestedScrollInteropConnection
makes it a
NestedScrollingChild3
e
ah, yeah. I tracked it down to the wrong place
ComposeView
is returning false from
canScrollVertically
before a gesture starts, it seems
so
SwipeRefreshLayout
doesn't delegate a pull down into
ComposeView
, but if you pull even a little bit first then it all works
a
I haven’t debugged it much, just saw that once I scrolled to the bottom, interop connection doesn’t receive events
as if SwipeToRefresh consume it
e
TBH I'm not entirely sure why it doesn't work on the Compose side…
a
me too, but thanks for looking into it
301 Views