iamthevoid
05/27/2021, 2:48 PMIcon(
imageVector = with(Icons.Default) { if (isAppDarkTheme()) DateRange else KeyboardArrowRight },
contentDescription = null
)
but if i replace it with resources icon not changing
Icon(
painter = painterResource(id = if (isAppDarkTheme()) R.drawable.ic_checkbox_on_night else R.drawable.ic_checkbox_on_day),
contentDescription = null
)
iamthevoid
05/27/2021, 2:52 PMNeal Sanche
05/27/2021, 2:59 PMisAppDarkTheme()
returning something that compose will know is changing? A state
?Neal Sanche
05/27/2021, 3:01 PMiamthevoid
05/27/2021, 3:01 PMisAppDarkTheme()
returns boolean. Like thisNeal Sanche
05/27/2021, 3:04 PMisSystemInDarkTheme()
once here.iamthevoid
05/27/2021, 3:05 PMdarkLightThemeState
from DARK to LIGHT on button click. And if i use ImageVector instead painterResource icon changesNeal Sanche
05/27/2021, 3:06 PMiamthevoid
05/27/2021, 3:08 PMisAppDarkTheme()
is just a boolean value, not dependent on system anyhow. So i just store resources in drawable
folderiamthevoid
05/27/2021, 3:08 PMiamthevoid
05/27/2021, 3:08 PMNeal Sanche
05/27/2021, 3:09 PMZach Klippenstein (he/him) [MOD]
05/27/2021, 3:19 PMisAppDarkTheme
when you’re expecting it to change? If so, sounds like it might be a bug in Icon
or painterResource
. If that’s the case, figure out if you’re getting a new painter when the value changes, file a bug on the affected component, and you could probably work around it by wrapping your icon with the key
composable.nitrog42
05/27/2021, 3:37 PMIcon(
painter = if (isAppDarkTheme()) painterResource(id = R.drawable.ic_checkbox_on_night) else painterResource(id = R.drawable.ic_checkbox_on_day),
contentDescription = null
)
?iamthevoid
05/27/2021, 4:01 PMZach Klippenstein (he/him) [MOD]
05/27/2021, 4:06 PMprintln("resource: $res")
val painter = painterResource(id = res)
println("painter: $painter")
Icon(painter, …)
That will tell you if the painter is being updated correctly. If not, that’s probably a bug. If it is, then Icon
probably has a bug. Either way, if that’s the issue, you should be able to workaround it by doing:
key(res) {
Icon(painter = painterResource(id = res), …)
}
iamthevoid
05/27/2021, 4:24 PMI/System.out: 2131099749
I/System.out: androidx.compose.ui.graphics.vector.VectorPainter@4d87db1
I/System.out: 2131099748
I/System.out: androidx.compose.ui.graphics.vector.VectorPainter@4d87db1
I/System.out: 2131099749
I/System.out: androidx.compose.ui.graphics.vector.VectorPainter@4d87db1
I/System.out: 2131099748
I/System.out: androidx.compose.ui.graphics.vector.VectorPainter@4d87db1
I/System.out: 2131099749
I/System.out: androidx.compose.ui.graphics.vector.VectorPainter@4d87db1
I/System.out: 2131099748
I/System.out: androidx.compose.ui.graphics.vector.VectorPainter@4d87db1
Chris Sinco [G]
05/27/2021, 5:08 PMChris Sinco [G]
05/27/2021, 5:09 PMImage
instead of Icon
?iamthevoid
05/27/2021, 5:17 PMLouis Pullen-Freilich [G]
05/27/2021, 5:21 PMic_checkbox_on_night
and ic_checkbox_on_day
- is it just a different color?Louis Pullen-Freilich [G]
05/27/2021, 5:22 PMIcon
by default applies a tint color, so the resource might be changing correctly, but Icon
is just always applying a color on top that makes it look like it is the sameiamthevoid
05/27/2021, 5:24 PMLouis Pullen-Freilich [G]
05/27/2021, 5:25 PMIcon
, and set tint = Color.Unspecified
- then this would probably workLouis Pullen-Freilich [G]
05/27/2021, 5:25 PMIcon
, probably easier just to use Image
insteadiamthevoid
05/27/2021, 5:33 PM