|
|
@@ -20,6 +20,11 @@ class TransitionAnimator : ComponentAnimator() {
|
|
|
*/
|
|
|
private var isShow = false
|
|
|
|
|
|
+ /**
|
|
|
+ * 组件宽高
|
|
|
+ */
|
|
|
+ private var mComponentSize: Pair<Int, Int>? = null
|
|
|
+
|
|
|
override fun show(onStart: (() -> Unit)?, onFinish: (() -> Unit)?) {
|
|
|
if (isShow) {
|
|
|
return
|
|
|
@@ -30,7 +35,7 @@ class TransitionAnimator : ComponentAnimator() {
|
|
|
val uiComponent = getUIComponent()
|
|
|
uiComponent?.asView()?.let { rootView ->
|
|
|
// 先测量view后,才能获取到尺寸
|
|
|
- measureView(rootView)
|
|
|
+ ensureInitComponentSize(rootView)
|
|
|
mShowAnimator = ValueAnimator.ofFloat(rootView.measuredWidth.toFloat(), 0f).apply {
|
|
|
duration = 300
|
|
|
interpolator = AccelerateInterpolator()
|
|
|
@@ -66,7 +71,7 @@ class TransitionAnimator : ComponentAnimator() {
|
|
|
val uiComponent = getUIComponent()
|
|
|
uiComponent?.asView()?.let { rootView ->
|
|
|
// 先测量view后,才能获取到尺寸
|
|
|
- measureView(rootView)
|
|
|
+ ensureInitComponentSize(rootView)
|
|
|
mHideAnimator = ValueAnimator.ofFloat(0f, rootView.measuredWidth.toFloat()).apply {
|
|
|
duration = 200
|
|
|
interpolator = AccelerateInterpolator()
|
|
|
@@ -91,4 +96,13 @@ class TransitionAnimator : ComponentAnimator() {
|
|
|
mHideAnimator!!.start()
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 确保测量了组件的大小
|
|
|
+ */
|
|
|
+ private fun ensureInitComponentSize(rootView: View) {
|
|
|
+ if (mComponentSize == null) {
|
|
|
+ mComponentSize = measureView(rootView)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|