|
1 | 1 | import androidx.compose.foundation.layout.PaddingValues |
| 2 | +import androidx.compose.foundation.layout.Spacer |
| 3 | +import androidx.compose.foundation.layout.fillMaxSize |
| 4 | +import androidx.compose.foundation.layout.height |
2 | 5 | import androidx.compose.foundation.layout.padding |
3 | 6 | import androidx.compose.runtime.Composable |
| 7 | +import androidx.compose.runtime.LaunchedEffect |
| 8 | +import androidx.compose.runtime.getValue |
4 | 9 | import androidx.compose.runtime.mutableStateOf |
5 | 10 | import androidx.compose.runtime.remember |
| 11 | +import androidx.compose.runtime.setValue |
6 | 12 | import androidx.compose.ui.Modifier |
7 | 13 | import androidx.compose.ui.unit.dp |
| 14 | +import kotlinx.coroutines.delay |
8 | 15 | import top.yukonga.miuix.kmp.basic.Card |
9 | 16 | import top.yukonga.miuix.kmp.basic.LazyColumn |
| 17 | +import top.yukonga.miuix.kmp.basic.PullToRefresh |
10 | 18 | import top.yukonga.miuix.kmp.basic.ScrollBehavior |
| 19 | +import top.yukonga.miuix.kmp.basic.rememberPullToRefreshState |
11 | 20 | import top.yukonga.miuix.kmp.extra.SuperDropdown |
12 | 21 |
|
13 | 22 | @Composable |
14 | 23 | fun SecondPage( |
15 | 24 | topAppBarScrollBehavior: ScrollBehavior, |
16 | 25 | padding: PaddingValues |
17 | 26 | ) { |
| 27 | + val pullToRefreshState = rememberPullToRefreshState() |
| 28 | + var isRefreshing by remember { mutableStateOf(false) } |
| 29 | + |
18 | 30 | val dropdownOptions = listOf("Option 1", "Option 2", "Option 3", "Option 4") |
19 | 31 | val dropdownSelectedOption = remember { mutableStateOf(0) } |
| 32 | + var ii = remember { mutableStateOf(10) } |
| 33 | + |
| 34 | + LaunchedEffect(pullToRefreshState.isRefreshing) { |
| 35 | + if (pullToRefreshState.isRefreshing) { |
| 36 | + isRefreshing = true |
| 37 | + delay(100) |
| 38 | + pullToRefreshState.completeRefreshing { |
| 39 | + isRefreshing = false |
| 40 | + } |
| 41 | + } |
| 42 | + } |
20 | 43 |
|
21 | | - LazyColumn( |
22 | | - contentPadding = PaddingValues(top = padding.calculateTopPadding()), |
23 | | - topAppBarScrollBehavior = topAppBarScrollBehavior |
| 44 | + PullToRefresh( |
| 45 | + modifier = Modifier.padding( |
| 46 | + top = padding.calculateTopPadding() |
| 47 | + ), |
| 48 | + pullToRefreshState = pullToRefreshState, |
| 49 | + onRefresh = { ii.value++ } |
24 | 50 | ) { |
25 | | - item { |
26 | | - Card( |
27 | | - modifier = Modifier |
28 | | - .padding(horizontal = 12.dp) |
29 | | - .padding(top = 12.dp, bottom = 12.dp + padding.calculateBottomPadding()) |
30 | | - ) { |
31 | | - for (i in 0 until 50) { |
32 | | - SuperDropdown( |
33 | | - title = "Dropdown", |
34 | | - items = dropdownOptions, |
35 | | - selectedIndex = dropdownSelectedOption.value, |
36 | | - onSelectedIndexChange = { newOption -> dropdownSelectedOption.value = newOption } |
37 | | - ) |
| 51 | + LazyColumn( |
| 52 | + modifier = Modifier |
| 53 | + .fillMaxSize(), |
| 54 | + topAppBarScrollBehavior = topAppBarScrollBehavior, |
| 55 | + ) { |
| 56 | + item { |
| 57 | + Card( |
| 58 | + modifier = Modifier |
| 59 | + .padding(12.dp) |
| 60 | + ) { |
| 61 | + for (i in 0 until ii.value) { |
| 62 | + SuperDropdown( |
| 63 | + title = "Dropdown ${i + 1}", |
| 64 | + items = dropdownOptions, |
| 65 | + selectedIndex = dropdownSelectedOption.value, |
| 66 | + onSelectedIndexChange = { newOption -> dropdownSelectedOption.value = newOption } |
| 67 | + ) |
| 68 | + } |
38 | 69 | } |
| 70 | + Spacer(modifier = Modifier.height(padding.calculateBottomPadding())) |
39 | 71 | } |
40 | 72 | } |
41 | 73 | } |
|
0 commit comments