[iOS]; How to leave space for top and bottom status bar - uno-platform

I found that hiding the status bar (at least on latest iPhones) does not make much sense since the space on top is partially consumed e.g. by the camera.
Similar issue at the bottom: there is a 'swipe bar' where some space should be left for.
Hence my question: what's the correct way to leave the right amount of space for the status bar on top of the iPhone screen and the 'swipe bar' at the bottom of an iPhone screen?
Thanks in advance

Indeed, making sure that app content isn't obscured by the 'notch' or the bottom swipe area on current-generation iPhones (and some newer Android devices as well) is an important consideration.
Uno Platform handles this using the VisibleBoundsPadding behavior. You can attach this behavior to any compatible container (eg a Panel or Border) and the content of the container will be padded such that stays within the 'safe' area of the screen.
In general you should place all 'content' in your application (eg text, images, interactive elements) within the VisibleBoundsPadding area, but some visual elements eg a full-screen backdrop might go outside of it.
You can place VisibleBoundsPadding anywhere you wish in your app (including multiple locations), though generally it makes sense to place it on or near a root element. It will adjust automatically to rotations and other layout updates.
Here's a simple example:
<Page x:Class="UnoTestbed20.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UnoTestbed20"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="using:Uno.UI.Toolkit"
mc:Ignorable="d">
<Grid Background="LightBlue" toolkit:VisibleBoundsPadding.PaddingMask="All">
<Border Background="LightYellow">
<TextBlock Text="Hello, world!"
Margin="20"
FontSize="30" />
</Border>
</Grid>
</Page>
And the resulting display on an iPhone 11:

Related

Xamarin.Forms: CarouselView empty left margin

Good morning
I am using CarouselView which takes the full screen on my page. The CarouselView is set to be used only vertically:
<CarouselView.ItemsLayout>
<LinearItemsLayout Orientation="Vertical" ItemSpacing="0" SnapPointsType="MandatorySingle" SnapPointsAlignment="Start" />
</CarouselView.ItemsLayout>
On Android each item takes a full screen, however on iOS there is always a margin to the left. Even if I specify Margin="0" the empty space still exists.
I have read there about PeekAreaInsets property. I did specify it also to the zero like margin but the space still exists. I am using CarouselView only vertically and I always Snap into "MandatorySignle".
I added CarouselView.BackgroundColor="Blue" for visualise the problem.
Is is possible to remove the empty space ?

Uno-platform: Canvas not in pixel but scaled by something

Uno says it is 'Pixel Perfect Everywhere'.
So I created a canvas with width 320 and height 320 and placed some buttons inside, one in each edge.
Now when I start the app, on Android or IOS, the canvas is bigger than the screen, and the buttons on the right side don't show at all.
But my iPhone8 and my Samsung S9 have a far bigger screen resolution than just 320 by 320.
The whole canvas gets scaled by something, and even the window bounds of the main window are far smaller than my screen resolution.
My questions:
Can I turn off the scaling and use the real resolution?
Is there a property where I can get the scaling factors, so I can resize my canvas and just calculate everything to the scaled size?
Layouting values like Width and Height in Uno/WinUI Xaml are defined in 'logical pixels', as distinct from 'physical pixels'. Since devices with similar physical dimensions may have wildly different physical pixel densities, logical pixels are a better way to specify layout dimensions in most cases.
Make sure you understand Xaml's layouting system - you normally shouldn't hard-code the dimensions at all when you're stretching content to the width of the screen. For example:
<Grid HorizontalAlignment="Stretch"
Height="320">
<Button Content="Button1"
HorizontalAlignment="Left"
VerticalAlignment="Top" />
<Button Content="Button2"
HorizontalAlignment="Right"
VerticalAlignment="Top" />
...
</Grid>
All that said, in the very rare cases that you do need to work with device-dependent physical pixels, you can use the DisplayInformation class and its properties, eg:
var displayInformation = DisplayInformation.GetForCurrentView();
var scaleFactor = displayInformation.RawPixelsPerViewPixel;
...

How to create an overflow menu (not on the toolbar) - Xamarin.Forms

I understand how to create a ToolbarItem and set it's Order equal to Secondary which will give me an overflow menu like so:
But I'm not sure how I could implement such a menu in other parts of my application. For instance in the app I'm currently working on, I've removed the toolbar and created my own meaning there is no way to set the ToolbarItems property. I can add a ImageButton for the 3 dots overflow menu icon but I cannot get it to display a menu like the out of the box implementation does.
I'd also like to use this in other parts of my app (not just on the toolbar) such as on some sort of CardView.
Has anyone dealt with this problem before?
You can use Absolute layout to achieve this:
<AbsoluteLayout>
<StackLayout RowSpacing="0" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">
<!--Main Content of the screen-->
</StackLayout>
<BoxView Color="Gray" AbsoluteLayout.LayoutBounds="1,0,250,250" AbsoluteLayout.LayoutFlags="PositionProportional" />
</AbsoluteLayout>
In the above code I have used a BoxView of Gray background for that menu toolbar to just show a demo, you can implement your view and set the width and height accordingly and make that view visible on click of icon which you will add on the toolbar.
Output:
This can be easily achieved using AbsoluteLayout in Xamarin.Forms
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/absolute-layout
https://xamgirl.com/absolutelayout-in-xamarin-made-simple/

Some Frames in Listview have sharp edges and some are round (Xamarin forms)

Some Frames in Listview have sharp edges and some are round (Xamarin forms)
I have a Xamarin forms app with a list view. The horizontal row has a couple different frames (boxes with text).
The issue is some of the frames have sharp edges and others are rounded. I can't see any pattern (size of text, etc).
I tried updating the padding but it did not have any effect on this issue.
What could cause the border/edges to be different?
How can I explicitly set them?
I am testing in the Android Simulator at the moment if it matters.
Wrap your box views within a frame so that all the boxviews will have the rounded corners.
<Frame OutlineColor="Black" HasShadow="False" Padding="0" VerticalOptions="FillAndExpand">
<BoxView x:Name="boxViewSeparator" HeightRequest="15" WidthRequest="10000" BackgroundColor="Green" />
</Frame>
I had to move the listview around some.
I would like to explicitly set this property (borders).
Example of straight edges
Straight and round
Round in the middle

Silverlight 4 Canvas.Left binding without canvas per item

I'm getting some performance issues with this code, where mousing over the canvas area is laggy if i leave in the canvases within the data template, but no lag if I take them out (but obviously the Canvas.Left bindings don't work so the ellipses are in the wrong place!) Is there a way to position these items without each one needing its own canvas?
<Canvas>
<ItemsControl ItemsSource="{Binding Path=SpatialData.TrainEvents.ArrDepEllipseOfLines}" Name="ctrlChartTrainEventsArrDep" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<Canvas>
<Ellipse Width="{Binding EventShape.Width}" Height="{Binding EventShape.Height}" Stroke="{Binding Path=Stroke}" StrokeThickness="{Binding StrokeThickness}" Fill="{Binding Path=Fill}" Canvas.Left="{Binding CanvasPlacement.X}" Canvas.Top="{Binding CanvasPlacement.Y}" />
</Canvas>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Canvas>
Thanks very much,
Becky
Yes, you can remove the canvas in your ellipse. I think you'll find that your values for CanvasPlacement.X don't increment properly per ellipse and the effect your seeing is the fact that each element in your ItemsControl is actually placed in a StackPanel (the default behaviour and can be changed via the ItemsPanel property) which is then laying these out for you - most likely in a horizontal line.

Resources