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>
@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