gabrielemariotti / cardslib

Android Library to build a UI Card
4.66k stars 1.19k forks source link

card.setOnExpandAnimatorStartListener doesn't work #508

Open txhuy opened 8 years ago

txhuy commented 8 years ago
            CustomCardExpand cardExpand = new CustomCardExpand(getContext(), R.layout.card_item_inner_expand_layout, message);
            card.addCardExpand(cardExpand);
            ViewToClickToExpand viewToClickToExpand = ViewToClickToExpand.builder().setupCardElement(ViewToClickToExpand.CardElementUI.CARD);
            card.setViewToClickToExpand(viewToClickToExpand);
            card.setSwipeable(false);
            card.setOnExpandAnimatorStartListener(new Card.OnExpandAnimatorStartListener() {
                @Override
                public void onExpandStart(Card card) {
                    ToastUtils.show("Expand start"); //this doesn't work
                }
            });
            card.setOnExpandAnimatorEndListener(new Card.OnExpandAnimatorEndListener() {
                @Override
                public void onExpandEnd(Card card) {
                    ToastUtils.show("Expand End"); //this works
                }
            });

I have problem with card.setOnExpandAnimatorStartListener.

Neuron64 commented 8 years ago

Add code card.doToogleExpand();

d4vidi commented 8 years ago

I've also encountered this issue. The same bug applies to the collapse-start listener. The fix is very simple, though: getting the ExpandCollapseHelper class to register a listener over the expand-animation that also overrides the onAnimationStart() method. In that method, the user's listener should be invoked. For example:

class ExpandCollapseHelper {
// ...
private static void animateExpanding(final ExpandContainerHelper helper) {
// ...
// ...
            helper.getCardView().getExpandAnimator().addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    if (helper.card.getOnExpandAnimatorStartListener() != null)
                        helper.card.getOnExpandAnimatorStartListener().onExpandStart(helper.card);
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    // ...
                }
 // ...