@@ -25,6 +25,7 @@ import androidx.compose.foundation.layout.Box
25
25
import androidx.compose.foundation.layout.Row
26
26
import androidx.compose.foundation.layout.Spacer
27
27
import androidx.compose.foundation.layout.fillMaxSize
28
+ import androidx.compose.foundation.layout.fillMaxWidth
28
29
import androidx.compose.foundation.layout.size
29
30
import androidx.compose.foundation.layout.width
30
31
import androidx.compose.runtime.Composable
@@ -45,9 +46,12 @@ import androidx.compose.ui.input.rotary.onRotaryScrollEvent
45
46
import androidx.compose.ui.unit.dp
46
47
import androidx.wear.compose.foundation.ExperimentalWearFoundationApi
47
48
import androidx.wear.compose.foundation.lazy.ScalingLazyColumn
49
+ import androidx.wear.compose.foundation.lazy.ScalingLazyColumnDefaults
48
50
import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState
49
51
import androidx.wear.compose.foundation.rememberActiveFocusRequester
50
52
import androidx.wear.compose.material.Chip
53
+ import androidx.wear.compose.material.ChipDefaults
54
+ import androidx.wear.compose.material.ListHeader
51
55
import androidx.wear.compose.material.MaterialTheme
52
56
import androidx.wear.compose.material.Picker
53
57
import androidx.wear.compose.material.PositionIndicator
@@ -204,6 +208,47 @@ fun TimePicker() {
204
208
// [END android_wear_rotary_input_picker]
205
209
}
206
210
211
+ @Composable
212
+ fun SnapScrollableScreen () {
213
+ // This sample doesn't add a Time Text at the top of the screen.
214
+ // If using Time Text, add padding to ensure content does not overlap with Time Text.
215
+ // [START android_wear_rotary_input_snap_fling]
216
+ val listState = rememberScalingLazyListState()
217
+ Scaffold (
218
+ positionIndicator = {
219
+ PositionIndicator (scalingLazyListState = listState)
220
+ }
221
+ ) {
222
+
223
+ val state = rememberScalingLazyListState()
224
+ ScalingLazyColumn (
225
+ modifier = Modifier .fillMaxWidth(),
226
+ state = state,
227
+ flingBehavior = ScalingLazyColumnDefaults .snapFlingBehavior(state = state)
228
+ ) {
229
+ // Content goes here
230
+ // [START_EXCLUDE]
231
+ item { ListHeader { Text (text = " List Header" ) } }
232
+ items(20 ) {
233
+ Chip (
234
+ onClick = {},
235
+ label = { Text (" List item $it " ) },
236
+ colors = ChipDefaults .secondaryChipColors()
237
+ )
238
+ }
239
+ // [END_EXCLUDE]
240
+ }
241
+ }
242
+ // [END android_wear_rotary_input_snap_fling]
243
+ }
244
+
245
+ @WearPreviewDevices
246
+ @WearPreviewFontScales
247
+ @Composable
248
+ fun TimePickerPreview () {
249
+ TimePicker ()
250
+ }
251
+
207
252
@WearPreviewDevices
208
253
@WearPreviewFontScales
209
254
@Composable
@@ -214,6 +259,6 @@ fun ScrollableScreenPreview() {
214
259
@WearPreviewDevices
215
260
@WearPreviewFontScales
216
261
@Composable
217
- fun TimePickerPreview () {
218
- TimePicker ()
262
+ fun SnapScrollableScreenPreview () {
263
+ SnapScrollableScreen ()
219
264
}
0 commit comments