@@ -21,6 +21,7 @@ import androidx.annotation.RequiresApi
2121import androidx.compose.runtime.Composable
2222import androidx.compose.ui.graphics.Color
2323import androidx.compose.ui.unit.dp
24+ import androidx.compose.ui.unit.DpSize
2425import androidx.glance.GlanceModifier
2526import androidx.glance.Image
2627import androidx.glance.ImageProvider
@@ -58,7 +59,6 @@ import com.example.platform.ui.appwidgets.glance.layout.utils.SmallWidgetPreview
5859 * Each item displays an edge-to-edge background photo with overlaid
5960 * title and caption details that auto-scale to fit the current widget size.
6061 */
61- @RequiresApi(Build .VERSION_CODES_FULL .BAKLAVA_1 )
6262@Composable
6363fun FullBleedImageLayout (
6464 data : List <ImageGridItemData >? = null,
@@ -81,30 +81,74 @@ fun FullBleedImageLayout(
8181 actionButtonIcon = R .drawable.sample_info_icon,
8282 actionButtonOnClick = actionStartDemoActivity(" on-click of info button in no data view" )
8383 )
84- } else if (data.size == 1 ) {
85- // If there's only 1 item (like in the widget preview), render with fillMaxSize to
86- // bypass LazyColumn measurement issues where the generated widget preview item doesn't
87- // fill the widget bounds.
88- GalleryItemCard (
89- item = data[0 ],
84+ } else if (Build .VERSION .SDK_INT_FULL >= Build .VERSION_CODES_FULL .BAKLAVA_1 ) {
85+ SnapScrollingGallery (
86+ data = data,
9087 isSmall = isSmall,
9188 appName = appName,
92- modifier = GlanceModifier .fillMaxSize()
89+ size = size
9390 )
9491 } else {
95- val limitedData = data.take(5 )
96- LazyColumn (
97- modifier = GlanceModifier .fillMaxSize(),
98- verticalScrollMode = VerticalScrollMode .SnapScrollMatchHeight (size.height)
99- ) {
100- items(limitedData, itemId = { it.key.hashCode().toLong() }) { item ->
101- GalleryItemCard (
102- item = item,
103- isSmall = isSmall,
104- appName = appName,
105- modifier = GlanceModifier .width(size.width).height(size.height)
106- )
107- }
92+ // Show a standard scrolling list of items without Snap Scrolling
93+ // TODO: Remove once Snap Scrolling gracefully degrades
94+ GalleryList (
95+ data = data,
96+ isSmall = isSmall,
97+ appName = appName,
98+ size = size
99+ )
100+ }
101+ }
102+ }
103+
104+ @RequiresApi(Build .VERSION_CODES_FULL .BAKLAVA_1 )
105+ @Composable
106+ private fun SnapScrollingGallery (
107+ data : List <ImageGridItemData >,
108+ isSmall : Boolean ,
109+ appName : String ,
110+ size : DpSize ,
111+ ) {
112+ GalleryList (
113+ data = data,
114+ isSmall = isSmall,
115+ appName = appName,
116+ size = size,
117+ verticalScrollMode = VerticalScrollMode .SnapScrollMatchHeight (size.height)
118+ )
119+ }
120+
121+ @Composable
122+ private fun GalleryList (
123+ data : List <ImageGridItemData >,
124+ isSmall : Boolean ,
125+ appName : String ,
126+ size : DpSize ,
127+ verticalScrollMode : VerticalScrollMode = VerticalScrollMode .Normal
128+ ) {
129+ if (data.size == 1 ) {
130+ // If there's only 1 item (like in the widget preview), render with fillMaxSize to
131+ // bypass LazyColumn measurement issues where the generated widget preview item doesn't
132+ // fill the widget bounds.
133+ GalleryItemCard (
134+ item = data[0 ],
135+ isSmall = isSmall,
136+ appName = appName,
137+ modifier = GlanceModifier .fillMaxSize()
138+ )
139+ } else {
140+ val limitedData = data.take(5 )
141+ LazyColumn (
142+ modifier = GlanceModifier .fillMaxSize(),
143+ verticalScrollMode = verticalScrollMode
144+ ) {
145+ items(limitedData, itemId = { item -> item.key.hashCode().toLong() }) { item ->
146+ GalleryItemCard (
147+ item = item,
148+ isSmall = isSmall,
149+ appName = appName,
150+ modifier = GlanceModifier .width(size.width).height(size.height)
151+ )
108152 }
109153 }
110154 }
@@ -142,9 +186,7 @@ private fun GalleryItemCard(
142186 modifier = GlanceModifier
143187 .fillMaxWidth()
144188 // Implementing a partial gradient scrim by applying a background modifier directly
145- // to a text Column, shown here, results in the gradient stretching to fill the
146- // entire widget. You can work around this by using an independent sibling Image
147- // with a hardcoded height (100.dp) to restrict a gradient to the bottom.
189+ // to a text Column results in the gradient stretching to fill the entire widget.
148190 .background(ImageProvider (R .drawable.sample_scrim_gradient))
149191 .padding(WidgetTextDimensions .widgetPadding),
150192 verticalAlignment = Alignment .Bottom ,
0 commit comments