How does ScrollView paging works? - react-native

Docs says When pagingEnabled is set to true, the scroll view stops on multiples of the scroll view's size when scrolling. This can be used for horizontal pagination.
I am trying to implement a carousel with say 15 items. I want to display only 5 items at a time. Every time the user scrolls, I want to scroll to the next 5 items
I am trying to figure out how the page size determined? in case of the above example, I want to set the page size to 5
What are the mandatory properties to set to achieve pagination?

Related

Is there a way to synchronize the scroll of two different scroll views which are on the same page?

I have two scroll views in my app. First one contains header of a list which works horizontally and the second contains the list which works horizontally and vertically ( in both directions). So now I want to synchronize the scroll of both scroll views. I want both scroll views work simultaneously.
You would need to look into the Scroll event and the Scroll To delegate action of a ScrollView
Scrolled event documentation can be found here
ScrollToAsync documentation can be found here
Depending on exactly what you're trying to achieve you could assign the the ScrollView.Scrolled event of each ScrollView:
ScrollView.Scrolled += ()=>{
// If vertical get Scroll Y and translate it to your second ScrollViews Scroll X
SecondScrollView.ScrollToAsync(ScrollView.ScrollX, SecondScrollView.ScrollY, true)
}
SecondScrollView.Scrolled += ()=>{
// If vertical get Scroll X and translate it to your first ScrollViews Scroll Y
ScrollView.ScrollToAsync(SecondScrollView.ScrollX, ScrollView.ScrollY, true)
}
I haven't had chance to test the above, it's more of a quick example to get you going in the right direction, a few things you'd have to look out for behavior wise is when ScrollToAsync is called it will likely fire off the scroll event of that ScrollView So you'll want to handle that to ensure there isn't some weird recursive behaviour.

ngx-datatable - Setting a table height

I have an ngx-datatable with server-side pagination. Given a page size of say 100 rows, the table grows vertically to display all the rows. However, I want to keep the table to a fixed height though, say with a viewport that shows 10 and a vertical scrollbar to scroll through the 100 in the current loaded page. (not using server-scrolling (scrollbarV)) - local scroll of the loaded page.
Is there a way to do this?
I also noticed that server-scrolling appears to use 5 rows by default even if my page size is say 100. Is that a setting somewhere?

Remove 'hidden' images from UIScrollView

I have a scrollView that shows images set by url. Now I only want the visible image and the previous and next image to be pre-loaded onto the scrollView to reduce memory usage. How do I accomplish this?
If you use a UITableView instead of a UIScrollView, you can create your own UITableViewCell type which loads 1 image in its content.
The advantage is that only the visible UITableViewCells (those currently displaying on the device's screen) are loaded into the system memory, so it won't use too much resources.
Here is one of the many CustomCell Tutorials you will find on the Internet.
When I did the same I created a UIScrollView of 3 times the size. Just big enough to hold the 3 images, the one that is currently displayed and the next siblings to the right and the left.
Those images are pre-loaded if they have not been loaded before. So the user has some smooth and responsive look & feel.
When the user scrolls to the next one, and he can scroll for one only, then I re-arrange the view. Lets say images 1, 2 and 3 are in the scroll view and 2 is visible, so 1, 2 and 3 are (pre-)loaded. The user scrolls to the right. Image 3 will be visible. As soon as it becomes fully visible I set the visible rect of the scroll view to the middle again. Now Image 2 is the left most one, image 3 is visible and image 4 is placed as the right most one and pre-loaded.
When the end of the list of images is reached, meaning when the 1st or last one are displayed, then I place a dummy view on the left most or right most place respectivly that is a simple text view showing "no more images".
Unfortunately I cannot share that code.

Scrolling through UIButtons on a UIView

I have 50 UIButtons.
Only 10 UIButtons are allowed to show on the UIView at a time.
How do I set this up to allow the user to scroll through the list of 50 buttons?
thx
As the other users have said you can do it with a scroll view.
Personally I think it might be easier with a tableview, (provided its not a specific 10, just 10 consecutive buttons). You could arrange the tableview to remove the separators, and adjust the cell heights so only 10 cells fit on the screen.
This seems simpler to me. And you may have no need for UIButtons if you implement didSelectRowAtIndexPath:.
add the 50 buttons to a scroll view.
Set the scroll view to be paging enabled..
be the delegate and check the content offset of the scroll view to determine which page user is on..
load the buttons of the page..and remove other page buttons to free up memory.(add later when user come back to page)

How to make a side-scrolling object?

I would like to make a side-scrolling object that is only 200 pixels wide and 50 pixels tall. This side-scrolling object would contain five different objects that, when scrolled into the middle, act as if selected. How could I go about doing this?
I want sort of the same effect that the iPhone home screen has where it latches on to a page when you slide it. Instead of latching on to the pages though, I want it to latch on to my five different objects.
The side-scrolling behavior is achieved with a UIScrollView with pagingEnabled set to YES. Set the scroll view's width to the size of your pages. Your scroll view delegate can calculate which object is on screen by dividing contentOffset.x by the scroll view's width.
If you want to show several items on the screen at once but still page between the individual items--think of the way the iWork apps show multiple documents, for example--there are three steps involved:
Set the scroll view's width to the width of the objects, not the width of the screen.
Set the scroll view's clipsToBounds property to NO so it displays the objects that aren't within the scroll view's frame.
Subclass UIScrollView and override -pointInside:withEvent: to return YES if the point is within the area you want to respond to touches within. (For example, if you want to respond to touches within the entire width of the screen, just ignore x and make sure y is between the top and bottom of the view.) Use this subclass instead of a standard UIScrollView.