https://kotlinlang.org logo
#compose-android
Title
# compose-android
m

Mark

11/14/2023, 6:14 AM
I recently noticed that including this API34+ unicode category, even though I guard with an API level check:
Copy code
"""\p{InCJK_UNIFIED_IDEOGRAPHS_EXTENSION_H}""".toRegex()
breaks my Compose preview. Is there a way to programmatically check I’m in Compose preview? Note: I’m not using this directly in the composable, so didn’t get any kind of compile time error/warning (though you do get this when using directly)
a

ascii

11/14/2023, 6:16 AM
Is there a way to programmatically check I’m in Compose preview?
LocalInspectionMode.current
m

Mark

11/14/2023, 6:17 AM
Thanks, but I’m not in a composable context either. This code is executed as part of some class initialization
a

ascii

11/14/2023, 6:19 AM
Can you not use that class in Preview? Or change its init based on it? No idea what the underlying issue is.
m

Mark

11/14/2023, 6:23 AM
If you just paste that code into a Preview you get “unknown character category” message and the category is highlighted in red, and the preview breaks. I don’t know if it’s just that the compose preview parser is using some pre 34 API level
2 Views