Skip to content

Commit b2a0075

Browse files
authored
Merge pull request #330 from android/wear
Add snap for rotary for SLC
2 parents 5bbe640 + 23712af commit b2a0075

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

gradle/libs.versions.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ recyclerview = "1.3.2"
4646
# @keep
4747
targetSdk = "34"
4848
version-catalog-update = "0.8.3"
49-
wearComposeFoundation = "1.3.0"
50-
wearComposeMaterial = "1.3.0"
49+
wearComposeFoundation = "1.4.0"
50+
wearComposeMaterial = "1.4.0"
5151
composeUiTooling = "1.3.1"
5252

5353
[libraries]

wear/src/main/java/com/example/wear/snippets/rotary/Rotary.kt

+47-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import androidx.compose.foundation.layout.Box
2525
import androidx.compose.foundation.layout.Row
2626
import androidx.compose.foundation.layout.Spacer
2727
import androidx.compose.foundation.layout.fillMaxSize
28+
import androidx.compose.foundation.layout.fillMaxWidth
2829
import androidx.compose.foundation.layout.size
2930
import androidx.compose.foundation.layout.width
3031
import androidx.compose.runtime.Composable
@@ -45,9 +46,12 @@ import androidx.compose.ui.input.rotary.onRotaryScrollEvent
4546
import androidx.compose.ui.unit.dp
4647
import androidx.wear.compose.foundation.ExperimentalWearFoundationApi
4748
import androidx.wear.compose.foundation.lazy.ScalingLazyColumn
49+
import androidx.wear.compose.foundation.lazy.ScalingLazyColumnDefaults
4850
import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState
4951
import androidx.wear.compose.foundation.rememberActiveFocusRequester
5052
import androidx.wear.compose.material.Chip
53+
import androidx.wear.compose.material.ChipDefaults
54+
import androidx.wear.compose.material.ListHeader
5155
import androidx.wear.compose.material.MaterialTheme
5256
import androidx.wear.compose.material.Picker
5357
import 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

Comments
 (0)