umano / AndroidSlidingUpPanel

This library provides a simple way to add a draggable sliding up panel (popularized by Google Music and Google Maps) to your Android application. Brought to you by Umano.
http://umano.me
Apache License 2.0
9.5k stars 2.26k forks source link

Calling setPanelHeight in onConfigChanged is resulting in bad behaviour of UI #538

Closed sirkyven closed 5 years ago

sirkyven commented 9 years ago

When I tried to set panel height in onConfigChanged callback of a fragment, Second child view of SlidingPanelLayout hasn't been rendered. I could trace it out that, the problem is with setPanleHeight(). Help please..!!

jgrife commented 9 years ago

I found that I had an issue with calling setPanelHeight() if calling it quickly and repeatedly with different values. I have a ViewPager that changes the panel height and if the user quickly drags back and forth between the two views, the PanelState erroneously gets set to either HIDDEN or ANCHORED. I fixed this by creating the following function in SlidingUpPanelLayout and I'm curious if it solves your issue as well...

public void setPanelHeight(int val, PanelState panelState) { mSlideState = panelState; setPanelHeight(val); }

sirkyven commented 9 years ago

Ty jgrife:-) But It didn't work, actually when I let android to take care of rotation, it's taking appropriate values from land directory. When I tried to pass the same values in onConfigurationChanged method, It's not drawing the second child of umanoSlidingPanelLayout.

sirkyven commented 9 years ago

Is there any alternative way to change the panel height, instead of changing through setPanelHeight in OnConfigurationChanged method.

jgrife commented 9 years ago

sorry if this sounds obtuse, but you say that android is taking the appropriate values from the land directory... do you mean that you have tried creating a /layout-land/ layout directory and in your layout there you have your SlidingUpPanelLayout view and are able to set the umanoPanelHeight and everything works just fine? If so, what is the issue with setting the height via the layout?

barbeau commented 8 years ago

I'm also having issues with the sliding panel hiding itself when I change the panel from HIDDEN to COLLAPSED state and call setPanelHeight() to change from a smaller height (106dp) to a larger height (146dp). A full rundown of the issue w/ screenshots is here on the OneBusAway project: https://github.com/OneBusAway/onebusaway-android/issues/294

It seems like the resize drops the panel beneath the bottom of the screen temporarily, which can trigger the panel to hide itself - onPanelHidden() gets called when this occurs. I've also noticed that I get a negative slide offset when this occurs in onPanelSlide():

09-18 17:01:39.891  12220-12220/com.joulespersecond.seattlebusbot D/BubblePopupHelper﹕ isShowingBubblePopup : false
09-18 17:01:39.891  12220-12220/com.joulespersecond.seattlebusbot D/HomeActivity﹕ onPanelSlide, offset -0.00729927
09-18 17:01:39.901  12220-12220/com.joulespersecond.seattlebusbot D/HomeActivity﹕ onPanelSlide, offset -0.00486618
09-18 17:01:39.921  12220-12220/com.joulespersecond.seattlebusbot D/HomeActivity﹕ onPanelSlide, offset -0.0030413626
09-18 17:01:39.941  12220-12220/com.joulespersecond.seattlebusbot D/HomeActivity﹕ onPanelSlide, offset -0.001216545
09-18 17:01:39.951  12220-12220/com.joulespersecond.seattlebusbot D/HomeActivity﹕ onPanelSlide, offset -6.082725E-4
09-18 17:01:39.981  12220-12220/com.joulespersecond.seattlebusbot D/HomeActivity﹕ onPanelSlide, offset 0.0

Maybe this code in onViewDragStateChanged() is causing it, triggered by the negative offset?

@Override
        public void onViewDragStateChanged(int state) {
            if (mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) {
                mSlideOffset = computeSlideOffset(mSlideableView.getTop());
                applyParallaxForCurrentSlideOffset();

                if (mSlideOffset == 1) {
                    if (mSlideState != PanelState.EXPANDED) {
                        updateObscuredViewVisibility();
                        mSlideState = PanelState.EXPANDED;
                        dispatchOnPanelExpanded(mSlideableView);
                    }
                } else if (mSlideOffset == 0) {
                    if (mSlideState != PanelState.COLLAPSED) {
                        mSlideState = PanelState.COLLAPSED;
                        dispatchOnPanelCollapsed(mSlideableView);
                    }
                } else if (mSlideOffset < 0) {   // <---Could this be hiding the panel?
                    mSlideState = PanelState.HIDDEN;
                    mSlideableView.setVisibility(View.INVISIBLE);
                    dispatchOnPanelHidden(mSlideableView);
                } else if (mSlideState != PanelState.ANCHORED) {
                    updateObscuredViewVisibility();
                    mSlideState = PanelState.ANCHORED;
                    dispatchOnPanelAnchored(mSlideableView);
                }
            }
        }

I don't recall seeing this prior to v3.0.0 of the library, but I could be wrong. The above happens intermittently in the app, so its been hard to pin down.

Recently I noticed that a similar (same?) problem seems to be triggered when opening the soft keyboard and calling setPanelHeight() to change from a larger to smaller value. This is easier to consistently reproduce in the app - here's a video: https://youtu.be/0Q7osS8SQuE

The following steps work as expected, which you see from 0:00 to 0:12 - I repeat these steps twice to open the keyboard twice and still see the header without problems:

As long as I return to the HIDDEN state between opening the keyboard, everything is fine. But, if I do the following, without returning to the HIDDEN state (from 0:12 on):

...the header disappears. It seems like the sliding panel loses track of its vertical state, and thinks its lower on the screen than it actually is, which causes it to hide itself.

barbeau commented 5 years ago

@vgangisetti just curious why you closed this? Did you find a fix?