Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#605]修复Android 13无法pause动画导致的Sorting went bad 崩溃 #644

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -254,6 +256,8 @@ public void start() {

mDirty = false;
mWrapped.start();
checkCurrentActivityLifecycle(mComponent);

View animatedView = mComponent.getHostView();
if (animatedView != null) {
// animated view may changed.
Expand All @@ -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() {
Expand Down
Loading