-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to latest compose stable versions (#1113)
- Loading branch information
1 parent
16a4ff0
commit d8b6f99
Showing
31 changed files
with
2,466 additions
and
24,685 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
50 changes: 50 additions & 0 deletions
50
app-tv/src/main/kotlin/app/ss/tv/presentation/extentions/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 app.ss.tv.presentation.extentions | ||
|
||
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.07f, | ||
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
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.