Use case description
I have integrated androidx.media3.cast.MediaRouteButton into my Compose UI. The problem is that my UI hides when user does not interact with it (traditional video controls). When user taps on a cast icon then cast dialog is shown. If user does not interact with it then video controls disappear including the dialog. Currently there is no way to tell if dialog is shown since showDialog it is hidden in lib function.
@MainThread
@UnstableApi
@Composable
fun MediaRouteButton(modifier: Modifier = Modifier) {
CastUtils.verifyMainThread()
MediaRouteButtonContainer() {
var showDialog by remember { mutableStateOf(false) }
IconButton(onClick = { showDialog = true }, modifier) { mediaRouteButtonIcon() }
if (showDialog) {
MediaRouteDialog { showDialog = false }
}
}
}
Proposed solution
I'd prefer to have an observable that tells me if dialog is shown so I can stop my local timer.
@MainThread
@UnstableApi
@Composable
fun MediaRouteButton(
modifier: Modifier = Modifier,
state: MediaRouteState = rememberMediaRouteState()
) {
CastUtils.verifyMainThread()
MediaRouteButtonContainer {
IconButton(
onClick = { state.showDialog() },
modifier = modifier
) {
mediaRouteButtonIcon()
}
if (state.isShowingDialog) {
MediaRouteDialog(onDismissRequest = { state.dismissDialog() })
}
}
}
@Stable
class MediaRouteState {
var isShowingDialog by mutableStateOf(false)
private set
internal fun showDialog() {
isShowingDialog = true
}
internal fun dismissDialog() {
isShowingDialog = false
}
}
@Composable
fun rememberMediaRouteState(): MediaRouteState {
return remember { MediaRouteState() }
}
Use case description
I have integrated
androidx.media3.cast.MediaRouteButtoninto my Compose UI. The problem is that my UI hides when user does not interact with it (traditional video controls). When user taps on a cast icon then cast dialog is shown. If user does not interact with it then video controls disappear including the dialog. Currently there is no way to tell if dialog is shown sinceshowDialogit is hidden in lib function.Proposed solution
I'd prefer to have an observable that tells me if dialog is shown so I can stop my local timer.