Skip to content

Instantly share code, notes, and snippets.

@ataulm
Last active January 23, 2022 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ataulm/a24fc121c92be9553b9bc1a1e25c78c9 to your computer and use it in GitHub Desktop.
Save ataulm/a24fc121c92be9553b9bc1a1e25c78c9 to your computer and use it in GitHub Desktop.
@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