Change content in iOSScrollableArea between two ContainerControls

Is this possible and not too difficult? I have one view with an iOSScrollableArea and have chosen the content of one contain, call it Container1. I’d like to tap a button on Container1 and display Container2, still within View1

I got this to work as hoped with using https://documentation.xojo.com/api/deprecated/iosapplication.html#iosapplication-currentscreen

Basically just changing the main view with another and making that the new main view

Not really sure this is the most optimal way of doing, so if anyone has any better thoughts, I’d love to hear

Depending on the workflow of your app that might be a solution.

Other solution is to add Container1 programmatically to the iOSScrollableArea and keep a reference to it.
Using that reference set Container1 to visible = false.

Then set the iOSScrollableArea.Content to container2.

This method in a module helps setting the layout constraints:

[code]Public Sub SetContentFullScreen(extends scroll as iosScrollableArea, content As iOSControl, FullScreen As Boolean = False)

scroll.Content = content

//Center the cc
Dim cons As iOSLayoutConstraint
cons = New iOSLayoutConstraint(content, _
iOSLayoutConstraint.AttributeTypes.CenterX, _
iOSLayoutConstraint.RelationTypes.Equal, _
scroll, _
iOSLayoutConstraint.AttributeTypes.CenterX, _
1.0, 0)
cons.Active = True
scroll.AddConstraint(cons)

'Dim bounds As xojo.Core.Rect = scroll.bounds
'Dim frame As xojo.Core.Rect = content.Frame

If FullScreen Then
cons = New iOSLayoutConstraint(content, _
iOSLayoutConstraint.AttributeTypes.Width, _
iOSLayoutConstraint.RelationTypes.Equal, _
scroll, _
iOSLayoutConstraint.AttributeTypes.Width, _
1.0, 0)
cons.Active = True
scroll.AddConstraint(cons)

cons = New iOSLayoutConstraint(content, _
iOSLayoutConstraint.AttributeTypes.Height, _
iOSLayoutConstraint.RelationTypes.GreaterThanOrEqual, _
scroll, _
iOSLayoutConstraint.AttributeTypes.Height, _
1.0, 0)
cons.Active = True
scroll.AddConstraint(cons)

End if

End Sub
[/code]

Use it like this:

iOSScrollableArea.SetContentFullScreen(theContainer, True)

Thank you as always Jeremie. Allow me to go deeper into what I am working on, and please chime in as to if the app.currentscreen is fine or should be totally out of the question.

I’m making a small game, which essentially will need just 2 screens. One, the user will answer some questions and earn spins. After they answer the questions, there will be a button to take them to the game board to use the spins. When done with the spins, they would click a button to go back and answer more questions. I wanted to control all the movement through button taps and did not want to use the PushTo since the previous screen can still be swiped right

I guess I may not really have had an actual need to use ContainerControl + ScrollableArea. Initially, I was thinking to be able to use these the same way we use PagePanel on desktop, where you have one screen and are just changing the main view of the panel. Using two views (not with CC and SA) with the app.currentscreen does the trick nicely. I’m just not sure what this might be doing in the background with continually destroying the previous view and replacing with a new one

I also have a similar game with only two views.
1st is the setup
2nd is the actual game.

I still use PushTo but I hide the Back button (which also prevents swiping right) with this:

[code]Public Sub SetHidesBackButtonXC(Extends v As iOSView, value As Boolean)

Declare Function navigationBar Lib “UIKit.framework” selector “navigationBar” (obj_ref As ptr) As ptr

Declare Function navigationController Lib “UIKit.framework” selector “navigationController” (viewController As ptr) As ptr
'Dim navigationControllerRef As ptr = navigationController(v.ViewControllerHandle)

'Dim navBar As ptr = navigationBar(navigationControllerRef)

Declare Function navigationItem Lib “UIKit.framework” selector “navigationItem” (obj_ref As ptr) As ptr
Dim navItem As ptr = navigationItem(v.Handle)

Declare Sub hidesBackButton Lib “UIKit.framework” selector “setHidesBackButton:” (obj_id As ptr, value As Boolean)
hidesBackButton(navItem, value)

End Sub
[/code]

Call like this:

iOSView.SetHidesBackButtonXC(True)

Your approach isn’t bad but isn’t natural in terms of user experience. Using PushTo will animate the view change and the user understands that’s the way to go forward in the workflow.
Anyway I think you should do what’s best for your users and easiest for you.

If your two views have heavy initialization functions it is better to keep them “alive”. If not, it’s up to you.

These can sometimes be exclusive. Lean toward what’s best for the users if it comes down to it.

I appreciate the comments. Thank you both. Jeremie, thank you for your insight with the PushTo animation as something users might expect. I will consider this. Still in the first stages of the app (only day 2 :slight_smile: )