Skip to content
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 opened this issue May 31, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@vkomysh-vicman
Copy link

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)
    }
}
@vkomysh-vicman vkomysh-vicman added the bug Something isn't working label May 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant