Skip to content

Commit

Permalink
fix(android): animation may cause IllegalStateException after destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
iPel authored and zealotchen0 committed Aug 7, 2023
1 parent 2d63fa5 commit e30d2a1
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class AnimationModule extends HippyNativeModuleBase implements DomActionI
private long mLastUpdateTime;
private final Set<Integer> mNeedUpdateAnimationNodes;
private Set<AnimationNode> mWaitUpdateAnimationNodes;
private boolean mInitialized = false;


public AnimationModule(HippyEngineContext context) {
Expand All @@ -71,6 +72,9 @@ public AnimationModule(HippyEngineContext context) {

@Override
public boolean handleMessage(Message msg) {
if (!mInitialized) {
return true;
}
int what = msg.what;
switch (what) {
case MSG_CHANGE_ANIMATION_STATUS: {
Expand Down Expand Up @@ -103,10 +107,12 @@ public void initialize() {
if (mContext.getDomManager() != null) {
mContext.getDomManager().addActionInterceptor(this);
}
mInitialized = true;
}

@Override
public void destroy() {
mInitialized = false;
mContext.removeEngineLifecycleEventListener(this);
if (mContext.getDomManager() != null) {
mContext.getDomManager().removeActionInterceptor(this);
Expand Down Expand Up @@ -156,7 +162,7 @@ public void onAnimationUpdate(Animation animation) {

mNeedUpdateAnimationNodes.addAll(nodeIds);

if (!mHandler.hasMessages(MSG_CHANGE_ANIMATION_STATUS)) {
if (mInitialized && !mHandler.hasMessages(MSG_CHANGE_ANIMATION_STATUS)) {
mHandler.sendEmptyMessage(MSG_CHANGE_ANIMATION_STATUS);
}
}
Expand Down Expand Up @@ -320,7 +326,7 @@ public HippyMap onUpdateNode(int tagId, HippyRootView rootView, HippyMap props)

@Override
public void onEngineResume() {
if (mHandler != null) {
if (mInitialized && mHandler != null) {
mHandler.post(new Runnable() {
@Override
public void run() {
Expand All @@ -340,7 +346,7 @@ public void run() {

@Override
public void onEnginePause() {
if (mHandler != null) {
if (mInitialized && mHandler != null) {
mHandler.post(new Runnable() {
@Override
public void run() {
Expand Down

0 comments on commit e30d2a1

Please sign in to comment.