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

Alexander Stolte

Expert
Licensed User
Longtime User
Update
  • 1.20
    • 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
PageChange
The event is triggered as soon as the action to change the page is received. e.g. The user releases the viewpager and the page is changed, as soon as the user releases, this event is triggered, even before scrolling. So things can be done in advance, before the complete page is visible.
PageChanged
With the event you can be sure that the page is done scrolling and the page has changed. This may be necessary if you do some things in the background on the viewpager, for example, dynamically add another page, without that the scrolling should be affected.
setIgnorePageChangeEvent
Sometimes you don't always need an event, then just dynamically set this property to false
 

Alexander Stolte

Expert
Licensed User
Longtime User
When sliding to the sides the tab line has a little delay, I liked it better before.
But this was necessary, because I had performance losses with my ASCalendarAdvanced after the page was changed, because I dynamically add more pages in the background and therefore the scrolling looked not so good.

Use the PageChange event.
 

angel_

Well-Known Member
Licensed User
Longtime User
So if you got it right, if I want the bar to move the same as the movement, I have to do this:

B4X:
Sub ASViewPager1_PageChange(Index As Int)
    TabStrip.ViewPager_PageChanged(Index)
End Sub

B4X:
Sub ASViewPager1_PageChanged(Index As Int)
'Code at the end of the action (end of scrolling)
End Sub
 

angel_

Well-Known Member
Licensed User
Longtime User
I think I explained myself wrong, this code works fine:

B4X:
Sub ASViewPager1_PageChange(Index As Int)
    TabStrip.ViewPager_PageChanged(Index)
End Sub

So I can use PageChange unless I have performance issues in transition in that case I should use PageChanged, is this interpretation correct?
 

angel_

Well-Known Member
Licensed User
Longtime User
I have noticed that when you swipe with rapid movement instead of going to the next tab it goes to the last

B4X:
Sub ASViewPager1_PageChange(Index As Int)
    TabStrip.ViewPager_PageChanged(Index)
    'code...
End Sub
 

angel_

Well-Known Member
Licensed User
Longtime User
Not every swipe the user makes should also go to the next page, if the gesture is too short or too fast, then the process stops.
With a newer device (Oneplus 8T, android 11) it is quite fluid but some lag in some demanding transition, with another older device (Oneplus one, android 10) the movement is erratic, with fast movements it jumps several tabs and goes to the last, sometimes it does not jump to the next tab as you say
 

wimpie3

Well-Known Member
Licensed User
Longtime User
Suppose you have loaded a page from a layout, like this:
B4X:
    Dim page1 As B4XView=xui.CreatePanel("")
    page1.LoadLayout("layout_page1")
    page1.SetLayoutAnimated(0,0,0,ASViewPager1.Base.Width,ASViewPager1.Base.Height)
    ASViewPager1.addpage(page1,"")

And later on in your code, you remove that page with
B4X:
ASViewPager1.RemovePage(1)

What happens with the variables used in layout_page1? Will they still exist in the activity or will they be empty?
 

angel_

Well-Known Member
Licensed User
Longtime User
Unfortunately still not working well, it takes a very long swipe almost from side to side to get it to the next tab
 

Alexander Stolte

Expert
Licensed User
Longtime User
In release mode it seems to work fine
You don't publish your app in debug mode... That's why Erel has been preaching "test it in release mode first" for years. In debug mode everything runs slowly. You can scroll a list in debug mode, or let it scroll, you will see, it is extremely jerky.

Even on my Iphone 12 Pro max I have problems to get to a next page in debug mode.
I'll test it later with my old 5s and I can tell you right now, in release mode, it will run just as fast as on the 12 pro.
 

angel_

Well-Known Member
Licensed User
Longtime User
When I do a quick swipe up (release mode, B4i) it jumps to the next tab, can it be disabled?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…