B4A Library [B4X] [XUI] AS ViewPager based on xCustomListView

Hey,
thanks to @KZero for his good zPager class, i was able to extract a few things from it to make this cross platform view.

I spend a lot of time in creating views, some views i need by my self, but some views not and to create a high quality view cost a lot of time. If you want to support me, then you can do it here by Paypal. :)

This library is compatible and tested with B4A,B4I and B4J!
If you have bugs or a wish then tell me it in the comments.

On B4J use the LEFT and RIGHT keys on your keyboard to change the page.
On B4I you need the GestureRecognizer class. Download it down below.
B4j: jXUI,JavaObject,xCustomListView,jReflection
B4a: XUi,Reflection,xCustomListView
B4i: iXUI,xCustomListView
Features
  • cross-platform compatible
  • based on a cross-platform ListView
  • add and remove pages
  • scroll to pages
  • a good swipe feeling
  • NEW - Vertical
  • NEW - Carousel
Horizontal and Vertical
20-04-22-20-36-012.gif
20-08-15-11-33-40.gif

B4A Carousel and B4I Carousel
B4A Carousel.gif
B4I Carousel.gif

ASViewPager
Author: Alexander Stolte
Version: 1.20

  • ASViewPager
    • Events:
      • PageChange (Index As Int)
      • PageChanged (Index As Int)
      • PageClick (Index As Int, Value As Object)
      • ReachEnd
      • ScrollChanged (Offset As Int)
      • TouchBegin
      • TouchEnd
    • Fields:
      • Tag As Object
    • Functions:
      • AddPage (xpnl_layout As B4XView, value As Object) As String
      • AddPageAt (index As Int, xpnl_layout As B4XView, value As Object) As String
        Adds an page at a special position
      • Base_Resize (Width As Double, Height As Double) As String
      • Class_Globals As String
      • Clear As String
      • DesignerCreateView (Base As Object, Lbl As Label, Props As Map) As String
        Base type must be Object
      • getBase As B4XView
      • getCurrentIndex As Int
      • getCustomListView As b4a.example3.customlistview
      • getisScrollEnabled As Boolean
        Checks if the swipe/scroll is enabled or disabled
      • getSize As Int
      • Initialize (Callback As Object, EventName As String) As String
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • NextPage As String
      • NextPage2 As String
        Jump to next page
      • PreviousPage As String
      • PreviousPage2 As String
        jump to previous page
      • RemovePage (index As Int) As String
      • setCurrentIndex (index As Int) As String
      • setCurrentIndex2 (index As Int) As String
        sets the current index - jumps to the item
      • setIgnorePageChangedEvent (ignore As Boolean) As String
      • setIgnorePageChangeEvent (ignore As Boolean) As String
      • setScroll (enabled As Boolean) As String
        B4I and B4A only
        enabled - False the scroll is deactivated
    • Properties:
      • Base As B4XView [read only]
      • CurrentIndex As Int
      • CurrentIndex2
        sets the current index - jumps to the item
      • CustomListView As b4a.example3.customlistview [read only]
      • IgnorePageChangedEvent
      • IgnorePageChangeEvent
      • isScrollEnabled As Boolean [read only]
        Checks if the swipe/scroll is enabled or disabled
      • Scroll
        B4I and B4A only
        enabled - False the scroll is deactivated
      • Size As Int [read only]
Changelog
  • 1.00
    • Release
  • 1.01
    • Base_Resize is now public
    • NextPage and PreviousPage Bug Fix
    • setCurrentIndex Bug Fix
    • PageChangeEvent Bug Fix
  • 1.02
    • B4I Bug Fixes
    • NextPage and PreviousPage Bug Fix
  • 1.03
    • Resize BugFix
  • 1.04
    • B4I Page-Height BugFix
    • B4I Page-Swipe BugFix
  • 1.05
    • BugFix
  • 1.06
    • Add Designer Property "Orientation" - Vertical is now supported
  • 1.07
    • BugFix getCurrentIndex
    • BugFix PageChanged event is now only firing if the index is changed
    • Add setIgnorePageChangedEvent Property
    • Add TouchBegin Event
    • Add TouchEnd Event
    • BugFix PageChanged is now firing if you press on a emulator, for example the arrow up or down keys on yor keyboard
  • 1.08
  • 1.09
    • B4I BugFixes for Release Mode - swiping is now better
  • 1.10
    • Add AddPageAt (experimental it works for my need, if you have issuses, then tell me) - Adds an page at a special position
    • Add set CurrentIndex2 - sets the current index - jumps to the item
    • Better resize handling
  • 1.11
    • RemovePage Bugfixes
    • B4J ScrollPane under the hood is now Transparent
    • Add NextPage2 -Jump to next page
    • Add PrevoiusPage2 - Jump to previous page
  • 1.12
    • [BETA] Add DesignerProperty Carousel - infinite swipe
      • On B4I Bounce Effect is disabled
    • B4I ScrollView Paging is now activated, this can improve the handling
  • 1.13
    • Add PageClick Event
  • 1.14 - read more about this update here
    • [B4I only] Add Scroll - enable or disable scroll with finger
      • ASViewPager1.Scroll(False)'disable scroll with finger
  • 1.15
    • Intern Function IIF renamed to iif2
  • 1.16
    • set Scroll is now B4X - disable the swipe/scroll
      • In B4J the arrow keys (Left/Right/Up/Down) are disabled if you deactivate the swipe/scroll
    • New property isScrollEnabled - checks if the swipe/scroll is enabled or disabled
    • Intern Function iif2 removed and the core iif is now used
      • B4A V11+ - B4J V9.10+ - B4I V7.50+
  • 1.18
    • PageChanged Event is now firing in some cases with a delay, because of a scroll animation
    • BugFix B4A setScroll - Events from other views are now no longer blocked
  • 1.19
    • BugFix on NextPage and PreviousPage
  • 1.20 (read more about this update)
    • Add Event PageChange - This event is triggered immediately after the page is changed, no delay because of animations
    • Add setIgnorePageChangeEvent - prevents the PageChange event from being triggered
  • 1.21
    • BugFixes
  • 1.22
    • B4I Scroll = False BugFix
  • 1.24
    • BugFix AddPageAt is now working better on B4A
