1+ /* 
2+  * Copyright 2025 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.m3.pager 
18+ 
19+ import  androidx.compose.foundation.layout.fillMaxWidth 
20+ import  androidx.compose.runtime.Composable 
21+ import  androidx.compose.ui.Modifier 
22+ import  androidx.wear.compose.foundation.lazy.TransformingLazyColumn 
23+ import  androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState 
24+ import  androidx.wear.compose.foundation.pager.HorizontalPager 
25+ import  androidx.wear.compose.foundation.pager.rememberPagerState 
26+ import  androidx.wear.compose.material3.AnimatedPage 
27+ import  androidx.wear.compose.material3.AppScaffold 
28+ import  androidx.wear.compose.material3.HorizontalPagerScaffold 
29+ import  androidx.wear.compose.material3.ListHeader 
30+ import  androidx.wear.compose.material3.ScreenScaffold 
31+ import  androidx.wear.compose.material3.Text 
32+ import  com.google.android.horologist.compose.layout.ColumnItemType 
33+ import  com.google.android.horologist.compose.layout.rememberResponsiveColumnPadding 
34+ 
35+ @Composable
36+ fun  HorizontalPager () {
37+     //  [START android_wear_horizontal_pager]
38+     AppScaffold  {
39+         val  pagerState =  rememberPagerState(pageCount =  { 10  })
40+         val  columnState =  rememberTransformingLazyColumnState()
41+         val  contentPadding =  rememberResponsiveColumnPadding(
42+             first =  ColumnItemType .ListHeader ,
43+             last =  ColumnItemType .BodyText ,
44+         )
45+         HorizontalPagerScaffold (pagerState =  pagerState) {
46+             HorizontalPager (
47+                 state =  pagerState,
48+             ) { page -> 
49+                 AnimatedPage (pageIndex =  page, pagerState =  pagerState) {
50+                     ScreenScaffold (
51+                         scrollState =  columnState,
52+                         contentPadding =  contentPadding
53+                     ) { contentPadding -> 
54+                         TransformingLazyColumn (
55+                             state =  columnState,
56+                             contentPadding =  contentPadding
57+                         ) {
58+                             item {
59+                                 ListHeader (
60+                                     modifier =  Modifier .fillMaxWidth()
61+                                 ) {
62+                                     Text (text =  " Pager sample"  )
63+                                 }
64+                             }
65+                             item {
66+                                 if  (page ==  0 ) {
67+                                     Text (text =  " Page #$page . Swipe right"  )
68+                                 }
69+                                 else {
70+                                     Text (text =  " Page #$page . Swipe left and right"  )
71+                                 }
72+                             }
73+                         }
74+                     }
75+ 
76+                 }
77+             }
78+         }
79+     }
80+     //  [END android_wear_horizontal_pager]
81+ }
0 commit comments