|
| 1 | +/* |
| 2 | + * Copyright 2022 The Android Open Source Project |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.example.wear.snippets.list |
| 18 | +import androidx.compose.material.icons.Icons |
| 19 | +import androidx.compose.material.icons.filled.Build |
| 20 | +import androidx.compose.runtime.Composable |
| 21 | +import androidx.wear.compose.material.Text |
| 22 | +import androidx.wear.compose.ui.tooling.preview.WearPreviewDevices |
| 23 | +import androidx.wear.compose.ui.tooling.preview.WearPreviewFontScales |
| 24 | +import com.google.android.horologist.annotations.ExperimentalHorologistApi |
| 25 | +import com.google.android.horologist.compose.layout.ScalingLazyColumn |
| 26 | +import com.google.android.horologist.compose.layout.ScalingLazyColumnDefaults |
| 27 | +import com.google.android.horologist.compose.layout.ScalingLazyColumnState |
| 28 | +import com.google.android.horologist.compose.layout.ScreenScaffold |
| 29 | +import com.google.android.horologist.compose.layout.rememberResponsiveColumnState |
| 30 | +import com.google.android.horologist.compose.material.Button |
| 31 | +import com.google.android.horologist.compose.material.ListHeaderDefaults.firstItemPadding |
| 32 | +import com.google.android.horologist.compose.material.ResponsiveListHeader |
| 33 | + |
| 34 | +@OptIn(ExperimentalHorologistApi::class) |
| 35 | +@Composable |
| 36 | +fun ComposeList() { |
| 37 | + // [START android_wear_list] |
| 38 | + val columnState = rememberResponsiveColumnState( |
| 39 | + contentPadding = ScalingLazyColumnDefaults.padding( |
| 40 | + first = ScalingLazyColumnDefaults.ItemType.Text, |
| 41 | + last = ScalingLazyColumnDefaults.ItemType.SingleButton |
| 42 | + ) |
| 43 | + ) |
| 44 | + ScreenScaffold(scrollState = columnState) { |
| 45 | + ScalingLazyColumn( |
| 46 | + columnState = columnState |
| 47 | + ) { |
| 48 | + item { |
| 49 | + ResponsiveListHeader(contentPadding = firstItemPadding()) { |
| 50 | + Text(text = "Header") |
| 51 | + } |
| 52 | + } |
| 53 | + // ... other items |
| 54 | + item { |
| 55 | + Button( |
| 56 | + imageVector = Icons.Default.Build, |
| 57 | + contentDescription = "Example Button", |
| 58 | + onClick = { } |
| 59 | + ) |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + // [END android_wear_list] |
| 64 | +} |
| 65 | + |
| 66 | +@OptIn(ExperimentalHorologistApi::class) |
| 67 | +@Composable |
| 68 | +fun SnapAndFlingComposeList() { |
| 69 | + // [START android_wear_snap] |
| 70 | + val columnState = rememberResponsiveColumnState( |
| 71 | + // ... |
| 72 | + // [START_EXCLUDE] |
| 73 | + contentPadding = ScalingLazyColumnDefaults.padding( |
| 74 | + first = ScalingLazyColumnDefaults.ItemType.Text, |
| 75 | + last = ScalingLazyColumnDefaults.ItemType.SingleButton |
| 76 | + ), |
| 77 | + // [END_EXCLUDE] |
| 78 | + rotaryMode = ScalingLazyColumnState.RotaryMode.Snap |
| 79 | + ) |
| 80 | + ScreenScaffold(scrollState = columnState) { |
| 81 | + ScalingLazyColumn( |
| 82 | + columnState = columnState |
| 83 | + ) { |
| 84 | + // ... |
| 85 | + // [START_EXCLUDE] |
| 86 | + item { |
| 87 | + ResponsiveListHeader(contentPadding = firstItemPadding()) { |
| 88 | + Text(text = "Header") |
| 89 | + } |
| 90 | + } |
| 91 | + // ... other items |
| 92 | + item { |
| 93 | + Button( |
| 94 | + imageVector = Icons.Default.Build, |
| 95 | + contentDescription = "Example Button", |
| 96 | + onClick = { } |
| 97 | + ) |
| 98 | + } |
| 99 | + // [END_EXCLUDE] |
| 100 | + } |
| 101 | + } |
| 102 | + // [END android_wear_snap] |
| 103 | +} |
| 104 | + |
| 105 | +@WearPreviewDevices |
| 106 | +@WearPreviewFontScales |
| 107 | +@Composable |
| 108 | +fun ComposeListPreview() { |
| 109 | + ComposeList() |
| 110 | +} |
0 commit comments