Have Fun :)
 

Attachments

  • B4X Example.zip
    9.9 KB · Views: 418
  • GestureRecognizer.bas
    11.2 KB · Views: 217
  • ASViewPager.b4xlib
    5 KB · Views: 83
Last edited:

Alexander Stolte

Expert
Licensed User
Update
1.14

  • [B4I only] Add Scroll - enable or disable scroll with finger
In some cases it is useful to prevent scrolling. Especially if you work with several xCustomLsitView at the same time.
In B4I you can disable native, in B4A native is not possible. There you have to add a dummy item, which then blocks the touch event.
An example from a real project of mine:
B4X:
Private Sub ASCalendarAdvanced1_TouchDown
    #If B4I
    ASViewPager1.Scroll(False)
    #End If
End Sub
Why do I have to deactivate the ViewPager to expand the calendar with my finger?
Answer: as soon as I drag the calendar downwards, I also address the ViewPager at the same time and it scrolls along and that is not a nice behavior.

When do I enable the ViewPager?
The calendar has an event called "_TouchUp" so I can be sure that the user has his fingers off the ViewPager and can activate it again.
 

Alessandro71

Active Member
Licensed User
any reports of crashing in GestureRecognizer on B4i?
I've just upgraded to 1.15 and my previously working app crashes as soon as touch the screen with the following message
B4X:
Error occurred on line: 174 (GestureRecognizer)
Expected: NSInputStream, object type: __NSCFNumber
Stack Trace: (
  CoreFoundation       F3021642-E3C0-33F8-9911-DD303A6056D0 + 1157612
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       F3021642-E3C0-33F8-9911-DD303A6056D0 + 120016
  Power checK Control  -[B4IObjectWrapper setObject:] + 276
  Power checK Control  +[B4IObjectWrapper createWrapper:object:] + 108
  Power checK Control  -[b4i_gesturerecognizer _uigesture_longpress:::::::] + 1116
  CoreFoundation       F3021642-E3C0-33F8-9911-DD303A6056D0 + 1175856
  CoreFoundation       F3021642-E3C0-33F8-9911-DD303A6056D0 + 8656
  Power checK Control  +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1608
  Power checK Control  -[B4IShell runMethod:] + 448
 Power checK Control  -[B4IShell raiseEventImpl:method:args::] + 2172
 Power checK Control  -[B4IShellBI raiseEvent:event:params:] + 1580
 Power checK Control  -[b4i_gesturerecognizer handleLongPress:] + 848
 UIKitCore            CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 7029756
 UIKitCore            CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 7068016
 UIKitCore            CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 7054840
 UIKitCore            CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 7052224
 UIKitCore            CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 7004496
 UIKitCore            CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 7001312
 UIKitCore            CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 11998412
 UIKitCore            CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 11848460
 UIKitCore            CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 12382328
 UIKitCore            CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 12400664
 UIKitCore            CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 12364540
 CoreFoundation       F3021642-E3C0-33F8-9911-DD303A6056D0 + 633840
 CoreFoundation       F3021642-E3C0-33F8-9911-DD303A6056D0 + 633584
 CoreFoundation       F3021642-E3C0-33F8-9911-DD303A6056D0 + 630328
 CoreFoundation       F3021642-E3C0-33F8-9911-DD303A6056D0 + 607200
 CoreFoundation       CFRunLoopRunSpecific + 572
 GraphicsServices     GSEventRunModal + 160
 UIKitCore            CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 11723508
 UIKitCore            UIApplicationMain + 164
 Power checK Control  main + 128
 libdyld.dylib        0B475C78-3C12-3121-B7F8-2B95B83DAF44 + 5480
)

