Skip to content

Commit

Permalink
Merge pull request #187 from vighnesh153/main
Browse files Browse the repository at this point in the history
feat: update lib versions and replace TvLazyRow with LazyRow
  • Loading branch information
pflammertsma authored Jan 22, 2025
2 parents ecb0909 + 9176d9d commit 19fc430
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 45 deletions.
6 changes: 3 additions & 3 deletions TvMaterialCatalog/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ dependencies {
implementation(libs.core.ktx)
implementation(libs.appcompat)
implementation(platform(libs.compose.bom))
implementation(libs.ui)
implementation(libs.foundation)
implementation(libs.lifecycle.runtime.ktx)
implementation(libs.activity.compose)
implementation(libs.tv.foundation)
implementation(libs.tv.material)
implementation(libs.coil.compose)
implementation(libs.navigation.compose)
implementation(libs.compose.ui)
implementation(libs.compose.foundation)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ fun FontScaleAndLayoutDirectionSelector(
selected = isSelected,
onClick = { onLayoutDirectionChange(it.direction) },
modifier = Modifier.semantics(mergeDescendants = true) { },
headlineContent = {
Text(text = it.title)
},
leadingContent = {
Icon(
painter = painterResource(id = it.icon),
Expand All @@ -126,10 +129,8 @@ fun FontScaleAndLayoutDirectionSelector(
RadioButton(
selected = isSelected,
onClick = { })
},
headlineContent = {
Text(text = it.title)
})
}
)
}
}
}
Expand Down Expand Up @@ -160,6 +161,9 @@ fun FontScaleAndLayoutDirectionSelector(
selected = isSelected,
onClick = { onFontScaleChange(it.scale) },
modifier = Modifier.semantics(mergeDescendants = true) { },
headlineContent = {
Text(text = it.title)
},
leadingContent = {
Icon(
painter = painterResource(id = R.drawable.ic_font_scale),
Expand All @@ -170,10 +174,8 @@ fun FontScaleAndLayoutDirectionSelector(
RadioButton(
selected = isSelected,
onClick = { })
},
headlineContent = {
Text(text = it.title)
})
}
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.gestures.BringIntoViewSpec
import androidx.compose.foundation.gestures.LocalBringIntoViewSpec
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember

@OptIn(ExperimentalFoundationApi::class)
@Composable
Expand All @@ -14,32 +15,34 @@ fun PositionFocusedItemInLazyLayout(
content: @Composable () -> Unit,
) {
// This bring-into-view spec pivots around the center of the scrollable container
val bringIntoViewSpec = object : BringIntoViewSpec {
override fun calculateScrollDistance(
// Initial position of item requesting focus
offset: Float,
// Size of item requesting focus
size: Float,
// Size of the lazy container
containerSize: Float
): Float {
val childSmallerThanParent = size <= containerSize
val initialTargetForLeadingEdge =
parentFraction * containerSize - (childFraction * size)
val spaceAvailableToShowItem = containerSize - initialTargetForLeadingEdge
val bringIntoViewSpec = remember(parentFraction, childFraction) {
object : BringIntoViewSpec {
override fun calculateScrollDistance(
// initial position of item requesting focus
offset: Float,
// size of item requesting focus
size: Float,
// size of the lazy container
containerSize: Float
): Float {
val childSmallerThanParent = size <= containerSize
val initialTargetForLeadingEdge =
parentFraction * containerSize - (childFraction * size)
val spaceAvailableToShowItem = containerSize - initialTargetForLeadingEdge

val targetForLeadingEdge =
if (childSmallerThanParent && spaceAvailableToShowItem < size) {
containerSize - size
} else {
initialTargetForLeadingEdge
}
val targetForLeadingEdge =
if (childSmallerThanParent && spaceAvailableToShowItem < size) {
containerSize - size
} else {
initialTargetForLeadingEdge
}

return offset - targetForLeadingEdge
return offset - targetForLeadingEdge
}
}
}

// LocalBringIntoViewSpec will apply to all scrollables in the hierarchy
// LocalBringIntoViewSpec will apply to all scrollables in the hierarchy.
CompositionLocalProvider(
LocalBringIntoViewSpec provides bringIntoViewSpec,
content = content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ fun ThemeAndColorModeSelector(
selected = isSelected,
onClick = { onThemeModeChange(it.mode) },
modifier = Modifier.semantics(mergeDescendants = true) { },
headlineContent = {
Text(text = it.title)
},
leadingContent = {
Icon(
painter = painterResource(id = it.icon),
Expand All @@ -124,10 +127,8 @@ fun ThemeAndColorModeSelector(
RadioButton(
selected = isSelected,
onClick = { })
},
headlineContent = {
Text(text = it.title)
})
}
)
}
}
}
Expand Down Expand Up @@ -158,6 +159,9 @@ fun ThemeAndColorModeSelector(
selected = isSelected,
onClick = { onSeedColorChange(it) },
modifier = Modifier.semantics(mergeDescendants = true) { },
headlineContent = {
Text(text = it.name)
},
leadingContent = {
Box(
modifier = Modifier
Expand All @@ -169,10 +173,8 @@ fun ThemeAndColorModeSelector(
RadioButton(
selected = isSelected,
onClick = { })
},
headlineContent = {
Text(text = it.name)
})
}
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fun CardsScreen() {
modifier = Modifier.width(180.dp),
imageCard = {
Card(
onClick = {},
onClick = { },
interactionSource = it,
colors = CardDefaults.colors(containerColor = Color.Transparent)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import androidx.tv.material3.Text
@Composable
fun ColorsScreen() {
Row(
Modifier.fillMaxSize().padding(start = 58.dp, end = 48.dp, top = 8.dp),
Modifier
.fillMaxSize()
.padding(start = 58.dp, end = 48.dp, top = 8.dp),
horizontalArrangement = Arrangement.spacedBy(20.dp)
) {
LazyVerticalGrid(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fun ImmersiveListScreen() {
fullWidth = it.size.width.toDp().value
}
},
contentPadding = PaddingValues(start = 58.dp, end = 46.dp),
contentPadding = PaddingValues(start = 58.dp),
horizontalArrangement = Arrangement.spacedBy(20.dp)
) {
itemsIndexed(immersiveListItems) { index, card ->
Expand Down Expand Up @@ -179,6 +179,30 @@ private val immersiveListItems = listOf(
description = description,
image = R.drawable.fc_4,
),
ImmersiveListSlide(
title = "Shadow Hunter",
subtitle = "Secondary · text",
description = description,
image = R.drawable.fc_1,
),
ImmersiveListSlide(
title = "Super Puppy",
subtitle = "Secondary · text",
description = description,
image = R.drawable.fc_2,
),
ImmersiveListSlide(
title = "Man with a cape",
subtitle = "Secondary · text",
description = description,
image = R.drawable.fc_3,
),
ImmersiveListSlide(
title = "Power Sisters",
subtitle = "Secondary · text",
description = description,
image = R.drawable.fc_4,
),
)

private data class ImmersiveListSlide(
Expand Down
6 changes: 4 additions & 2 deletions TvMaterialCatalog/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ tv-foundation = "1.0.0-alpha11"
tv-material = "1.0.0"
lifecycle-runtime-ktx = "2.8.7"
activity-compose = "1.9.3"
foundation = "1.7.0-beta07"
ui = "1.7.0-beta07"

[libraries]
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil-compose" }
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" }
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "compose-bom" }
foundation = { module = "androidx.compose.foundation:foundation", version.ref = "foundation" }
navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigation-compose" }
tv-foundation = { group = "androidx.tv", name = "tv-foundation", version.ref = "tv-foundation" }
tv-material = { group = "androidx.tv", name = "tv-material", version.ref = "tv-material" }
lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycle-runtime-ktx" }
activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activity-compose" }
compose-ui = { group = 'androidx.compose.ui', name = 'ui', version = "1.7.5" }
compose-foundation = { group = 'androidx.compose.foundation', name = 'foundation', version = "1.7.5" }
ui = { module = "androidx.compose.ui:ui", version.ref = "ui" }

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

0 comments on commit 19fc430

Please sign in to comment.