Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant