@@ -25,6 +25,7 @@ import androidx.compose.foundation.layout.Box
2525import androidx.compose.foundation.layout.Row
2626import androidx.compose.foundation.layout.Spacer
2727import androidx.compose.foundation.layout.fillMaxSize
28+ import androidx.compose.foundation.layout.fillMaxWidth
2829import androidx.compose.foundation.layout.size
2930import androidx.compose.foundation.layout.width
3031import androidx.compose.runtime.Composable
@@ -45,9 +46,12 @@ import androidx.compose.ui.input.rotary.onRotaryScrollEvent
4546import androidx.compose.ui.unit.dp
4647import androidx.wear.compose.foundation.ExperimentalWearFoundationApi
4748import androidx.wear.compose.foundation.lazy.ScalingLazyColumn
49+ import androidx.wear.compose.foundation.lazy.ScalingLazyColumnDefaults
4850import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState
4951import androidx.wear.compose.foundation.rememberActiveFocusRequester
5052import androidx.wear.compose.material.Chip
53+ import androidx.wear.compose.material.ChipDefaults
54+ import androidx.wear.compose.material.ListHeader
5155import androidx.wear.compose.material.MaterialTheme
5256import androidx.wear.compose.material.Picker
5357import androidx.wear.compose.material.PositionIndicator
@@ -204,6 +208,47 @@ fun TimePicker() {
204208 // [END android_wear_rotary_input_picker]
205209}
206210
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+
207252@WearPreviewDevices
208253@WearPreviewFontScales
209254@Composable
@@ -214,6 +259,6 @@ fun ScrollableScreenPreview() {
214259@WearPreviewDevices
215260@WearPreviewFontScales
216261@Composable
217- fun TimePickerPreview () {
218- TimePicker ()
262+ fun SnapScrollableScreenPreview () {
263+ SnapScrollableScreen ()
219264}
0 commit comments