Do we have something for when we want to use one v...
# compose
c
Do we have something for when we want to use one value for Preview and another one for Build?
y
You can provide any params you want for @previews
c
Copy code
class BaseDimensions  {
    companion object {
//        TODO("The commented lines should be used for real devices and their replacements are there to use Compose Preview")
        private const val testingWidth = 1440
        private const val testingDensity = 3.5f
//        private val displayMetrics = Common.appContext.resources.displayMetrics
        internal const val boardSize = 9
        private const val tilePaddingLeftRight = 4
        val tileSize =
//            (((displayMetrics.widthPixels / displayMetrics.density) - ((boardSize + 1) * tilePaddingLeftRight)) / boardSize).dp
            (((testingWidth / testingDensity) - ((boardSize + 1) * tilePaddingLeftRight)) / boardSize).dp
    }
}
Here, when using preview, appContext wasn’t provided yet, so, if I’m not using regular builds, I need to comment everything and provide temporary values, which is kind of unpractical the way I’m doing
I was hoping for something like if(Compose) X else Y
j
If the state of your composables is properly hoistable, there is no reason for such a conditional. Moreover, such a conditional would inevitably lead to your previews that do not correctly demonstrate the expected/proper usage/behavior of your composables. The lack of such a conditional is very intentional, as it encourages you to more properly design your composable.
c
True about the proper expected behavior. Problem is that I'm dinamicaly sitting up my composables and I need window width. I tried other methods which ended in a messy ping ponging of updates a re-renders. The cleanest wya I found to dinamicaly draw my board was to previwsly know my screen width. Problem with this is thst I need context. I found a method with a provider but the way this is initialized probably makes it not available when preview tries to use it and then I have a null. This values yes are unriliable but they allow me to test the app without running it on a device every time.