Android Question Swipe to Close Page

Hi, I want to implement in B4XPages (B4A) a gesture where, when the user swipes from the left edge to the right, the current page moves dynamically following the finger, revealing the previous page behind it. If the swipe passes a certain distance, the current page should close with an animation; otherwise, it should return to its original position — exactly like the swipe-back effect in Telegram chats.
 

epiCode

Active Member
Licensed User
You can achieve that using
1. sliding layouts (multiple b4a libraries are available each with its own merit)
2. use horizontal CLV with snap feature
3. viewpager (ahviewpager, as viewpager)
4. flowmenu
 
Upvote 0
You can achieve that using
1. sliding layouts (multiple b4a libraries are available each with its own merit)
2. use horizontal CLV with snap feature
3. viewpager (ahviewpager, as viewpager)
4. flowmenu
I don't want to use non-standard or non-optimal methods, and more importantly, the solution must be fully compatible with b4xPages.
 
Upvote 0
Upvote 0
I tried to implement it like this but it doesn't work!
B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    
    Private StartX As Float
    Private IsSwiping As Boolean
    Private Threshold As Int = 100dip
End Sub

Public Sub Initialize As Object
    Return Me
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.Color=Colors.Blue
End Sub

Private Sub Root_Touch (Action As Int, X As Float, Y As Float)
    Select Action
        Case Root.TOUCH_ACTION_DOWN
            StartX = X
            IsSwiping = True
        Case Root.TOUCH_ACTION_MOVE
            If IsSwiping Then
                Dim dx As Float = X - StartX
                If dx > 0 Then
                    Root.Left = dx
                End If
            End If
        Case Root.TOUCH_ACTION_UP
            If IsSwiping Then
                Dim dx As Float = X - StartX
                If dx > Threshold Then
                    B4XPages.ClosePage(Me)
                Else
                    Root.Left = 0
                End If
                IsSwiping = False
            End If
    End Select
End Sub
 
Upvote 0

epiCode

Active Member
Licensed User
I tried to implement it like this but it doesn't work!
You need to elaborate on what happens and what did you expect because nobody knows what is "doesn't work"

Also you do not have to work with "root" if you were seeking a b4xpages compatible solution.
Refer to examples of "b4xpages transitions" and see how they create and animate pages and use same method in your logic.
 
Upvote 0
Top