shiburagi / Drawer-Behavior

Drawer behavior is a library that provide an extra behavior on drawer, such as, move view or scaling view's height while drawer on slide.
https://shiburagi.github.io/Drawer-Behavior/
MIT License
593 stars 101 forks source link

Left drawer closes when I click on it (not happening on right drawer) #3

Closed albert0m closed 6 years ago

albert0m commented 6 years ago

This is the code:

<com.infideap.drawerbehavior.AdvanceDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                                 xmlns:app="http://schemas.android.com/apk/res-auto"
                                                 xmlns:tools="http://schemas.android.com/tools"
                                                 android:id="@+id/drawer_layout"
                                                 android:layout_width="match_parent"
                                                 android:layout_height="match_parent"
                                                 android:fitsSystemWindows="false"
                                                 android:background="#ffffff">

    <android.support.design.widget.NavigationView
            android:id="@+id/left_drawer"
            android:background="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="false">

.....

  <android.support.design.widget.NavigationView
            android:id="@+id/righ_drawer"
            android:background="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="end"
            android:fitsSystemWindows="false">

....

</com.infideap.drawerbehavior.AdvanceDrawerLayout>

After I open the left drawer, whenever I click on it, the drawer will close ignoring any event that I'm trying to trigger. If I move the left drawer to the right (Gravity.END), the issue won't happen. Why is this happening only on a NavigatioView moved to the left?

shiburagi commented 6 years ago

Maybe the problem came from Activity class..can u share the code??

On Wed, 3 Jan 2018 at 11:25 PM, marconealberto notifications@github.com wrote:

This is the code:

<com.infideap.drawerbehavior.AdvanceDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="false" android:background="#ffffff">

<android.support.design.widget.NavigationView
        android:id="@+id/left_drawer"
        android:background="#ffffff"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="false">

.....

<android.support.design.widget.NavigationView android:id="@+id/righ_drawer" android:background="#ffffff" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="end" android:fitsSystemWindows="false">

....

</com.infideap.drawerbehavior.AdvanceDrawerLayout>

After I open the left drawer, whenever I click on it, the drawer will close ignoring any event that I'm trying to trigger. If I move the left drawer to the right (Gravity.END), the issue won't happen. Why is this happening only on a NavigatioView moved to the left?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/shiburagi/Drawer-Behavior/issues/3, or mute the thread https://github.com/notifications/unsubscribe-auth/AO0HP5RL8w1-eEDBRNA9TqOmYz_5EmWgks5tG5vbgaJpZM4RR3Zj .

shiburagi commented 6 years ago

There may have this segment of code in your activity class.

@SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // This code will close the left drawer after drawer's item clicked
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

try remove/comment this line of code

        drawer.closeDrawer(GravityCompat.START);
albert0m commented 6 years ago

this is weird because I removed the only places where I called the closeDrawer, and it still happens. This only happens if I move the drawer to the left. How can I debug where the closing is happening?

albert0m commented 6 years ago

found it, it's in the DrawerLayout sources:

 @Override
    public boolean onTouchEvent(MotionEvent ev) {

... 
        switch (action & MotionEventCompat.ACTION_MASK) {

...
            case MotionEvent.ACTION_UP: {
                   closeDrawers(peekingOnly);

}
shiburagi commented 6 years ago

not in drawer layout..but in Activity/ Fragment class should have that code

shiburagi commented 6 years ago

by default code generator for navigation activity, the generator with create this segment of call,

   @SuppressWarnings("StatementWithEmptyBody")
   @Override
   public boolean onNavigationItemSelected(MenuItem item) {
       // This code will close the left drawer after drawer's item clicked
       drawer.closeDrawer(GravityCompat.START);
       return true;
   }

which will close the left drawer after the item clicked

albert0m commented 6 years ago

I'm not sure where I'm failing to explain myself, but the code you pasted twice IS NOT PRESENT ANYWHERE. I showed you where the problem is happening, but it's past beyond your library. I'm dropping it from my app and I will be googling the solution. Thank you anyways

shiburagi commented 6 years ago

okayy

shiburagi commented 6 years ago

i already push example code which left drawer will not close after item clicked on branch "revision1"

https://github.com/shiburagi/Drawer-Behavior/tree/revision1/app/src/main/java/com/infideap/drawerbehaviorexample/drawer