Skip to content

Commit

Permalink
update: rowFR.saveFocusedChild() & modifier.focusGroup()
Browse files Browse the repository at this point in the history
  • Loading branch information
muedsa committed Dec 10, 2024
1 parent 253a7d9 commit ef2b32b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions app/src/main/kotlin/com/muedsa/compose/tv/widget/ImageCardsRow.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.muedsa.compose.tv.widget

import androidx.compose.foundation.focusGroup
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
Expand All @@ -15,6 +16,8 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.FocusRequester.Companion.FocusRequesterFactory.component1
import androidx.compose.ui.focus.FocusRequester.Companion.FocusRequesterFactory.component2
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.focusRestorer
import androidx.compose.ui.graphics.Color
Expand Down Expand Up @@ -50,7 +53,7 @@ fun <T> ImageCardsRow(

val (rowFR, firstItemFR) = remember { FocusRequester.createRefs() }

Column(modifier) {
Column(modifier.focusGroup()) {
Text(
modifier = Modifier.padding(start = ImageCardRowCardPadding),
text = title,
Expand Down Expand Up @@ -86,7 +89,10 @@ fun <T> ImageCardsRow(
type = CardType.COMPACT,
model = contentFn(index, it),
onItemFocus = { onItemFocus(index, it) },
onItemClick = { onItemClick(index, it) }
onItemClick = {
rowFR.saveFocusedChild()
onItemClick(index, it)
}
)
}
}
Expand Down Expand Up @@ -120,7 +126,7 @@ fun <T> StandardImageCardsRow(
}) ImageCardRowCardPadding - CardContentPadding
else ImageCardRowCardPadding

Column(modifier) {
Column(modifier.focusGroup()) {
Text(
modifier = Modifier.padding(start = ImageCardRowCardPadding),
text = title,
Expand Down Expand Up @@ -156,7 +162,10 @@ fun <T> StandardImageCardsRow(
type = CardType.STANDARD,
model = contentFn(index, it),
onItemFocus = { onItemFocus(index, it) },
onItemClick = { onItemClick(index, it) }
onItemClick = {
rowFR.saveFocusedChild()
onItemClick(index, it)
}
)
}
}
Expand Down

0 comments on commit ef2b32b

Please sign in to comment.