I ended up removing my <OnSwipe>
from my MotionScene and using my MotionLayout's Transition listener and my RecyclerView's Scroll listener to check the direction of a scroll and trigger the corresponding transition.
Create some member varables to track the transition state:
private boolean mTransitioningToEnd = false;
private boolean mTransitioningToStart = false;
Then, in your Activity/Fragment's onCreate():
int endState = motionLayout.getEndState();
int startState = motionLayout.getStartState();
motionLayout.setTransitionListener(new MotionLayout.TransitionListener() {
@Override
public void onTransitionStarted(MotionLayout motionLayout, int startId, int endId) {
}
@Override
public void onTransitionChange(MotionLayout motionLayout, int startId, int endId, float progress) {
}
@Override
public void onTransitionCompleted(MotionLayout motionLayout, int currentId) {
// Update transition variables when completed
if(currentId == startState){
mTransitioningToStart = false;
}else if(currentId == endState){
mTransitioningToEnd = false;
}
}
@Override
public void onTransitionTrigger(MotionLayout motionLayout, int triggerId, boolean positive, float progress) {
}
});
myRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
int currentState = motionLayout.getCurrentState();
int threshold = 25; // Use a threshold to compare significant scroll motion
// Check for significant vertical motion
// and that we're not already transitioning
if(dy > threshold && currentState != endState && !mTransitioningToEnd){
motionLayout.transitionToEnd();
// Track the transition
mTransitioningToEnd = true;
mTransitioningToStart = false;
}else if(dy < -threshold && currentState != startState && !mTransitioningToStart){
motionLayout.transitionToStart();
// Track the transition
mTransitioningToStart = true;
mTransitioningToEnd = false;
}
super.onScrolled(recyclerView, dx, dy);
}
});
This isn't necessarily an ideal method. It will play the full transition in either direction at the duration set in the MotionScene. But it doesn't directly correspond to the scroll amount so it won't stop the transition midway if you're looking for partial progress.