Found a reproducible(?) case of preview not working. Basically just using a color from a custom them...
c
Found a reproducible(?) case of preview not working. Basically just using a color from a custom theme as a background causes preview to fail. Code in thread. Stacktrace snippet:
Copy code
Render Problem
java.lang.IllegalStateException: No RollerToasterColorPalette provided   at com.rollertoaster.app.theme.ThemeKt$AmbientRollerToasterColors$1.invok
Fails:
Copy code
@Preview
@Composable
fun MyPrev() {
    Column(
        modifier = Modifier
            .background(color = RollerToasterTheme.colors.main_1)
            .fillMaxWidth(1F)
    ) {
        Text("asdf")
    }
}
Works:
Copy code
@Preview
@Composable
fun MyPrev() {
    Column(
        modifier = Modifier
            .fillMaxWidth(1F)
    ) {
        Text("asdf")
    }
}
a
You can't expect your theme to work if you don't include the theme composable in the preview.
c
Oof. For some reason... I did not know what. I feel like that maybe shouldn't compile or something? Idk. I understand it's valid code and so having it compile makes sense, but I totally did not get the feeling that I had to wrap it in my theme. I guess I haven't wrapped any of my previews in my theme
j
This is one of the reasons you should avoid ambients - they create implicit dependencies that aren't tracked by the compiler. Of course, they're a little hard to avoid when material theme is an ambient 😔. But as a general rule. This is actually one of the less-bad failures; sometimes the issues are a lot more subtle. I pushed pretty hard for ambients to be tracked by the compiler. Maybe some day we will have a different feature which provides similar capabilities but is more safe in a variety of ways.
💯 2
c
Yes right now functions shown in Preview need the app themes to be included/wrapped since otherwise it defaults to MaterialTheme. We've considered how to make this clearer but haven't resolved it yet.
c
@Chris Sinco [G] is there an issue I can star?
c
I can’t seem to find it on the public tracker as a feature request, so if you can, please file it to this component on Issue Tracker: Compose Preview
c
Compose Preview is locked btw @Chris Sinco [G] But filed here: https://issuetracker.google.com/issues/184759538
c
Fun 🙂 Alright let me triage - thanks for filing!
👍 1