Skip to content

Commit 19fc430

Browse files
authored
Merge pull request #187 from vighnesh153/main
feat: update lib versions and replace TvLazyRow with LazyRow
2 parents ecb0909 + 9176d9d commit 19fc430

8 files changed

+80
-45
lines changed

TvMaterialCatalog/app/build.gradle.kts

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ dependencies {
5151
implementation(libs.core.ktx)
5252
implementation(libs.appcompat)
5353
implementation(platform(libs.compose.bom))
54+
implementation(libs.ui)
55+
implementation(libs.foundation)
5456
implementation(libs.lifecycle.runtime.ktx)
5557
implementation(libs.activity.compose)
5658
implementation(libs.tv.foundation)
5759
implementation(libs.tv.material)
5860
implementation(libs.coil.compose)
5961
implementation(libs.navigation.compose)
60-
implementation(libs.compose.ui)
61-
implementation(libs.compose.foundation)
62-
}
62+
}

TvMaterialCatalog/app/src/main/java/com/google/tv/material/catalog/FontScaleAndLayoutDirectionSelector.kt

+10-8
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ fun FontScaleAndLayoutDirectionSelector(
116116
selected = isSelected,
117117
onClick = { onLayoutDirectionChange(it.direction) },
118118
modifier = Modifier.semantics(mergeDescendants = true) { },
119+
headlineContent = {
120+
Text(text = it.title)
121+
},
119122
leadingContent = {
120123
Icon(
121124
painter = painterResource(id = it.icon),
@@ -126,10 +129,8 @@ fun FontScaleAndLayoutDirectionSelector(
126129
RadioButton(
127130
selected = isSelected,
128131
onClick = { })
129-
},
130-
headlineContent = {
131-
Text(text = it.title)
132-
})
132+
}
133+
)
133134
}
134135
}
135136
}
@@ -160,6 +161,9 @@ fun FontScaleAndLayoutDirectionSelector(
160161
selected = isSelected,
161162
onClick = { onFontScaleChange(it.scale) },
162163
modifier = Modifier.semantics(mergeDescendants = true) { },
164+
headlineContent = {
165+
Text(text = it.title)
166+
},
163167
leadingContent = {
164168
Icon(
165169
painter = painterResource(id = R.drawable.ic_font_scale),
@@ -170,10 +174,8 @@ fun FontScaleAndLayoutDirectionSelector(
170174
RadioButton(
171175
selected = isSelected,
172176
onClick = { })
173-
},
174-
headlineContent = {
175-
Text(text = it.title)
176-
})
177+
}
178+
)
177179
}
178180
}
179181
}

TvMaterialCatalog/app/src/main/java/com/google/tv/material/catalog/PositionFocusedItemInLazyLayout.kt

+24-21
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.compose.foundation.gestures.BringIntoViewSpec
55
import androidx.compose.foundation.gestures.LocalBringIntoViewSpec
66
import androidx.compose.runtime.Composable
77
import androidx.compose.runtime.CompositionLocalProvider
8+
import androidx.compose.runtime.remember
89

910
@OptIn(ExperimentalFoundationApi::class)
1011
@Composable
@@ -14,32 +15,34 @@ fun PositionFocusedItemInLazyLayout(
1415
content: @Composable () -> Unit,
1516
) {
1617
// This bring-into-view spec pivots around the center of the scrollable container
17-
val bringIntoViewSpec = object : BringIntoViewSpec {
18-
override fun calculateScrollDistance(
19-
// Initial position of item requesting focus
20-
offset: Float,
21-
// Size of item requesting focus
22-
size: Float,
23-
// Size of the lazy container
24-
containerSize: Float
25-
): Float {
26-
val childSmallerThanParent = size <= containerSize
27-
val initialTargetForLeadingEdge =
28-
parentFraction * containerSize - (childFraction * size)
29-
val spaceAvailableToShowItem = containerSize - initialTargetForLeadingEdge
18+
val bringIntoViewSpec = remember(parentFraction, childFraction) {
19+
object : BringIntoViewSpec {
20+
override fun calculateScrollDistance(
21+
// initial position of item requesting focus
22+
offset: Float,
23+
// size of item requesting focus
24+
size: Float,
25+
// size of the lazy container
26+
containerSize: Float
27+
): Float {
28+
val childSmallerThanParent = size <= containerSize
29+
val initialTargetForLeadingEdge =
30+
parentFraction * containerSize - (childFraction * size)
31+
val spaceAvailableToShowItem = containerSize - initialTargetForLeadingEdge
3032

31-
val targetForLeadingEdge =
32-
if (childSmallerThanParent && spaceAvailableToShowItem < size) {
33-
containerSize - size
34-
} else {
35-
initialTargetForLeadingEdge
36-
}
33+
val targetForLeadingEdge =
34+
if (childSmallerThanParent && spaceAvailableToShowItem < size) {
35+
containerSize - size
36+
} else {
37+
initialTargetForLeadingEdge
38+
}
3739

38-
return offset - targetForLeadingEdge
40+
return offset - targetForLeadingEdge
41+
}
3942
}
4043
}
4144

42-
// LocalBringIntoViewSpec will apply to all scrollables in the hierarchy
45+
// LocalBringIntoViewSpec will apply to all scrollables in the hierarchy.
4346
CompositionLocalProvider(
4447
LocalBringIntoViewSpec provides bringIntoViewSpec,
4548
content = content,

TvMaterialCatalog/app/src/main/java/com/google/tv/material/catalog/ThemeAndColorModeSelector.kt

+10-8
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ fun ThemeAndColorModeSelector(
114114
selected = isSelected,
115115
onClick = { onThemeModeChange(it.mode) },
116116
modifier = Modifier.semantics(mergeDescendants = true) { },
117+
headlineContent = {
118+
Text(text = it.title)
119+
},
117120
leadingContent = {
118121
Icon(
119122
painter = painterResource(id = it.icon),
@@ -124,10 +127,8 @@ fun ThemeAndColorModeSelector(
124127
RadioButton(
125128
selected = isSelected,
126129
onClick = { })
127-
},
128-
headlineContent = {
129-
Text(text = it.title)
130-
})
130+
}
131+
)
131132
}
132133
}
133134
}
@@ -158,6 +159,9 @@ fun ThemeAndColorModeSelector(
158159
selected = isSelected,
159160
onClick = { onSeedColorChange(it) },
160161
modifier = Modifier.semantics(mergeDescendants = true) { },
162+
headlineContent = {
163+
Text(text = it.name)
164+
},
161165
leadingContent = {
162166
Box(
163167
modifier = Modifier
@@ -169,10 +173,8 @@ fun ThemeAndColorModeSelector(
169173
RadioButton(
170174
selected = isSelected,
171175
onClick = { })
172-
},
173-
headlineContent = {
174-
Text(text = it.name)
175-
})
176+
}
177+
)
176178
}
177179
}
178180
}

