Android Question [SOLVED] Regarding the scrim in B4ADrawer

Sandman

Expert
Licensed User
Longtime User
This thread continues the topic of the dark area to the right of the open drawer. That area is called scrim, in Googles specifications. Here is that topic:

[class] B4ADrawer - sliding drawer
https://www.b4x.com/android/forum/threads/class-b4adrawer-sliding-drawer.97828/

It will also make it more difficult to start the swipe gesture.

You're right. It did feel a bit off, so I played around with Gmail a bit more to figure out what the difference was. Turns out it was quite simple, I don't know why I missed it in the original thread.

I thought the rule was to close the drawer on TOUCH_ACTION_DOWN, but it's not. It's TOUCH_ACTION_UP. (Which also ignores all swipes on the scrim, which also is exactly what happens in Gmail.)

So all that needs to be changed is this

B4X:
If IsOpen And Action = mBasePanel.TOUCH_ACTION_DOWN Then

...to this...

B4X:
If IsOpen And Action = mBasePanel.TOUCH_ACTION_UP Then
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
V1.03 implements the behavior you are talking about. Any touch on the scrim area causes the drawer to close. It is not done with an additional listener.

Adding a listener to DarkPanel is not good for two reasons:

1. The DarkPanel sits above the center panel. It will prevent touches from reaching the center panel when the drawer is closed and the DarkPanel is invisible. This can be solved.

2. This point is a bit more complicated. We want the user to be able to interact with the views in the left menu or on the left side of the screen and we want to detect swiping gestures. If the user touches a point that doesn't belong to any view (in the relevant area) then we can be almost sure that the user starts a swipe gesture. This is not the case if the point belongs to a view. In the later case we need to be careful not to "steal" the touch event too early or the user will have hard time interacting with the menu items (scrolling the list for example).
The difference between the two cases is: 3dip horizontal movement vs. 10dip horizontal movement. You can see these values in the code.

If you add a touch listener to the dark panel then you will lose the case where no view has consumed the touch event and it reached the base panel.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
I'm not sure I understand what you're talking about now, Erel. I haven't added a listener, I don't even know what they are.

The only thing I did was to change this sub (copied from 1.03):

B4X:
Private Sub Base_OnTouchEvent (Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
    Dim LeftPanelRightSide As Int = mLeftPanel.Left + mLeftPanel.Width
    If HandlingSwipe = False And x > LeftPanelRightSide Then
        If IsOpen And Action = mBasePanel.TOUCH_ACTION_DOWN Then ' <--- CHANGED TO TOUCH_ACTION_UP
            setLeftOpen(False)
            Return False
        End If
        If IsOpen = False And x > LeftPanelRightSide + ExtraWidth Then
            Return False
        End If
    End If
    Select Action
        Case mBasePanel.TOUCH_ACTION_MOVE
            Dim dx As Float = x - TouchXStart
            TouchXStart = X
            If HandlingSwipe Or Abs(dx) > 3dip Then
                HandlingSwipe = True
                ChangeOffset(mLeftPanel.Left + dx, True)
            End If
        Case mBasePanel.TOUCH_ACTION_UP
            If HandlingSwipe Then
                ChangeOffset(mLeftPanel.Left, False)
            End If
            HandlingSwipe = False
    End Select
    Return True
End Sub

I changed the fourth line, that's all. So it's considered being a "touch" when the finger leaves, not when it presses down.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
So that's what it was.
I too thought there was something different, but unlike you it didn't bother me too much, I just went with the flow. Well spotted @Sandman, all my Google created apps do close with the finger up and not down action, I've just checked. Hey even the link you supplied above to Google Navigation Drawer does the exact same thing through my mobile phone browser. When you press the burger menu button, the scrim reacts to finger up and not finger down, that's continuity for you.

Hmm, changing mBasePanel.TOUCH_ACTION_DOWN to
mBasePanel.TOUCH_ACTION_UP is what I probably would have done too if I had noticed it, but without trying it out for myself, I have absolutely no idea if TOUCH_ACTION_UP would work correctly. I have a strange feeling that it would cause an issue though.
 
Last edited:
Upvote 0
Top