https://kotlinlang.org logo
#compose
Title
# compose
h

Halil Ozercan

07/14/2020, 10:41 PM
I came across a possible bug related to
IconButton
and
Icon
. I'm developing a VideoPlayer fully written in Compose and wanted to add on-screen play/pause button. These icons need to be differentiable on video, so that I chose to use white for icon colors and draw shadow around them. Code looks something like this
Copy code
IconButton(
    onClick = {
        mediaPlayer.toggle()
        playButtonUiState = mediaPlayer.isPlaying
    }
) {
    Icon(
        asset = if (playButtonUiState) Icons.Filled.Pause else Icons.Filled.PlayArrow,
        modifier = Modifier.drawShadow(elevation = 2.dp)
    )
}
Without shadow, everything seems like to work. State changes and icon is updated when clicked on the button. However, when I add shadow as in the example, icon stops changing. Functionality works but icon gets fixed to
Pause
. Is there something wrong with my code or is this might be a bug?
t

Timo Drick

07/14/2020, 10:58 PM
I am not sure if it is a bug. But i had the same issue and a work around is to define two different Icon() elements:
Copy code
if (playButtonUiState)
   Icon(
        asset =  Icons.Filled.Pause,
        modifier = Modifier.drawShadow(elevation = 2.dp)
    )
else
   Icon(
        asset = Icons.Filled.PlayArrow,
        modifier = Modifier.drawShadow(elevation = 2.dp)
    )
c

Chuck Jazdzewski [G]

07/14/2020, 11:29 PM
@Halil Ozercan Can you please submit this as a bug? If @Timo Drick work-arounds works for you then this is indeed a bug.
h

Halil Ozercan

07/15/2020, 7:40 AM
Thanks @Timo Drick, the work-around works, although the shadow from elevation is not what I was looking for 🙂 Where should I submit the bug?
t

Timo Drick

07/15/2020, 9:05 AM
You can find the link in the header of the #compose channel https://issuetracker.google.com/issues?q=componentid:612128
👍 1
n

Nader Jawad

07/22/2020, 5:46 AM
Thanks for filing that ticket @Timo Drick. Just to confirm, which release of compose did you see this behavior? It might have been addressed in a more recent release. I verified the same sample code above with the alternating play/pause buttons and it seemed to switch between the 2 as expected.
t

Timo Drick

07/22/2020, 9:19 AM
@Nader Jawad i did not filed a bug. I had this issue in an earlier version of compose. Did not tried in version dev14.
h

Halil Ozercan

07/22/2020, 9:34 AM
Hey @Nader Jawad, @Timo Drick, I actually filed the bug 2 days ago. Yesterday I also provided a screen recording showing the bug in action. In that recording, the version is also visible in the last 5 seconds as
dev14
4 Views