-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e935792
commit c16fd9d
Showing
3 changed files
with
53 additions
and
8 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
39 changes: 39 additions & 0 deletions
39
app/src/main/kotlin/nl/ndat/tvlauncher/ui/indication/scale.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,39 @@ | ||
package nl.ndat.tvlauncher.ui.indication | ||
|
||
import androidx.compose.animation.core.animateFloatAsState | ||
import androidx.compose.foundation.Indication | ||
import androidx.compose.foundation.IndicationInstance | ||
import androidx.compose.foundation.interaction.FocusInteraction | ||
import androidx.compose.foundation.interaction.InteractionSource | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.graphics.drawscope.ContentDrawScope | ||
import androidx.compose.ui.graphics.drawscope.scale | ||
|
||
private class ScaleIndicationInstance( | ||
private val scale: Float, | ||
) : IndicationInstance { | ||
override fun ContentDrawScope.drawIndication() { | ||
scale(scale) { | ||
this@drawIndication.drawContent() | ||
} | ||
} | ||
} | ||
|
||
class FocusScaleIndication( | ||
private val focusedScale: Float, | ||
) : Indication { | ||
@Composable | ||
override fun rememberUpdatedInstance(interactionSource: InteractionSource): IndicationInstance { | ||
val interaction by interactionSource.interactions.collectAsState(initial = null) | ||
val currentScale = when (interaction) { | ||
is FocusInteraction.Focus -> focusedScale | ||
else -> 1.0f | ||
} | ||
|
||
val scale by animateFloatAsState(currentScale) | ||
return remember(scale) { ScaleIndicationInstance(scale) } | ||
} | ||
} |