|
|
@ -5,11 +5,22 @@ import androidx.constraintlayout.widget.ConstraintLayout |
|
|
|
import androidx.constraintlayout.widget.ConstraintSet |
|
|
|
import androidx.constraintlayout.widget.ConstraintSet |
|
|
|
import androidx.transition.TransitionManager |
|
|
|
import androidx.transition.TransitionManager |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun ConstraintLayout.modify(withAnim: Boolean = false): ConstraintModify.ConstraintBegin { |
|
|
|
|
|
|
|
val begin = ConstraintModify(this).begin |
|
|
|
|
|
|
|
if (withAnim) { |
|
|
|
|
|
|
|
TransitionManager.beginDelayedTransition(this) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return begin |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Suppress("MemberVisibilityCanBePrivate", "unused") |
|
|
|
@Suppress("MemberVisibilityCanBePrivate", "unused") |
|
|
|
class ConstraintModify(private val constraintLayout: ConstraintLayout) { |
|
|
|
class ConstraintModify(private val constraintLayout: ConstraintLayout) { |
|
|
|
|
|
|
|
|
|
|
|
private var begin: ConstraintBegin? = null |
|
|
|
val begin: ConstraintBegin by lazy { |
|
|
|
|
|
|
|
ConstraintBegin(constraintLayout, applyConstraintSet).apply { |
|
|
|
|
|
|
|
applyConstraintSet.clone(constraintLayout) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
private val applyConstraintSet = ConstraintSet() |
|
|
|
private val applyConstraintSet = ConstraintSet() |
|
|
|
private val resetConstraintSet = ConstraintSet() |
|
|
|
private val resetConstraintSet = ConstraintSet() |
|
|
|
|
|
|
|
|
|
|
@ -17,26 +28,13 @@ class ConstraintModify(private val constraintLayout: ConstraintLayout) { |
|
|
|
resetConstraintSet.clone(constraintLayout) |
|
|
|
resetConstraintSet.clone(constraintLayout) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 开始修改 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
fun begin(): ConstraintBegin { |
|
|
|
|
|
|
|
synchronized(ConstraintBegin::class.java) { |
|
|
|
|
|
|
|
if (begin == null) { |
|
|
|
|
|
|
|
begin = ConstraintBegin(constraintLayout, applyConstraintSet) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
applyConstraintSet.clone(constraintLayout) |
|
|
|
|
|
|
|
return begin!! |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 带动画的修改 |
|
|
|
* 带动画的修改 |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun beginWithAnim(): ConstraintBegin { |
|
|
|
fun beginWithAnim(): ConstraintBegin { |
|
|
|
TransitionManager.beginDelayedTransition(constraintLayout) |
|
|
|
TransitionManager.beginDelayedTransition(constraintLayout) |
|
|
|
return begin() |
|
|
|
return begin |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|