ContentView2
RedCorners.Forms.ContentView2
is an enhanced version of ContentView
. When used inside a ContentPage2
, through a recursive chain of events, it gains extra abilities to know when it’s appearing and disappearing on the screen.
This control can also automatically adjust its top and bottom paddings based on the device’s safe insets or custom global values set by the developer. This means taking care of the notch on iPhone X series.
ContentView2
is best used when inside a ContentPage2
page and a BindableModel
context attached to it.
Properties
bool FixTopPadding, bool FixBottomPadding
When true
, ContentView2
overrides its top and/or bottom components of its Padding
property to values retrieved from NotchSystem.Instance.GetPageMargin()
.
By default, this means you can make sure your UI controls won’t overlap with the iOS notch or the task switching hot area on the bottom of the screen, if you turn on these properties.
On devices without notch, by default the padding values are set to zero.
You can always override or augment these values using the NotchSystem
singleton. For more information, read the docs for NotchSystem
.
Metadata Properties
ContentView2
provides a number of metadata properties that are meant to be used when the control is embedded inside a tabbed page, or in similar scenarios. These properties are:
string Title
ImageSource Icon
ImageSource SelectedIcon
bool IsVisibleAsTab
ICommand ShowTabCommand
For example, if you embed a ContentView2
inside a TabbedContentView
:
- The
Title
property is used as the text for the tab button; Icon
andSelectedIcon
are used as the images for the tab button, depending on whether the tab is active or not. (Note:SelectedIcon
is optional.)IsVisibleAsTab
indicates whether thisContentView2
has a button on the tab bar, or is a hidden page that can only be navigated to programmatically.
Methods
OnStart
and OnStop
When ContentView2
controls are embedded inside a ContentPage2
, the page recursively finds all instances of ContentView2
objects and calls their OnStart
and OnStop
methods when:
- They exist in the page and the page appears (
OnStart
); - They are added to a page that is already visible (
OnStart
); - Their
Parent
is set tonull
(OnStop
); - They exist in the page and the page disappears (
OnStop
).
Overriding these methods can be useful when you want to detect when the control is shown or hidden:
public override void OnStart()
{
Console.WriteLine("Hello!");
}
public override void OnStop()
{
Console.WriteLine("Goodbye!");
}
ContentPage2 GetPage()
The GetPage()
method recursively seeks and returns the ContentPage2
that holds the ContentView2
control. If no ContentPage2
is found, null
is returned.
bool GetIsVisibleRecursive()
This method recursively checks and returns true
if the control and all its parent View
s are visible (i.e. IsVisible
is true
).