line 174 is the last one in this block from GestureRecognizer class
B4X:
Private Sub uigesture_longpress(state As Int,numtouch As Int, Numtaps As Int, x As Float, y As Float, obj As Object)
Dim att As  LongPress_Attributes
att.NumberOfTaps=Numtaps            'ignore
 

Alessandro71

Active Member
Licensed User
I was able to reproduce the issue with your B4A Example package also, so I'm still using this thread because it looks like a library issue.
Here are the steps I followed (environment is B4i 7.20 with hosted builder: please note that this is a B4i, not a B4A issue)
- Download the B4A Example zip from the first page
- Extract
- Download GestureRecognizer.bas from the link in the first page also, and put it in the B4i project directory
- Flag ASPageViewer in the Libraries Manager tab (it's missing in the example project)
- Change the provisioning file and the package name to match my original project (along with a blessing to Apple for turning even a simple step into a waste of time)
- Compile in Debug mode and send to B4i Bridge on a real device
The app starts fine, but as soon as you touch the screen, it crashes with
B4X:
Error occurred on line: 174 (GestureRecognizer)
Line 174 is
B4X:
att.NumberOfTaps=Numtaps
Where a warning #22 is also present since NumberOfTaps is an InputStream while Numtaps is an Int
 

Alexander Stolte

Expert
Licensed User
Download GestureRecognizer.bas from the link in the first page also, and put it in the B4i project directory
then download the .bas file againn, I have now added the class to the 1st post. Months ago I had already adapted the class for the ASCalendarAdvanced there I had said error.
 

wimpie3

Well-Known Member
Licensed User
Update
1.14

  • [B4I only] Add Scroll - enable or disable scroll with finger
In some cases it is useful to prevent scrolling. Especially if you work with several xCustomLsitView at the same time.
In B4I you can disable native, in B4A native is not possible. There you have to add a dummy item, which then blocks the touch event.
An example from a real project of mine:
B4X:
Private Sub ASCalendarAdvanced1_TouchDown
    #If B4I
    ASViewPager1.Scroll(False)
    #End If
End Sub
Why do I have to deactivate the ViewPager to expand the calendar with my finger?
Answer: as soon as I drag the calendar downwards, I also address the ViewPager at the same time and it scrolls along and that is not a nice behavior.

When do I enable the ViewPager?
The calendar has an event called "_TouchUp" so I can be sure that the user has his fingers off the ViewPager and can activate it again.

Sorry but this is not very clear to me. What do I have to do to disable finger scrolling completely? I guess for IOS it's:
B4X:
    #If B4I
    ASViewPager1.Scroll(False)
    #End If

But how do you do it on Android?
 

Alexander Stolte

Expert
Licensed User
Sorry but this is not very clear to me. What do I have to do to disable finger scrolling completely? I guess for IOS it's:
yes, in B4I the scrollview has an internal function to disable swiping. The B4A listview unfortunately does not have this.
But how do you do it on Android?
In B4A you have to place a panel with the full width and length and catch the touch event from it.
An example is attached.
And if you want to enable it again, simply call panel1.visible = False
 

Attachments

  • Disable Swiping.zip
    5 KB · Views: 44

wimpie3

Well-Known Member
Licensed User
It is not possible otherwise!
I could still make it build in...
Yes why not, I think other people could find this interesting as well. As long as the panel supports click-throughs (we still need to be able to fill in form fields for instance on the page below the panel) I think I'd prefer this solution.
 

Alexander Stolte

Expert
Licensed User
Update
  • 1.16
    • set Scroll is now B4X - disable the swipe/scroll
      • In B4J the arrow keys (Left/Right/Up/Down) are disabled if you deactivate the swipe/scroll
    • New property isScrollEnabled - checks if the swipe/scroll is enabled or disabled
    • Intern Function iif2 removed and the core iif is now used
      • B4A V11+ - B4J V9.10+ - B4I V7.50+
 
Last edited:

wimpie3

Well-Known Member
Licensed User
Update
  • 1.16
    • set Scroll is now B4X - disable the swipe/scroll
      • In B4J the arrow keys (Left/Right/Up/Down) are disabled if you deactivate the swipe/scroll
    • New property isScrollEnabled - checks if the swipe/scroll is enabled or disabled
    • Intern Function iif2 removed and the core iif is now used
      • B4A V9.10+ - B4J V9.10+ - B4I V7.50+

Thanks, great work!

When isScrollEnabled is false, are events still passed onto the underlying views? In other words, can you still scroll through a list view on a view page for instance?
 

angel_

Well-Known Member
Licensed User
Update
  • 1.18
    • PageChanged Event is now firing in some cases with a delay, because of a scroll animation
    • BugFix B4A setScroll - Events from other views are now no longer blocked
When sliding to the sides the tab line has a little delay, I liked it better before.

By the way, the problem I had with the intermediate position of the tab seems to be solved
 
Last edited:
Top