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

showPanel() not working shortly after hidePanel() and vice versa #345

Closed
Pkmmte opened this issue Dec 21, 2014 · 5 comments
Closed

showPanel() not working shortly after hidePanel() and vice versa #345

Pkmmte opened this issue Dec 21, 2014 · 5 comments

Comments

@Pkmmte
Copy link

Pkmmte commented Dec 21, 2014

If I call hidePanel() and shortly afterwards call showPanel(), the showPanel() call gets ignored if called too soon. I think it's because the panel is sliding animating to the hidden state when I call showPanel() and therefore ignores the call. It's easy to replicate this issue by simply calling those two together, maybe with some slight delay.

I understand we're not supposed to use these two so quickly but here's my use case: In my app, the panel hides when user starts dragging the map and reappears when they stop dragging and new data loads. This works fine and all but in some cases my data loads so fast that the panel has yet to finish hiding and therefore ignores the second call.

Example:
https://play.google.com/store/apps/details?id=co.nowl
Right after clicking the location button, the panel hides and refuses to appear again until something else triggers it.

@tokudu
Copy link
Contributor

tokudu commented Jan 10, 2015

Please execute the call on the handler. Also, keep in mind that the API is changing in the upcoming version 3.0 36c0063

@tokudu tokudu closed this as completed Jan 10, 2015
@subodh-malgonde
Copy link

@Pkmmte how did you handle this?

@tokudu what handler are you talking about?

@Pkmmte
Copy link
Author

Pkmmte commented Apr 1, 2015

@subodh-malgonde I ended up forking the latest version of this library, having a "queuedState" variable, and having a timer check the currentState with the queuedState every half second to ensure setPanelState() worked correctly. It's not the best solution but at least it works now.

@subodh-malgonde
Copy link

@Pkmmte Thanks, but I could not find any "queuedState" variable in the latest version? I am looking in the SlidingUpPanelLayout.java. Can you maybe explain with a code snippet?

@Pkmmte
Copy link
Author

Pkmmte commented Apr 1, 2015

@subodh-malgonde Essentially, I just created a variable called mQueuedState and a Runnable which compares it to mSlideState recursively. When the view is constructed, it calls a fixState() function that executes that runnable with a 500 millisecond delay.

In short:

private PanelState mQueuedState;

private final Runnable runnable = new Runnable() {
    @Override
    public void run() {
        if(mQueuedState != mSlideState && (mSlideState == PanelState.HIDDEN))
            setPanelState(mQueuedState);
        fixState();
    }
};

public void setPanelState(PanelState state) {
    if (state == null || state == PanelState.DRAGGING) {
        throw new IllegalArgumentException("Panel state cannot be null or DRAGGING.");
    }
    mQueuedState = state;
    if (!isEnabled()
            || mSlideableView == null
            || state == mSlideState
            || mSlideState == PanelState.DRAGGING) return;

    if (mFirstLayout) {
        mSlideState = state;
    } else {
        if (mSlideState == PanelState.HIDDEN) {
            mSlideableView.setVisibility(View.VISIBLE);
            requestLayout();
        }
        switch (state) {
            case ANCHORED:
                smoothSlideTo(mAnchorPoint, 0);
                break;
            case COLLAPSED:
                smoothSlideTo(0, 0);
                break;
            case EXPANDED:
                smoothSlideTo(1.0f, 0);
                break;
            case HIDDEN:
                int newTop = computePanelTopPosition(0.0f) + (mIsSlidingUp ?        +mPanelHeight : -mPanelHeight);
                smoothSlideTo(computeSlideOffset(newTop), 0);
                break;
        }
    }
}

private void fixState() {
    postDelayed(runnable, 500);
}

The full gist I made for it:
https://gist.github.com/Pkmmte/57cd4f18b940f5e3bd78

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

No branches or pull requests

3 participants