dmitry-zaitsev/AndroidSideMenu

Toggle to close the side bar not working

Closed this issue · 6 comments

I am able to toggle(open) the sidebar on first button click but not able to close the side bar on clicking again. As per my knowledge after the sidebar opens, the parent view of the button is getting disabled because its not able to recognize my click event. Please can you look into this issue so that I can toggle the sidebar back to its initial position on button click.

Where you putting your button?

Indeed, when menu is opened - main layout is inactive (which I think is reasonable, because user is just not focused on it). There is two possible solutions:

  1. Use application icon as toggle button (if you are working with ActionBar or ActionBarSherlock, or something else that don't belongs to SlideHolder). YouTube app works in this way (and I also prefer this solution, which you can see on screenshot)
  2. Place second button inside left menu (that will also call toggle() method). I don't know any application that works in that way, so personally I don't like it.

I totally agree with you but as per my app requirement am supposed to do so. So if you can help me figure this out, it would be a great help.

Well, then you should modify some source code (because your case, unfortunately, is out of scope of this library).

Look at dispatchTouchEvent() method of SlideHolder. There is something like

if(mSlideMode != MODE_FINISHED) {
    //stuff to do if menu is closed
} else {
    //stuff to do if menu is opened
}

Your interest is "else" case. There is a code that dispatches touch event to menu (if it was pressed) or started closing procedures of SlideHolder. Modify it in a such way, that touch event will be passed to main layout also.

Hi there,

I have the same same issue as @ritesh-dubey so i've modified the source like so:

if(!rect.contains((int) ev.getX(), (int) ev.getY())) {
    mClosing = true;
    onTouchEvent(ev);
    if(ev.getAction() == MotionEvent.ACTION_UP){
        close();
    }
    return true;
} 

However, I don't understand what mClosing is used for? Any chance you could provide an explanation?
Cheers

@brettyukich mClosing appears to be unused. I've made some changes into layout mechanism, so looks like I've just forgot about this variable. Sorry for that.

Thanks for your code, I'll add it into next update.

@ritesh-dubey

Now you can use

setDispatchTouchWhenOpened(true)

to dispatch touch events to childs when SlideHolder is opened