Skip to content

Instantly share code, notes, and snippets.

@PiotrPrus
Created February 21, 2020 23:04
Show Gist options
  • Save PiotrPrus/139a238b4096730ae6dd1574a4560881 to your computer and use it in GitHub Desktop.
Save PiotrPrus/139a238b4096730ae6dd1574a4560881 to your computer and use it in GitHub Desktop.
xml scene to demonstrate onClick and onSwipe transitions not working in motionLayout beta4
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetStart="@id/start"
app:constraintSetEnd="@id/end"
app:duration="1000">
<OnSwipe
app:dragDirection="dragDown"
app:touchAnchorSide="top"
app:touchRegionId="@id/box" />
</Transition>
<Transition
app:constraintSetStart="@id/start"
app:constraintSetEnd="@id/scaleUp"
app:duration="500">
<OnClick
app:targetId="@id/box"
app:clickAction="toggle"/>
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint android:id="@+id/box"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint android:id="@+id/box"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</ConstraintSet>
<ConstraintSet android:id="@+id/scaleUp"
app:deriveConstraintsFrom="@id/start">
<Constraint android:id="@id/box"
android:layout_width="100dp"
android:layout_height="100dp"
android:scaleY="2"
android:scaleX="2"/>
</ConstraintSet>
</MotionScene>
@JeromeFranco
Copy link

I'm having the same issue. Did you manage to make this work?

@PiotrPrus
Copy link
Author

Yes, I talked with the creators of ML and this is not supported. To make onClick possible you need to override the MotionLayout method onTouch and determine the type of event that will result in a click. I will be talking about this during the upcoming devFest: https://devfest.pl/

@dmstreltcov
Copy link

Hi, do you have updates?

@PiotrPrus
Copy link
Author

Hello, as I said before, it is not working. You cannot have onSwipe and onClick on one element. here is a workaround:
https://github.com/PiotrPrus/MotionLayoutPlayground/blob/master/app/src/main/java/com/piotrprus/motionlayoutplayground/helper/CustomMotionLayout.kt

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