Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Execution speed is too fast, causing the animation execution sequence to change #9

Open
tcqq opened this issue May 17, 2018 · 1 comment

Comments

@tcqq
Copy link

tcqq commented May 17, 2018

@florent37 If two different animations are executed quickly at the same time, the original execution sequence may change, resulting in is not the expected effect, I want to add a stop animation should be able to solve this problem, but I did not find the stop the animation method, can you add a stop animation method? Or how should this situation be solved?

@tcqq
Copy link
Author

tcqq commented May 17, 2018

I used this method to solve the above problem, But is there an easier way to solve the above problem?

    ExpectAnim mShowAnim;
    ExpectAnim mHideAnim;
    boolean mIsShowAnim;
    boolean mIsHideAnim;

    private void setFabAnim(boolean show) {
        Observable
                .just(show)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<Boolean>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        if (mHideAnim != null) {
                            if (mHideAnim.isPlaying() && show) {
                                d.dispose();
                                mIsHideAnim = true;
                                Timber.d("ShowAnim start");
                            }
                        } else if (mShowAnim != null) {
                            if (mShowAnim.isPlaying() && !show) {
                                d.dispose();
                                mIsShowAnim = true;
                                Timber.d("HideAnim start");
                            }
                        }
                    }

                    @Override
                    public void onNext(Boolean aBoolean) {
                        if (aBoolean) {
                            Timber.d("Execute start anim");
                            showAnim();
                        } else {
                            Timber.d("Execute hide anim");
                            hideAnim();
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        Timber.e(e.getLocalizedMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    private void showAnim() {
        mShowAnim = new ExpectAnim()
                .expect(mFloatingActionButton)
                .toBe(
                        scale(1, 1),
                        visible()
                )
                .toAnimation()
                .setDuration(200)
                .addStartListener(expectAnim -> mIsShowAnim = false)
                .addEndListener(expectAnim -> {
                    if (mIsShowAnim) {
                        hideAnim();
                    }
                })
                .start();
    }

    private void hideAnim() {
        mHideAnim = new ExpectAnim()
                .expect(mFloatingActionButton)
                .toBe(
                        scale(0, 0),
                        invisible()
                )
                .toAnimation()
                .setDuration(200)
                .addStartListener(expectAnim -> mIsHideAnim = false)
                .addEndListener(expectAnim -> {
                    if (mIsHideAnim) {
                        showAnim();
                    }
                })
                .start();
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant