|
1 | 1 | import androidx.compose.foundation.Image |
2 | 2 | import androidx.compose.foundation.clickable |
| 3 | +import androidx.compose.foundation.layout.BoxWithConstraints |
3 | 4 | import androidx.compose.foundation.layout.Column |
4 | 5 | import androidx.compose.foundation.layout.PaddingValues |
| 6 | +import androidx.compose.foundation.layout.Row |
| 7 | +import androidx.compose.foundation.layout.Spacer |
| 8 | +import androidx.compose.foundation.layout.WindowInsets |
| 9 | +import androidx.compose.foundation.layout.WindowInsetsSides |
| 10 | +import androidx.compose.foundation.layout.displayCutout |
5 | 11 | import androidx.compose.foundation.layout.fillMaxSize |
6 | 12 | import androidx.compose.foundation.layout.fillMaxWidth |
| 13 | +import androidx.compose.foundation.layout.height |
| 14 | +import androidx.compose.foundation.layout.navigationBars |
| 15 | +import androidx.compose.foundation.layout.only |
7 | 16 | import androidx.compose.foundation.layout.padding |
| 17 | +import androidx.compose.foundation.layout.windowInsetsPadding |
8 | 18 | import androidx.compose.runtime.Composable |
9 | 19 | import androidx.compose.runtime.getValue |
10 | 20 | import androidx.compose.runtime.mutableStateOf |
@@ -35,80 +45,177 @@ fun MainPage( |
35 | 45 | var miuixSearchValue by remember { mutableStateOf("") } |
36 | 46 | var expanded by rememberSaveable { mutableStateOf(false) } |
37 | 47 |
|
38 | | - LazyColumn( |
39 | | - contentPadding = PaddingValues(top = padding.calculateTopPadding()), |
40 | | - topAppBarScrollBehavior = topAppBarScrollBehavior, |
| 48 | + BoxWithConstraints( |
| 49 | + modifier = Modifier.fillMaxSize() |
41 | 50 | ) { |
42 | | - item { |
43 | | - SearchBar( |
44 | | - modifier = Modifier.padding(horizontal = 12.dp, vertical = 10.dp), |
45 | | - inputField = { |
46 | | - InputField( |
47 | | - query = miuixSearchValue, |
48 | | - onQueryChange = { miuixSearchValue = it }, |
49 | | - onSearch = { expanded = false }, |
50 | | - expanded = expanded, |
51 | | - onExpandedChange = { expanded = it }, |
52 | | - label = "Search", |
53 | | - leadingIcon = { |
54 | | - Image( |
55 | | - modifier = Modifier.padding(horizontal = 16.dp), |
56 | | - imageVector = MiuixIcons.Search, |
57 | | - colorFilter = BlendModeColorFilter( |
58 | | - MiuixTheme.colorScheme.onSurfaceContainer, |
59 | | - BlendMode.SrcIn |
60 | | - ), |
61 | | - contentDescription = "Search" |
| 51 | + if (maxWidth < 840.dp) { |
| 52 | + LazyColumn( |
| 53 | + contentPadding = PaddingValues(top = padding.calculateTopPadding()), |
| 54 | + topAppBarScrollBehavior = topAppBarScrollBehavior, |
| 55 | + ) { |
| 56 | + item { |
| 57 | + SearchBar( |
| 58 | + modifier = Modifier.padding(horizontal = 12.dp, vertical = 10.dp), |
| 59 | + inputField = { |
| 60 | + InputField( |
| 61 | + query = miuixSearchValue, |
| 62 | + onQueryChange = { miuixSearchValue = it }, |
| 63 | + onSearch = { expanded = false }, |
| 64 | + expanded = expanded, |
| 65 | + onExpandedChange = { expanded = it }, |
| 66 | + label = "Search", |
| 67 | + leadingIcon = { |
| 68 | + Image( |
| 69 | + modifier = Modifier.padding(horizontal = 16.dp), |
| 70 | + imageVector = MiuixIcons.Search, |
| 71 | + colorFilter = BlendModeColorFilter( |
| 72 | + MiuixTheme.colorScheme.onSurfaceContainer, |
| 73 | + BlendMode.SrcIn |
| 74 | + ), |
| 75 | + contentDescription = "Search" |
| 76 | + ) |
| 77 | + }, |
62 | 78 | ) |
63 | 79 | }, |
64 | | - ) |
65 | | - }, |
66 | | - outsideRightAction = { |
67 | | - Text( |
68 | | - modifier = Modifier |
69 | | - .padding(start = 12.dp) |
70 | | - .clickable( |
71 | | - interactionSource = null, |
72 | | - indication = null |
73 | | - ) { |
74 | | - expanded = false |
75 | | - miuixSearchValue = "" |
76 | | - }, |
77 | | - text = "Cancel", |
78 | | - color = MiuixTheme.colorScheme.primary |
79 | | - ) |
80 | | - }, |
81 | | - expanded = expanded, |
82 | | - onExpandedChange = { expanded = it } |
83 | | - ) { |
84 | | - Column( |
85 | | - Modifier.fillMaxSize() |
86 | | - ) { |
87 | | - repeat(4) { idx -> |
88 | | - val resultText = "Suggestion $idx" |
89 | | - BasicComponent( |
90 | | - title = resultText, |
91 | | - modifier = Modifier |
92 | | - .fillMaxWidth(), |
93 | | - onClick = { |
94 | | - miuixSearchValue = resultText |
95 | | - expanded = false |
| 80 | + outsideRightAction = { |
| 81 | + Text( |
| 82 | + modifier = Modifier |
| 83 | + .padding(start = 12.dp) |
| 84 | + .clickable( |
| 85 | + interactionSource = null, |
| 86 | + indication = null |
| 87 | + ) { |
| 88 | + expanded = false |
| 89 | + miuixSearchValue = "" |
| 90 | + }, |
| 91 | + text = "Cancel", |
| 92 | + color = MiuixTheme.colorScheme.primary |
| 93 | + ) |
| 94 | + }, |
| 95 | + expanded = expanded, |
| 96 | + onExpandedChange = { expanded = it } |
| 97 | + ) { |
| 98 | + Column( |
| 99 | + Modifier.fillMaxSize() |
| 100 | + ) { |
| 101 | + repeat(4) { idx -> |
| 102 | + val resultText = "Suggestion $idx" |
| 103 | + BasicComponent( |
| 104 | + title = resultText, |
| 105 | + modifier = Modifier |
| 106 | + .fillMaxWidth(), |
| 107 | + onClick = { |
| 108 | + miuixSearchValue = resultText |
| 109 | + expanded = false |
| 110 | + } |
| 111 | + ) |
96 | 112 | } |
97 | | - ) |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + if (!expanded) { |
| 117 | + item( |
| 118 | + key = "text" |
| 119 | + ) { |
| 120 | + TextComponent() |
| 121 | + } |
| 122 | + item( |
| 123 | + key = "other" |
| 124 | + ) { |
| 125 | + OtherComponent(padding) |
98 | 126 | } |
99 | 127 | } |
100 | 128 | } |
101 | | - } |
102 | | - if (!expanded) { |
103 | | - item( |
104 | | - key = "text" |
105 | | - ) { |
106 | | - TextComponent() |
107 | | - } |
108 | | - item( |
109 | | - key = "other" |
| 129 | + } else { |
| 130 | + Row( |
| 131 | + modifier = Modifier |
| 132 | + .windowInsetsPadding(WindowInsets.displayCutout.only(WindowInsetsSides.Horizontal)) |
| 133 | + .windowInsetsPadding(WindowInsets.navigationBars.only(WindowInsetsSides.Horizontal)) |
110 | 134 | ) { |
111 | | - OtherComponent(padding) |
| 135 | + LazyColumn( |
| 136 | + modifier = Modifier.weight(1f), |
| 137 | + contentPadding = PaddingValues(top = padding.calculateTopPadding()), |
| 138 | + topAppBarScrollBehavior = topAppBarScrollBehavior, |
| 139 | + ) { |
| 140 | + item { |
| 141 | + SearchBar( |
| 142 | + modifier = Modifier.padding(horizontal = 12.dp, vertical = 10.dp), |
| 143 | + inputField = { |
| 144 | + InputField( |
| 145 | + query = miuixSearchValue, |
| 146 | + onQueryChange = { miuixSearchValue = it }, |
| 147 | + onSearch = { expanded = false }, |
| 148 | + expanded = expanded, |
| 149 | + onExpandedChange = { expanded = it }, |
| 150 | + label = "Search", |
| 151 | + leadingIcon = { |
| 152 | + Image( |
| 153 | + modifier = Modifier.padding(horizontal = 16.dp), |
| 154 | + imageVector = MiuixIcons.Search, |
| 155 | + colorFilter = BlendModeColorFilter( |
| 156 | + MiuixTheme.colorScheme.onSurfaceContainer, |
| 157 | + BlendMode.SrcIn |
| 158 | + ), |
| 159 | + contentDescription = "Search" |
| 160 | + ) |
| 161 | + }, |
| 162 | + ) |
| 163 | + }, |
| 164 | + outsideRightAction = { |
| 165 | + Text( |
| 166 | + modifier = Modifier |
| 167 | + .padding(start = 12.dp) |
| 168 | + .clickable( |
| 169 | + interactionSource = null, |
| 170 | + indication = null |
| 171 | + ) { |
| 172 | + expanded = false |
| 173 | + miuixSearchValue = "" |
| 174 | + }, |
| 175 | + text = "Cancel", |
| 176 | + color = MiuixTheme.colorScheme.primary |
| 177 | + ) |
| 178 | + }, |
| 179 | + expanded = expanded, |
| 180 | + onExpandedChange = { expanded = it } |
| 181 | + ) { |
| 182 | + Column( |
| 183 | + Modifier.fillMaxSize() |
| 184 | + ) { |
| 185 | + repeat(4) { idx -> |
| 186 | + val resultText = "Suggestion $idx" |
| 187 | + BasicComponent( |
| 188 | + title = resultText, |
| 189 | + modifier = Modifier |
| 190 | + .fillMaxWidth(), |
| 191 | + onClick = { |
| 192 | + miuixSearchValue = resultText |
| 193 | + expanded = false |
| 194 | + } |
| 195 | + ) |
| 196 | + } |
| 197 | + } |
| 198 | + } |
| 199 | + } |
| 200 | + if (!expanded) { |
| 201 | + item( |
| 202 | + key = "text" |
| 203 | + ) { |
| 204 | + OtherComponent(padding) |
| 205 | + |
| 206 | + } |
| 207 | + } |
| 208 | + } |
| 209 | + LazyColumn( |
| 210 | + modifier = Modifier.padding(end = 12.dp).weight(1f), |
| 211 | + contentPadding = PaddingValues(top = padding.calculateTopPadding()), |
| 212 | + topAppBarScrollBehavior = topAppBarScrollBehavior |
| 213 | + ) { |
| 214 | + item { |
| 215 | + TextComponent() |
| 216 | + Spacer(modifier = Modifier.height(12.dp + padding.calculateBottomPadding())) |
| 217 | + } |
| 218 | + } |
112 | 219 | } |
113 | 220 | } |
114 | 221 | } |
|
0 commit comments