package com.example.test import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.gestures.Orientation import androidx.compose.foundation.gestures.draggable import androidx.compose.foundation.gestures.rememberDraggableState import androidx.compose.foundation.gestures.scrollBy import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.safeDrawing import androidx.compose.foundation.layout.windowInsetsPadding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Text import androidx.compose.material3.pulltorefresh.PullToRefreshBox import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults.Indicator import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.input.pointer.PointerType import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.unit.dp import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlin.time.Duration.Companion.seconds class MainActivity : ComponentActivity() { @OptIn(ExperimentalMaterial3Api::class) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { val scope = rememberCoroutineScope() val lazyListState = rememberLazyListState() var isRefreshing by remember { mutableStateOf(false) } val refreshState = rememberPullToRefreshState() var isMouseScroll by remember { mutableStateOf(false) } val onRefresh: () -> Unit = { if (!isMouseScroll) { scope.launch { isRefreshing = true delay(1.seconds) isRefreshing = false } } } PullToRefreshBox( isRefreshing = isRefreshing, onRefresh = onRefresh, state = refreshState, indicator = { if (!isMouseScroll) { Indicator( modifier = Modifier.align(Alignment.TopCenter), isRefreshing = isRefreshing, state = refreshState, ) } }, modifier = Modifier .windowInsetsPadding(WindowInsets.safeDrawing) .pointerInput(Unit) { awaitPointerEventScope { while (true) { val event = awaitPointerEvent() isMouseScroll = event.changes.any { it.type == PointerType.Mouse } } } } ) { LazyColumn( state = lazyListState, modifier = Modifier .draggable( orientation = Orientation.Vertical, state = rememberDraggableState { delta -> scope.launch { lazyListState.scrollBy(-delta) } }, ) ) { items(100) { Text( text = "Item $it", modifier = Modifier .fillMaxWidth() .padding(16.dp), ) } } } } } }