horologist
horologist copied to clipboard
Tile previews show the incorrect icon

@WearSmallRoundDevicePreview
@Composable
fun WorkoutButtons() {
val context = LocalContext.current
LayoutRootPreview(
Workout.buttonsLayout(
context,
context.deviceParams(),
button1Clickable = emptyClickable,
button2Clickable = emptyClickable,
button3Clickable = emptyClickable,
chipClickable = emptyClickable,
)
) {
addIdToImageMapping(Workout.BUTTON_1_ICON_ID, drawableResToImageResource(R.drawable.ic_run_24))
addIdToImageMapping(Workout.BUTTON_2_ICON_ID, drawableResToImageResource(R.drawable.ic_yoga_24))
addIdToImageMapping(Workout.BUTTON_3_ICON_ID, drawableResToImageResource(R.drawable.ic_cycling_24))
}
}
object Workout {
val BUTTON_1_ICON_ID = "1"
val BUTTON_2_ICON_ID = "2"
val BUTTON_3_ICON_ID = "3"
fun buttonsLayout(
context: Context,
deviceParameters: DeviceParameters,
button1Clickable: Clickable,
button2Clickable: Clickable,
button3Clickable: Clickable,
chipClickable: Clickable
) =
PrimaryLayout.Builder(deviceParameters)
.setPrimaryLabelTextContent(
Text.Builder(context, "1 run this week")
.setTypography(Typography.TYPOGRAPHY_CAPTION1)
.setColor(ColorBuilders.argb(GoldenTilesColors.Blue))
.build()
)
.setContent(
MultiButtonLayout.Builder()
.addButtonContent(
Button.Builder(context, button1Clickable).setIconContent(BUTTON_1_ICON_ID)
.build()
)
.addButtonContent(
Button.Builder(context, button2Clickable).setIconContent(BUTTON_2_ICON_ID)
.build()
)
.addButtonContent(
Button.Builder(context, button3Clickable).setIconContent(BUTTON_3_ICON_ID)
.build()
)
.build()
)
.setPrimaryChipContent(
CompactChip.Builder(context, "More", chipClickable, deviceParameters)
.setChipColors(
ChipColors(
/*backgroundColor=*/ ColorBuilders.argb(GoldenTilesColors.BlueGray),
/*contentColor=*/ ColorBuilders.argb(GoldenTilesColors.White)
)
)
.build()
)
.build()
}
If I use setVersion("")
and rebuild, then it fixes itself (and I can remove the setVersion()
):
...
) {
setVersion("")
addIdToImageMapping(Workout.BUTTON_1_ICON_ID, drawableResToImageResource(R.drawable.ic_run_24))
addIdToImageMapping(Workout.BUTTON_2_ICON_ID, drawableResToImageResource(R.drawable.ic_yoga_24))
addIdToImageMapping(Workout.BUTTON_3_ICON_ID, drawableResToImageResource(R.drawable.ic_cycling_24))
}
}
I guess this is because of the PERMANENT_RESOURCES_VERSION
in LayoutRootPreview
.
For previews, maybe we could increment it every time we recompose, since the purpose is rapid iteration, and it's reasonable to assume that the users will be changing the icons associated with a resource ID (because of copy and pasting/placeholders).
Haven't seen recently. @ataulm open if still an issue.