Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

MotionLayout OnSwipe without TouchAnchorId (support nested scroll) #856

Open
@vkomysh-vicman

Description

Case:
MotionLayout with RecyclerView child.
Transition has OnSwipe TouchResponse without TouchAnchorId (whole MotionLayout area):

   <Transition
        android:id="@+id/transition"
        motion:constraintSetStart="@id/start"
        motion:constraintSetEnd="@id/end">
        <OnSwipe />
    </Transition>

All works fine after any MOVE touch event (non-nested scrollable): mAnchorDpDt set by minSize = Math.min(mMotionLayout.getWidth(), mMotionLayout.getHeight())

But, before processTouchEvent MOVE, mAnchorDpDt has incorrect value [0.01, 0.01] and strange behavior in case nested scroll TouchResponse.scrollMove

Temporary fix:

fun MotionScene.Transition.fixAnchorDpDt(minSize: Float) {
    val mAnchorDpDt: FloatArray = touchResponse.getPrivateProperty("mAnchorDpDt") as FloatArray
    mAnchorDpDt[1] = -minSize
}

fun <T : Any> T.getPrivateProperty(variableName: String): Any? {
    return javaClass.getDeclaredField(variableName).let { field ->
        field.isAccessible = true
        return@let field.get(this)
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions