The main page should contain at least four containers. Two containers will be dedicated to holding full-screen views, where one of them will be dedicated to hidden and other, to visible views. The same goes for the other two containers, except that they are in charge of overlays (popups, slide-ins, and others).
Overlays container should have precedence overviews container. Even though views themselves are pretty much empty shells, with a bunch of boxes, when they are not populated with data, if rendered, they will still take significant amounts of RAM and can clog UI thread.
However having them not rendered, makes a whole world of difference on that end, while still allowing the developer to reference it and its bits. In XAML, property responsible for disabling rendering of elements is “Visibility” and is completely different from property “Opacity”, in a sense that opacity is only affecting alpha visibility of elements, still rendering it and occupying resources. Any framework should have equivalents for those two.
Here we can take one of two turns. The first one and a bit easier are to add views and overlays to their respective ‘non-rendered’ containers. This ensures that all visual components get initialized. It’s a bit costly on startup, as in many cases users will not go through every view and popup.
In this case, data binding will not happen inside the UI element constructor, so only elements that are going to be created will pretty much be empty boxes, no lists or carousels.
The second path is to load elements on demand. It means that once the view is requested a separate method on the main page, will need to check for element existence and instantiate it, if necessary.
Flickers on initial screen renderings are possible with this method (usually only on low-end devices). I prefer the first method, even though it requires views and overlays, to implement hooks that can be called, in order to get data.
Once we have decided which view should be displayed, we move it from a ‘non-rendered’ container to a ‘rendered’ one. ‘’Big deal’’ in this process are two delegate methods, “ToggleView” and “ToggleOverlay”.
The difference between these two is in the behavior they produce. ToggleView is conceived to manipulate UI elements that should completely overtake viewport, so once it is executed, any view or overlay still in the ‘rendered’ container, will be moved to their ‘non-rendered’ counterparts.
ToggleOverlay is different in a way that manipulates the existence of elements, in only overlay containers. These delegate methods can be made in a way that they accept a range of arguments.
There are two usual arguments and they are: state – it is ‘’boolean value’’, telling delegate whether the targeted element should be hidden or shown; and the other is uiEelement - a string that has value like “profileView”, which tells delegate what should be targeted (can be mapped, however, not necessarily the string).
Other arguments that can be included are ‘animated’, ‘duration’, ‘lifespan’, and similar, which will later affect the way new elements get presented on screen. After the view has been moved to the rendered container, if not done in the constructor, then UI elements should subscribe to the same delegate as the main page and detect their time and load necessary data.
Every view can contain subviews that are not part of the main view alternating routine. They can have direct access to singleton data, just like their parent. Every delegate invocation should be followed by making a record in the history log, so we can navigate back if needed.