I would like to request the compose team for a fra...
# compose
t
I would like to request the compose team for a fractional layout modifier. Its works better than LayoutOffset because I don't have to manager pixels. Its make sense?
Copy code
data class LayoutFractional(val dx: Float, val dy: Float) : LayoutModifier {
    override fun ModifierScope.modifyPosition(
        childSize: IntPxSize,
        containerSize: IntPxSize
    ): IntPxPosition = IntPxPosition(
        x = childSize.width * dx.coerceIn(MIN_FRACTION, MAX_FRACTION) *
                if (layoutDirection == LayoutDirection.Ltr) MAX_FRACTION else MIN_FRACTION,
        y = childSize.height * dy.coerceIn(MIN_FRACTION, MAX_FRACTION)
    )

    companion object {
        private const val MAX_FRACTION = 1f
        private const val MIN_FRACTION = -1f

        val Origin = LayoutFractional(0f, 0f)
    }
}
a
Why restrict it from -1 to 1? Seems like multiples would be valid
t
Restricted because I would like to let user to set range between [-1, 1] only.
a
I ask because we would not apply that restriction if we added something like this upstream to make it more general purpose 🙂
t
Its make sense. I restricted because the name "Fractional" means a range 0%..100% for me.
Thanks @Adam Powell . Removing the restriction really increase the possibilities. Will Compose have something like that in next versions?
a
Probably not the next version since the next version is cut tomorrow and I'm working on some other major modifier-related changes first, but it seems potentially useful
👍 1
🍾 1
m
I am not completely sold that this is a general enough modifier to merge it in compose
Unless you meant computing x and y as fraction of
containerSize - childSize
? In this case I agree it would make sense to have it
Probably without the MAX_FRACTION and MIN_FRACTION coercing though, as Adam suggested
t
Yes, @Mihai Popa, I have applied the Adam suggestions and its make sense. And about merge, I aggre that only if have a general purpose. For me was easier to use something like that instead of works with pixels using LayoutOffset. https://github.com/programadorthi/compose-weather-forecast/blob/02884a698153a7cd0b81df7472bee26ca2e92829/app/src/main/java/br/com/programadorthi/compose/helpers/modifiers.kt#L21