From 52bba3a5cc53d7c681b8ca65ec8ce7dfbe96ea33 Mon Sep 17 00:00:00 2001 From: chaihua1 Date: Thu, 4 Jan 2024 17:17:32 +0800 Subject: [PATCH] =?UTF-8?q?[#605]=E4=BF=AE=E5=A4=8DAndroid=2013=E6=97=A0?= =?UTF-8?q?=E6=B3=95pause=E5=8A=A8=E7=94=BB=E5=AF=BC=E8=87=B4=E7=9A=84Sort?= =?UTF-8?q?ing=20went=20bad=20=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chaihua1 --- .../component/animation/CSSAnimatorSet.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/core/runtime/android/runtime/src/main/java/org/hapjs/component/animation/CSSAnimatorSet.java b/core/runtime/android/runtime/src/main/java/org/hapjs/component/animation/CSSAnimatorSet.java index 6be20d22..a1eac7ee 100755 --- a/core/runtime/android/runtime/src/main/java/org/hapjs/component/animation/CSSAnimatorSet.java +++ b/core/runtime/android/runtime/src/main/java/org/hapjs/component/animation/CSSAnimatorSet.java @@ -157,6 +157,8 @@ public CSSAnimatorSet(HapEngine hapEngine, Component component) { mWrapped = new AnimatorSet(); mWrapped.setInterpolator(new LinearInterpolator()); mWrapped.addListener(new CssAnimationListener(this)); + // 根据activity可见性暂停或重启动画 + installActivityListener(mComponent); } public static CSSAnimatorSet createNewAnimator( @@ -254,6 +256,8 @@ public void start() { mDirty = false; mWrapped.start(); + checkCurrentActivityLifecycle(mComponent); + View animatedView = mComponent.getHostView(); if (animatedView != null) { // animated view may changed. @@ -263,9 +267,25 @@ public void start() { // 百分比参数动画在自身尺寸发生变化时,需要进行自适应 installLayoutChangeListener(animatedView); + } - // 根据activity可见性暂停或重启动画 - installActivityListener(mComponent); + /** + * 在Android 13机型上,如果当前快应用退至后台时创建了CssAnimatorSet并调用了start方法, + * 由于当前已经在onPause的生命周期中,不会触发对应的生命周期回调来停止动画, + * 会导致当前动画抛出UnsupportedOperationException("Sorting went bad, the start event should always be at index 0")异常。 + * 需要主动查询一下当前Activity状态 + * + * @param component + */ + private void checkCurrentActivityLifecycle(Component component) { + final HybridView hybridView = component != null ? component.getHybridView() : null; + if (hybridView == null) { + return; + } + final HybridManager hybridManager = hybridView.getHybridManager(); + if (!hybridManager.isResumed()) { + mActivityStateListener.onActivityPause(); + } } public void finish() {