Hi everyone. I'm encountering a strange bug on iOS...
# compose
l
Hi everyone. I'm encountering a strange bug on iOS related to the PullToRefresh in CMP. Sometimes, when I use the gesture to refresh, the PullToRefresh feature behaves unexpectedly—the screen tries to scroll down the
LazyColumn
. This issue only occurs when the component is scrollable. I’ll share a video to show exactly what’s happening.https://youtube.com/shorts/WZSkPGpTPLU?feature=share
h
I'm not sure anyone is able to help you without some code
👍 1
l
This the code
Copy code
@Composable
fun PullToRefreshLazyColumn(
    modifier: Modifier = Modifier,
    isRefreshing: Boolean? = null,
    enabledPullToRefresh: Boolean = true,
    onRefresh: () -> Unit,
    contentPadding: PaddingValues = PaddingValues(),
    verticalArrangement: Arrangement.Vertical = <http://Arrangement.Top|Arrangement.Top>,
    lazyListState: LazyListState = rememberLazyListState(),
    positionalThreshold: Dp = PullToRefreshDefaults.PositionalThreshold,
    content: (LazyListScope.() -> Unit),
) {
    val scope = rememberCoroutineScope()
    val pullToRefreshState = rememberPullToRefreshState()
    Box(
        modifier = modifier
            .pullToRefresh(
                isRefreshing = isRefreshing ?: false,
                state = pullToRefreshState,
                threshold = positionalThreshold,
                enabled = enabledPullToRefresh,
                onRefresh = {
                    onRefresh()
                    scope.launch {
                        if (isRefreshing == null) pullToRefreshState.animateToHidden()
                    }
                }
            ),
    ) {
        LazyColumn(
            state = lazyListState,
            contentPadding = contentPadding,
            modifier = Modifier
                .fillMaxSize(),
            verticalArrangement = verticalArrangement
        ) {
            content()
        }

        Indicator(
            modifier = Modifier.align(Alignment.TopCenter),
            isRefreshing = isRefreshing ?: false,
            state = pullToRefreshState,
            threshold = positionalThreshold,
        )
    }
}
@Hristijan