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

Commit 3d2c70c

Browse files
jafu888oscar-ad
authored andcommitted
fix the gone behavour in MotionLayout (#504)
* fix the gone behavour in MotionLayout * fix comments * comments 2
1 parent 99a48f3 commit 3d2c70c

File tree

4 files changed

+88
-3
lines changed

4 files changed

+88
-3
lines changed

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/widget/MotionLayout.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2606,6 +2606,7 @@ private void setupConstraintWidget(ConstraintWidgetContainer base, ConstraintSet
26062606
}
26072607
// build id widget map
26082608
for (ConstraintWidget child : base.getChildren()) {
2609+
child.setAnimated(true);
26092610
View view = (View) child.getCompanionWidget();
26102611
mapIdToWidget.put(view.getId(), child);
26112612
}

constraintlayout/core/src/main/java/androidx/constraintlayout/core/widgets/ConstraintWidget.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ public enum DimensionBehaviour {
481481

482482
// Contains the visibility status of the widget (VISIBLE, INVISIBLE, or GONE)
483483
private int mVisibility = VISIBLE;
484-
484+
// Contains if this widget is animated. Currently only affects gone behaviour
485+
private boolean mAnimated = false;
485486
private String mDebugName = null;
486487
private String mType = null;
487488

@@ -922,6 +923,24 @@ public int getVisibility() {
922923
return mVisibility;
923924
}
924925

926+
/**
927+
* Set if this widget is animated. Currently only affects gone behaviour
928+
*
929+
* @param animated if true the widget must be positioned correctly when not visible
930+
*/
931+
public void setAnimated(boolean animated) {
932+
mAnimated = animated;
933+
}
934+
935+
/**
936+
* Returns if this widget is animated. Currently only affects gone behaviour
937+
*
938+
* @return true if ConstraintWidget is used in Animation
939+
*/
940+
public boolean isAnimated() {
941+
return mAnimated;
942+
}
943+
925944
/**
926945
* Returns the name of this widget (used for debug purposes)
927946
*
@@ -2417,8 +2436,8 @@ public void addToSolver(LinearSystem system, boolean optimize) {
24172436
}
24182437
}
24192438

2420-
if (mVisibility == GONE && !hasDependencies()
2421-
&& !mIsInBarrier[HORIZONTAL] && !mIsInBarrier[VERTICAL]) {
2439+
if (!(mVisibility != GONE || mAnimated || hasDependencies() ||
2440+
mIsInBarrier[HORIZONTAL] || mIsInBarrier[VERTICAL])) {
24222441
return;
24232442
}
24242443

@@ -3426,6 +3445,7 @@ public void copy(ConstraintWidget src, HashMap<ConstraintWidget, ConstraintWidge
34263445
mCompanionWidget = src.mCompanionWidget;
34273446
mContainerItemSkip = src.mContainerItemSkip;
34283447
mVisibility = src.mVisibility;
3448+
mAnimated = src.mAnimated;
34293449
mDebugName = src.mDebugName;
34303450
mType = src.mType;
34313451

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.motion.widget.MotionLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools"
6+
android:id="@+id/rootView"
7+
android:layout_width="match_parent"
8+
android:layout_height="match_parent"
9+
android:background="#BECEED"
10+
app:layoutDescription="@xml/bug_006_scene"
11+
tools:context=".OnCreateTransiton"
12+
>
13+
<View
14+
android:id="@+id/view"
15+
android:layout_width="100dp"
16+
android:layout_height="10dp"
17+
android:background="#4B1A8F"
18+
19+
app:layout_constraintVertical_bias="0"
20+
app:layout_constraintStart_toStartOf="parent"
21+
app:layout_constraintBottom_toBottomOf="parent"
22+
app:layout_constraintEnd_toEndOf="parent"
23+
app:layout_constraintTop_toTopOf="parent" />
24+
<View
25+
android:id="@+id/view2"
26+
android:layout_width="100dp"
27+
android:layout_height="10dp"
28+
android:background="#790"
29+
app:layout_constraintStart_toStartOf="parent"
30+
app:layout_constraintBottom_toBottomOf="parent"
31+
app:layout_constraintEnd_toEndOf="parent"
32+
app:layout_constraintTop_toTopOf="parent"/>
33+
</androidx.constraintlayout.motion.widget.MotionLayout>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:motion="http://schemas.android.com/apk/res-auto">
4+
5+
<ConstraintSet android:id="@+id/end">
6+
<Constraint android:id="@+id/view"
7+
android:layout_width="100dp"
8+
android:layout_height="10dp"
9+
android:visibility="visible"
10+
motion:layout_constraintVertical_bias="1"
11+
motion:layout_constraintStart_toStartOf="parent"
12+
motion:layout_constraintBottom_toBottomOf="parent"
13+
motion:layout_constraintEnd_toEndOf="parent"
14+
motion:layout_constraintTop_toTopOf="parent" />
15+
16+
</ConstraintSet>
17+
18+
<ConstraintSet android:id="@+id/start">
19+
</ConstraintSet>
20+
21+
<Transition
22+
motion:constraintSetStart="@id/start"
23+
motion:constraintSetEnd="@id/end"
24+
motion:duration="1000">
25+
<OnClick />
26+
<KeyFrameSet>
27+
<KeyTrigger motion:framePosition="50" motion:motionTarget="@+id/view" motion:triggerId="@id/foo" />
28+
</KeyFrameSet>
29+
</Transition>
30+
31+
</MotionScene>

0 commit comments

Comments
 (0)