Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit

Permalink
fix the gone behavour in MotionLayout (#504)
Browse files Browse the repository at this point in the history
* fix the gone behavour in MotionLayout

* fix comments

* comments 2
  • Loading branch information
jafu888 authored and oscar-ad committed Apr 22, 2022
1 parent 99a48f3 commit 3d2c70c
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2606,6 +2606,7 @@ private void setupConstraintWidget(ConstraintWidgetContainer base, ConstraintSet
}
// build id widget map
for (ConstraintWidget child : base.getChildren()) {
child.setAnimated(true);
View view = (View) child.getCompanionWidget();
mapIdToWidget.put(view.getId(), child);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ public enum DimensionBehaviour {

// Contains the visibility status of the widget (VISIBLE, INVISIBLE, or GONE)
private int mVisibility = VISIBLE;

// Contains if this widget is animated. Currently only affects gone behaviour
private boolean mAnimated = false;
private String mDebugName = null;
private String mType = null;

Expand Down Expand Up @@ -922,6 +923,24 @@ public int getVisibility() {
return mVisibility;
}

/**
* Set if this widget is animated. Currently only affects gone behaviour
*
* @param animated if true the widget must be positioned correctly when not visible
*/
public void setAnimated(boolean animated) {
mAnimated = animated;
}

/**
* Returns if this widget is animated. Currently only affects gone behaviour
*
* @return true if ConstraintWidget is used in Animation
*/
public boolean isAnimated() {
return mAnimated;
}

/**
* Returns the name of this widget (used for debug purposes)
*
Expand Down Expand Up @@ -2417,8 +2436,8 @@ public void addToSolver(LinearSystem system, boolean optimize) {
}
}

if (mVisibility == GONE && !hasDependencies()
&& !mIsInBarrier[HORIZONTAL] && !mIsInBarrier[VERTICAL]) {
if (!(mVisibility != GONE || mAnimated || hasDependencies() ||
mIsInBarrier[HORIZONTAL] || mIsInBarrier[VERTICAL])) {
return;
}

Expand Down Expand Up @@ -3426,6 +3445,7 @@ public void copy(ConstraintWidget src, HashMap<ConstraintWidget, ConstraintWidge
mCompanionWidget = src.mCompanionWidget;
mContainerItemSkip = src.mContainerItemSkip;
mVisibility = src.mVisibility;
mAnimated = src.mAnimated;
mDebugName = src.mDebugName;
mType = src.mType;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#BECEED"
app:layoutDescription="@xml/bug_006_scene"
tools:context=".OnCreateTransiton"
>
<View
android:id="@+id/view"
android:layout_width="100dp"
android:layout_height="10dp"
android:background="#4B1A8F"

app:layout_constraintVertical_bias="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/view2"
android:layout_width="100dp"
android:layout_height="10dp"
android:background="#790"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.motion.widget.MotionLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">

<ConstraintSet android:id="@+id/end">
<Constraint android:id="@+id/view"
android:layout_width="100dp"
android:layout_height="10dp"
android:visibility="visible"
motion:layout_constraintVertical_bias="1"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintTop_toTopOf="parent" />

</ConstraintSet>

<ConstraintSet android:id="@+id/start">
</ConstraintSet>

<Transition
motion:constraintSetStart="@id/start"
motion:constraintSetEnd="@id/end"
motion:duration="1000">
<OnClick />
<KeyFrameSet>
<KeyTrigger motion:framePosition="50" motion:motionTarget="@+id/view" motion:triggerId="@id/foo" />
</KeyFrameSet>
</Transition>

</MotionScene>

0 comments on commit 3d2c70c

Please sign in to comment.