TvMaterialCatalog/app/src/main/java/com/google/tv/material/catalog/screens/CardsScreen.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fun CardsScreen() {
3232
modifier = Modifier.width(180.dp),
3333
imageCard = {
3434
Card(
35-
onClick = {},
35+
onClick = { },
3636
interactionSource = it,
3737
colors = CardDefaults.colors(containerColor = Color.Transparent)
3838
) {

TvMaterialCatalog/app/src/main/java/com/google/tv/material/catalog/screens/ColorsScreen.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import androidx.tv.material3.Text
2424
@Composable
2525
fun ColorsScreen() {
2626
Row(
27-
Modifier.fillMaxSize().padding(start = 58.dp, end = 48.dp, top = 8.dp),
27+
Modifier
28+
.fillMaxSize()
29+
.padding(start = 58.dp, end = 48.dp, top = 8.dp),
2830
horizontalArrangement = Arrangement.spacedBy(20.dp)
2931
) {
3032
LazyVerticalGrid(

TvMaterialCatalog/app/src/main/java/com/google/tv/material/catalog/screens/ImmersiveListScreen.kt

+25-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fun ImmersiveListScreen() {
117117
fullWidth = it.size.width.toDp().value
118118
}
119119
},
120-
contentPadding = PaddingValues(start = 58.dp, end = 46.dp),
120+
contentPadding = PaddingValues(start = 58.dp),
121121
horizontalArrangement = Arrangement.spacedBy(20.dp)
122122
) {
123123
itemsIndexed(immersiveListItems) { index, card ->
@@ -179,6 +179,30 @@ private val immersiveListItems = listOf(
179179
description = description,
180180
image = R.drawable.fc_4,
181181
),
182+
ImmersiveListSlide(
183+
title = "Shadow Hunter",
184+
subtitle = "Secondary · text",
185+
description = description,
186+
image = R.drawable.fc_1,
187+
),
188+
ImmersiveListSlide(
189+
title = "Super Puppy",
190+
subtitle = "Secondary · text",
191+
description = description,
192+
image = R.drawable.fc_2,
193+
),
194+
ImmersiveListSlide(
195+
title = "Man with a cape",
196+
subtitle = "Secondary · text",
197+
description = description,
198+
image = R.drawable.fc_3,
199+
),
200+
ImmersiveListSlide(
201+
title = "Power Sisters",
202+
subtitle = "Secondary · text",
203+
description = description,
204+
image = R.drawable.fc_4,
205+
),
182206
)
183207

184208
private data class ImmersiveListSlide(

TvMaterialCatalog/gradle/libs.versions.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ tv-foundation = "1.0.0-alpha11"
1010
tv-material = "1.0.0"
1111
lifecycle-runtime-ktx = "2.8.7"
1212
activity-compose = "1.9.3"
13+
foundation = "1.7.0-beta07"
14+
ui = "1.7.0-beta07"
1315

1416
[libraries]
1517
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil-compose" }
1618
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" }
1719
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
1820
compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "compose-bom" }
21+
foundation = { module = "androidx.compose.foundation:foundation", version.ref = "foundation" }
1922
navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigation-compose" }
2023
tv-foundation = { group = "androidx.tv", name = "tv-foundation", version.ref = "tv-foundation" }
2124
tv-material = { group = "androidx.tv", name = "tv-material", version.ref = "tv-material" }
2225
lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycle-runtime-ktx" }
2326
activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activity-compose" }
24-
compose-ui = { group = 'androidx.compose.ui', name = 'ui', version = "1.7.5" }
25-
compose-foundation = { group = 'androidx.compose.foundation', name = 'foundation', version = "1.7.5" }
27+
ui = { module = "androidx.compose.ui:ui", version.ref = "ui" }
2628

2729
[plugins]
2830
androidApplication = { id = "com.android.application", version.ref = "agp" }

0 commit comments

Comments
 (0)