Thread
#compose
    bruno.aybar

    bruno.aybar

    2 years ago
    Is there a reason why
    DirectionalAlignment
    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

    Nader Jawad

    2 years ago
    We do provide the
    Alignment
    interface and
    DirectionalAlignment
    implements that. We also provide some default alignment implementations for center, bottom right, top left, etc.
    bruno.aybar

    bruno.aybar

    2 years ago
    Yes, and those implementations look like
    @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

    Mihai Popa

    2 years ago
    Could you please file a bug to make this public? Thanks 🙂
    Nader Jawad

    Nader Jawad

    2 years ago
    Looks like
    AbsoluteAlignment
    is exposed and supports the use case you are looking for although it does not expose rtl support
    Mihai Popa

    Mihai Popa

    2 years ago
    AbsoluteAlignment
    's constructor is also internal
    We want to provide a few factories for Alignments. You should not need to copy paste
    DirectionalAlignment
    to create custom Alignments by percentage
    bruno.aybar

    bruno.aybar

    2 years ago
    @Nader Jawad I was not aware of
    AbsoluteAlignment
    ! That's actually what I was looking for, as I don't need rtl support
    @Mihai Popa done! Here's the bug: https://issuetracker.google.com/issues/169406772