Last active
January 23, 2022 09:22
-
-
Save ataulm/a24fc121c92be9553b9bc1a1e25c78c9 to your computer and use it in GitHub Desktop.
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
@Composable | |
fun Track( | |
trackInfo: TrackInfo, | |
isPlaying: Boolean, | |
playAction: () -> Unit, | |
pauseAction: () -> Unit, | |
moreAction: () -> Unit, | |
modifier: Modifier = Modifier | |
) { | |
Row( | |
modifier.clearAndSetSemantics { | |
contentDescription = "${trackInfo.name}, ${trackInfo.artist}, ${trackInfo.length}" | |
stateDescription = if (isPlaying) "is playing" else null | |
customActions = trackInfo.createCustomActions( | |
playAction, | |
pauseAction, | |
moreAction | |
) | |
} | |
) { | |
// I've done the semantics tree, you can do the composition tree | |
} | |
} | |
private fun TrackInfo.createCustomActions( | |
playAction: () -> Unit, | |
pauseAction: () -> Unit, | |
moreAction: () -> Unit | |
): List<CustomAccessibilityAction> { | |
val playPauseAction = if (isPlaying) { | |
CustomAccessibilityAction("pause") { pauseAction(); true } | |
} else { | |
CustomAccessibilityAction("play") { playAction(); true } | |
} | |
return listOf( | |
playPauseAction, | |
CustomAccessibilityAction("more") { moreAction(); true } | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment