B4A Library [B4X] [XUI] AS ViewPagerNative based on AHViewPager and iTabstrip

The goal was to create a cross-platform viewpager based on existing viewpagers. Since AHViewPager and iTabstrip are very different, the view helps to create a unified interface.

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 and B4I.
B4J is currently not compatible, maybe this will change in the future.
B4a: XUi,AHViewPager
B4i: iXUI,iTabStrip
B4A: Make sure you have the AHViewPager V3.00
B4I: Make sure you have the ButtonCell.xib in the Special folder
B4A and B4I
21-10-27-23-30-23.gif
RPReplay_Final1635369956.gif

ASViewPagerNative
Author: Alexander Stolte
Version: 1.01

  • ASViewPagerNative
    • Events:
      • PageChanged (Index As Int)
      • ReachEnd
    • Fields:
      • mBase As B4XView
      • Tag As Object
    • Functions:
      • AddPages (ListOfPanels As List, Text As String) As String
      • Base_Resize (Width As Double, Height As Double) As String
      • Class_Globals As String
      • DesignerCreateView (Base As Object, Lbl As Label, Props As Map) As String
        Base type must be Object
      • getCurrentIndex As Int
        gets or sets the current index
      • getNativeViewPager As de.amberhome.viewpager.AHViewPager
      • getSize As Int
        Gets the number of pages
      • Initialize (Callback As Object, EventName As String) As String
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • NextPage As String
        Smooth goes to next page
      • PreviousPage As String
        Smooth goes to previous page
      • setCurrentIndex (Index As Int) As String
        gets or sets the current index
      • setCurrentIndexAnimated (Index As Int) As String
        sets the current index animated
    • Properties:
      • CurrentIndex As Int
        gets or sets the current index
      • CurrentIndexAnimated
        sets the current index animated
      • NativeViewPager As de.amberhome.viewpager.AHViewPager [read only]
      • Size As Int [read only]
        Gets the number of pages
Changelog
  • 1.00
    • Add Event ReachEnd - Triggers if the last page is selected
    • Add get NativeViewPager - Gets the native ViewPager View in B4A: AHViewPager B4I: iTabstrip
    • Add get CurrentIndex - Gets the current index
    • Add set CurrentIndexAnimated - Sets the current index animated
    • BreakingChange set CurrentPage renamed to set CurrentIndex
    • Add get Size - Gets the number of pages
    • Base_Resize is now Public
    • Add NextPage - Smooth goes to next page
    • Add PreviousPage - Smooth goes to previous page
  • 1.01
    • AddPages - Remove "Text" Parameter
Have Fun :)
 

Attachments

  • ASViewPagerNative Example.zip
    11.3 KB · Views: 443
  • ASViewPagerNative.b4xlib
    3.3 KB · Views: 413
Last edited:

Alexander Stolte

Expert
Licensed User
Longtime User
I would like to know if there are some pros and cons between ASViewPager and ASViewPagerNative.
It's hard for me, but I'll try to list something.
ASViewPager
  • Pros
    • Fully customizable
    • Based on a cross-platform list
      • Lazy loading and other things possible
    • Horizontal + Vertical slide
    • Carousel
    • some custom views are based on this
      • you can create some easier
  • Cons
    • Google Maps or other maps do not work properly when they are on the ViewPager
    • can be further optimized
ASViewPagerNative
  • Pros
    • Google Maps or other maps work
    • Based on already working viewpager
    • views with complicating gestures work better
    • under circumstances the swiping works better
  • Cons
    • Only conditionally customizable
    • Not all functions of the ASViewPager available
    • Adding pages not completely consistent possible (want to try something later)
 

TILogistic

Expert
Licensed User
Longtime User
It's hard for me, but I'll try to list something.
ASViewPager
  • Pros
    • Fully customizable
    • Based on a cross-platform list
      • Lazy loading and other things possible
    • Horizontal + Vertical slide
    • Carousel
    • some custom views are based on this
      • you can create some easier
  • Cons
    • Google Maps or other maps do not work properly when they are on the ViewPager
    • can be further optimized
ASViewPagerNative
  • Pros
    • Google Maps or other maps work
    • Based on already working viewpager
    • views with complicating gestures work better
    • under circumstances the swiping works better
  • Cons
    • Only conditionally customizable
    • Not all functions of the ASViewPager available
    • Adding pages not completely consistent possible (want to try something later)
and how does it work with a camera embedded in a page or tab?
 

EduardoElias

Well-Known Member
Licensed User
Longtime User
Hi Alexander, I am getting the following error o iOS

1635416171152.png


this is the code:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.Color = xui.Color_White

    Root.LoadLayout("pageMain")
'    FillViewPager

'    FillCarOptions
'    FillNews
'    FillSettings
'
    
End Sub

Private Sub B4XPage_Appear
    If FirstTime Then
        FillViewPager
        StartMap
        FirstTime = False
    End If
End Sub

#Region Main Page
Private Sub FillViewPager

    Dim lst As List
    lst.Initialize

    AddPage("pvMyCar", lst)
    AddPage("pvHome", lst)
    AddPage("pvSettings", lst)
    spMain.AddPages(lst, "text")

The error happens on the last line when addpages is called. The very same code works on android.

I am using the library posted on this thread
 

EduardoElias

Well-Known Member
Licensed User
Longtime User
and how should I now know what your AddPage function does?
Remember, with B4I you have to add a page instead of a panel to the list, see the example project. And post errors as text, the image doesn't show much.
I am sorry !

B4X:
    Dim lst As List
    lst.Initialize

    AddPage("pvMyCar", lst)

Private Sub AddPage(aPage As String, alst As List)
    #If B4A
        Dim xpnl As B4XView = xui.CreatePanel("")
        xpnl.Color = Rnd(xui.Color_Black,xui.Color_White)
        xpnl.SetLayoutAnimated(0,0,0,Root.Width,Root.Height)
        xpnl.LoadLayout(aPage)
        alst.Add(xpnl)
    #Else If B4I
        Dim page As Page
        page.Initialize("page")
        page.RootPanel.Color = Rnd(xui.Color_Black,xui.Color_White)
        page.RootPanel.As(B4XView).SetLayoutAnimated(0,0,0,Root.Width,Root.Height)
        page.RootPanel.LoadLayout(aPage)
        alst.Add(page)
    #End If
End Sub

B4X:
, _spmain=[_meventname=spmain, _mcallback=, _mbase=<B4XViewWrapper: <B4IPanelView: 0x14be52650; frame = (0 0; 375 557); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x280721920>; layer = <CALayer: 0x280929780>>>
, _xui=<B4IXUI: 0x280b0df50>, _xclv_main=, _current_index=0
, _g_x=0, _g_y=0, _g_dv=0
, _g_ad=0, _g_ms=0, _isfirstmove=0
, _tmp=, _g_ignorepagechangedevent=0, _g_ignorepagechangeevent=0
, _g_orientation=Horizontal, _g_carousel=0, _ismoving=0
, _g_isscrollenabled=1, _tag=, _dateutils=<b4i_dateutils: (null)>
, _main=<b4i_main: (null)>, _mycode=<b4i_mycode: (null)>, _yconsts=<b4i_yconsts: (null)>
, _b4xpages=<b4i_b4xpages: (null)>, _b4xcollections=<b4i_b4xcollections: (null)>, _httputils2service=<b4i_httputils2service: (null)>
, _xuiviewsutils=<b4i_xuiviewsutils: (null)>, _yglobalapiconsts=<b4i_yglobalapiconsts: (null)>], _viewpagerplaces=, _lstimage=<B4IList: (null)>
, _lstname=<B4IList: (null)>, _lstrank=<B4IList: (null)>, _lstduc=<B4IList: (null)>
, _lsttime=<B4IList: (null)>, _lstview=<B4IList: (null)>, _indexduc=0
, _btnpvhomelista=<B4XViewWrapper: <UIButton: 0x14bd52cb0; frame = (10 10; 40 40); opaque = NO; layer = <CALayer: 0x28092cbc0>>>, _btnpvhomelike=<B4XViewWrapper: <UIButton: 0x14bd53a20; frame = (325 10; 40 40); opaque = NO; layer = <CALayer: 0x28092ce80>>>, _wobblemenumain=
, _clvcaroptions=, _clvsettings=, _lblcardsettingssetting=<B4XViewWrapper: (null)>
, _lblcardsettingsicon=<B4XViewWrapper: (null)>, _lblpvsettingstitle=<B4XViewWrapper: <UILabel: 0x14be60210; frame = (90 15; 195 38); text = 'Configurações'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x282a1a8a0>>>, _lblcaroptionstitle=<B4XViewWrapper: (null)>
, _lblcaroptionsdesc=<B4XViewWrapper: (null)>, _ivcaroptions=<B4XViewWrapper: (null)>, _btncardparkestacione=
, _lblparkplacename=<B4XViewWrapper: (null)>, _pnlpvhomeplaces=<B4IPanelWrapper: <B4IPanelView: 0x14bd54040; frame = (0 517; 375 130); clipsToBounds = YES; layer = <CALayer: 0x28092d0e0>>>, _pnlpvhomemap=<B4XViewWrapper: <B4IPanelView: 0x14bd54950; frame = (0 70; 375 647); clipsToBounds = YES (message truncated)...
Stack Trace: (
  CoreFoundation       <redacted> + 252
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       <redacted> + 0
  SigaVaga             +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 336
  SigaVaga             -[B4IShell runMethod:] + 448
  SigaVaga             -[B4IShell raiseEventImpl:method:args::] + 1648
  SigaVaga             -[B4IShellBI raiseEvent:event:params:] + 1580
  SigaVaga             __33-[B4I raiseUIEvent:event:params:]_block_invoke + 52
  libdispatch.dylib    <redacted> + 24
  libdispatch.dylib    <redacted> + 16
 libdispatch.dylib    <redacted> + 1068
 CoreFoundation       <redacted> + 12
 CoreFoundation       <redacted> + 1924
 CoreFoundation       CFRunLoopRunSpecific + 436
 GraphicsServices     GSEventRunModal + 104
 UIKitCore            UIApplicationMain + 212
 SigaVaga             main + 120
 libdyld.dylib        <redacted> + 4
)
 

Alexander Stolte

Expert
Licensed User
Longtime User
I don't think the problem is with the view, the log doesn't even have the name of my view or the iTabStrip. Generally I don't see any error message. Build the view pager in the create event and not in the appear event. If that doesn't work, then you can extract the .bas file from the .b4xlib and mount it to see in which line it stays, I'm sure not, because the error is not caused by the view.
Anyway, it's better to make an example project showing the error and open a new thread.
 

sultan87

Active Member
Licensed User
Longtime User
Bonjour je voudrais utiliser votre projet comme exemple en B4A
il me manque la librairie asviewpagernative
j'ai récupéré ASViewPagerNative.b4xlib
je ne sais pas comment l'utiliser pour faire fonctionner ce projet
pouvez vous m'aider
pierre
 

sultan87

Active Member
Licensed User
Longtime User
Hello I would like to use your project as an example in B4A I miss the asviewpagernative library I got ASViewPagerNative.b4xlib I don't know how to use it to make this project work can you help me Pierre
 
Top