-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update lib versions and replace TvLazyRow with LazyRow
- Loading branch information
1 parent
a6ca5ff
commit 4539569
Showing
10 changed files
with
182 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...talog/app/src/main/java/com/google/tv/material/catalog/PositionFocusedItemInLazyLayout.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.google.tv.material.catalog | ||
|
||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
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 | ||
fun PositionFocusedItemInLazyLayout( | ||
parentFraction: Float = 0.3f, | ||
childFraction: Float = 0f, | ||
content: @Composable () -> Unit, | ||
) { | ||
// a bring into view spec that pivots around the center of the scrollable container | ||
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 | ||
} | ||
|
||
return offset - targetForLeadingEdge | ||
} | ||
} | ||
} | ||
|
||
// LocalBringIntoViewSpec will apply to all scrollables in the hierarchy. | ||
CompositionLocalProvider( | ||
LocalBringIntoViewSpec provides bringIntoViewSpec, | ||
content = content, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.