bruno.aybar
09/24/2020, 5:16 AMDirectionalAlignment
is a private class? Being able to create an alignment with custom vertical and horizontal bias could be really useful. In my case I need to move a component around, and this seemed like the easiest way:
@Composable
fun Sample {
val offset = animatedFloat(initVal = ...)
onActive { offset.animateTo(...) }
Stack {
SomethingThatMoves(Modifier.align(DirectionalAlignment(offset.value,offset.value)))
}
}
Given that it's private, I just copy & pasted the class, and worked perfectly. Is there another easy way to accomplish that?Nader Jawad
09/24/2020, 6:31 PMAlignment
interface and DirectionalAlignment
implements that. We also provide some default alignment implementations for center, bottom right, top left, etc.bruno.aybar
09/24/2020, 7:37 PM@Stable
val TopStart: Alignment = DirectionalAlignment(-1f, -1f)
@Stable
val TopCenter: Alignment = DirectionalAlignment(-1f, 0f)
@Stable
val TopEnd: Alignment = DirectionalAlignment(-1f, 1f)
@Stable
val CenterStart: Alignment = DirectionalAlignment(0f, -1f)
@Stable
val Center: Alignment = DirectionalAlignment(0f, 0f)
But let's say that I want some element not quite at the top center, but almost there (verticalBias = -0.75f instead of -1f).
Why not provide the ability to create new instances of that DirectionalAlignment
implementation?
As you say, yes it's an interface so custom implementations can be easily created, that's really good. Just wondering if there's any reason why that specific implementation is private
instead of public.Mihai Popa
09/25/2020, 3:52 PMNader Jawad
09/25/2020, 3:54 PMAbsoluteAlignment
is exposed and supports the use case you are looking for although it does not expose rtl supportMihai Popa
09/25/2020, 3:55 PMAbsoluteAlignment
's constructor is also internalDirectionalAlignment
to create custom Alignments by percentagebruno.aybar
09/25/2020, 8:29 PMAbsoluteAlignment
! That's actually what I was looking for, as I don't need rtl support