I have a scrollView with 4 page; I want to change it's background color at every page; then I want to know index page value. For example, if I have page 1, I want to know that I have index 1 then background must be red or if I have page 3, I want to know that I have index 3 and background color must be blue.
then I want to do an "if" where I control if my current page have index 1, or index 2, or index 3.....
The page index is found by: scrollview.contentOffset.x / scrollview.frame.size.width.
To set the background color you can either:
implement the delegate methods for responding to scroll ending.
Insert subviews with their background colours set at the page index offsets.
There is problem with option one. When transitioning between pages the background colour will be incorrect until the scrolling ends.
Related
I have a ScrollableRow with lets say 5 fullscreen composables.
ScrollableRow(
modifier = Modifier.fillMaxSize(),
scrollState = scrollState) {
myData.items.forEachIndexed{ index, pageItem ->
showPage(pageItem)
}
}
Everything is shown so far, but when I swipe left/right it stops exactly on the position, where I stopped swiping:
As you can see and imagne, almost everytime it stops between two of these full screen composables.
I'd rather have a kind of stickyness and show full pages for each single left/right swipe as pictured here:
So obviously, here in the second picture with third page showing:
when I swipe one time left, I want to see full screen page 4, only
when I swipe one time right, I want to see full screen page 2, only
I bet there is a mechanism for this?
HorizontalPager will suit you. Check Accompanist Pager layouts
I have two pages, both with their own Scaffold and a slightly different AppBar. I use Navigator.push to switch between them.
The second page is a popup which overlays the first page by having a transparent Scaffold with body of about 50% screen height. Here's how it looks:
In the first page, the red curtain ends just below the AppBar. When you open the second page, the curtain animates down to the screenshot above. I achieved this by starting the down animation in initState of the second screen.
Now, I want the opposite animation of the curtain rolling back up when you leave the second page. How would I do that? Is there a way to animate widgets (not just fade/slide whole pages) when you enter/leave the page?
Can I access the Route's transition animation (the same one that is passed to Route.buildTransitions) and use it to animate widgets inside the page itself?
I have a custom cell where it displays a table like structure with multiple columns.
Each row has a column that is a button that will perform different tasks.
My issue is trying to get the middle column to communicate its state with the other rows.
Initially everything will be grey (not selected) but, when I tap the middle column button, the state will be green. When I select a different row that button will turn green and the previous row would be grey.
Again, each column in the row is a button that does something different (i.e. the right button loads up a modal view). I have tried to use
didSelectRowAtIndexPath but, with the overlapping custom views it does not seem to read the selection.
Any help would be appreciated
White boxes represent items in an NSArray.
Swiping from a directing changes the indexes and update the items accordingly. (not scrolling 1 by 1 but like changing pages. So, changing all 4 items at every swipe)
In this example, there are approximately 20 items in this array and we are in the second page. It currently shows item at index 4,5,6,7.
There can be more items.
I don't want to create at least 20 items and keep them at a far frame (CGRect).
I want to have a scheme like UITableView, where it creates approximately 6 items for infinite number of items if the tableview can show only 4 items at a time.
So, I plan to have 5 or 6 items for 6+ items and just update the item's contents (item = white boxes) according to real data at that index of NSArray
Is there a quick and ready way to do this easily or may there be a better way to do something like this?
instead of using tableview you can use scrollview with page control.
try using this link :https://github.com/cwalcott/UIScrollView-Paging/tree/buttons
I have a UISegmentedControl with four segments. Some of the subviews are present in both the segments. Now on click of a segment i want all the subviews to be refreshed to their default state.
To make it more clear, if I have a button being with default title FootyApps, shared between two segments, and if I set the button title in one segment as Hello, then on click 0f second segment I want the button to display FootyApps and not "Hello".
Is this possible?
You have to set it back manually. There is no "initial" state saved for your views. No way to go back automatically.