Why does my page content start off the screen then adjust down? - ios

I experience this issue only my Xamarin iOS project. The Android version works correctly.
I have a standard ContentPage that is pushed via PushAsync. When the page loads, the content loads off the screen then (it seems) after binding is finished moves down the page. I have attached a screen where it shows loading off the screen and one where it re-adjusts.
Content off the screen
After binding
XAML File
<ContentPage.Content>
<AbsoluteLayout>
<Frame Padding="10"
Margin="20, 20, 20, 20"
BackgroundColor="AliceBlue"
AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
AbsoluteLayout.LayoutFlags="SizeProportional">
<StackLayout Margin="10">
<Label Text="{Binding OutreachTitle}"
FontSize="Title"
TextColor="{StaticResource PrimaryTextColor}"
HorizontalOptions="Center" />
<controls:HorizontalRuleControl RuleColor="{StaticResource SecondaryColor}" />
<Label Text="{Binding OutreachText}"
Margin="0, 10, 0, 0"
TextColor="{StaticResource PrimaryTextColor}"
VerticalOptions="End"/>
</StackLayout>
</Frame>
</AbsoluteLayout>
</ContentPage.Content>

I did not reproduced the problem on my side. While I would recommend you to use StackLayout instead of AbsoluteLayout.
The problem is probably caused by resize of View in ContentPage, when you set SizeProportional of AbsoluteLayout, the size will following the changing of the View and that would cause the content loads off the screen:
<StackLayout>
<Frame Padding="10"
Margin="20, 20, 20, 20"
BackgroundColor="AliceBlue"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<StackLayout Margin="10">
<Label Text="{Binding OutreachTitle}"
FontSize="Title"
TextColor="Yellow"
HorizontalOptions="Center" />
<Label Text="{Binding OutreachText}"
Margin="0, 10, 0, 0"
TextColor="Green"
VerticalOptions="End"/>
</StackLayout>
</Frame>
</StackLayout>

Related

Xamarin.Forms: CarouselView not works as expected on iOS

I'm trying to implement CarouselView control with horizontal scroll.
I'm using Xamarin.Forms 5.0.0.2012.
This is the xaml code:
<CarouselView x:Name="carViewArticoliAlt"
Loop="False"
ItemsSource="{Binding ListaProdottiAlt}"
IndicatorView="indicatorView"
IsVisible="{Binding ArticoliAlt}"
HeightRequest="200"
PeekAreaInsets="100">
<CarouselView.ItemsLayout>
<LinearItemsLayout Orientation="Horizontal"
SnapPointsAlignment="Start"
SnapPointsType="Mandatory"
ItemSpacing="20" />
</CarouselView.ItemsLayout>
<CarouselView.ItemTemplate>
<DataTemplate>
<Frame HasShadow="True" BorderColor="LightGray"
CornerRadius="5" Padding="5"
HeightRequest="310"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" >
<Frame.GestureRecognizers>
<TapGestureRecognizer
Tapped="TapGestureRecognizer_Tapped"/>
</Frame.GestureRecognizers>
<Grid>
<StackLayout x:Name="stkArticoloAlt">
<ImageButton x:Name="ImageArt"
Source="{Binding ImageArt}"
Aspect="AspectFit"
HeightRequest="80"
Clicked="ImageArt_Clicked"
BackgroundColor="White"/>
<Label Text="{Binding Descrizione}"
Style="{StaticResource labelDescrizioneStyle}"
MaxLines="3" LineBreakMode="TailTruncation"
HeightRequest="55"
FontSize="15"/>
</StackLayout>
</StackLayout>
</Grid>
</Frame>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
<IndicatorView x:Name="indicatorView"
IndicatorColor="LightGray"
SelectedIndicatorColor="DarkGray"
HorizontalOptions="Center" />
On Android platform the control is well rendered, but on iOS the following exception is thrown: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: negative sizes are not supported in the flow layout.
I followed this tutorial:
https://learn.microsoft.com/it-it/xamarin/xamarin-forms/user-interface/carouselview/scrolling
I noticed that the cause of the exception is the PeekAreaInsets property. Infact, if I don't handle this property, the exception does not occur. However the control is not drawn correctly, since the tabs are overlapping. Android code keeps on running correctly.
As you can see in the image, the cards are all overlapped, even if LinearItemsLayout.Orientation is set to horizontal.
Name: NSInternalInconsistencyException Reason: negative sizes are not supported in the flow layout.
The error indicates that the child's size( in datatemplate) is bigger than parent layout's size.
<CarouselView x:Name="carViewArticoliAlt"
Loop="False"
ItemsSource="{Binding ListaProdottiAlt}"
IndicatorView="indicatorView"
IsVisible="{Binding ArticoliAlt}"
HeightRequest="200" --------->parent's height
PeekAreaInsets="100">
<CarouselView.ItemsLayout>
<LinearItemsLayout Orientation="Horizontal"
SnapPointsAlignment="Start"
SnapPointsType="Mandatory"
ItemSpacing="20" />
</CarouselView.ItemsLayout>
<CarouselView.ItemTemplate>
<DataTemplate>
<Frame HasShadow="True" BorderColor="LightGray"
CornerRadius="5" Padding="5"
HeightRequest="310" --------->child's height
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" >
To solve the problem try to remove HeightRequest="200" on CarouselView.
Since the Xamarin.Forms 5 release a new feature has been implemented on the CarouselView: Loop. This seems to be set to True by default and is causing some issues together with the PeakAreaInsets property. I was able to solve/work-around above crash/error by setting Loop="False". Perhaps that also works in your case?

Xamarin iOS toolbar background image

I need to put image as background in toolbar in Xamarin Forms in iOS project with master detail page and navigation bar (to have software back button in iOS). On android it works well but in iOS not good enough. I use this code in AppDelegate.cs:
UINavigationBar.Appearance.SetBackgroundImage(new UIImage("toolbar_iOS.jpg"), UIBarPosition.Any, UIBarMetrics.Default);
I put here image with pattern 400x125 pixels (less width - it displays 1 image and part of second image to the right, more pixels - image is zoomed). I want to have image displayed as aspect fill, because at page just under toolbar I have the same image with pattern and I want them exactly in the same size to match pattern.
Second way was to put an image in stack layout in Xamarin.Forms in NavigationPage.TitleView. I can modify aspect, but image is displayed only in about 70% of area of toolbar (it bypass hamburger icon and status bar), so it is not good.
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Layout.xxx.Views.MainMenuPage"
xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
xmlns:ffimageloadingsvg="clr-namespace:FFImageLoading.Svg.Forms;assembly=FFImageLoading.Svg.Forms"
xmlns:pages="clr-namespace:Layout.xxx.Views">
<MasterDetailPage.Master>
<pages:MainMenuPageMaster x:Name="MasterPage"/>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<pages:MainMenuPageDetail x:Name="DetailPage">
<NavigationPage.TitleView>
<Grid>
<ffimageloading:CachedImage Margin="-50,-30,0,0" Grid.Row="0" Source="background.jpg" Aspect="AspectFill" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" />
<StackLayout Grid.Row="0" VerticalOptions="Center" HorizontalOptions="FillAndExpand">
<StackLayout.Margin>
<OnPlatform x:TypeArguments="Thickness" iOS="-35,0,0,0" Android="-60,0,0,0"/>
</StackLayout.Margin>
<ffimageloadingsvg:SvgCachedImage Margin="0" Source="logo_svg.svg" Aspect="AspectFit" HeightRequest="40" VerticalOptions="Center" HorizontalOptions="Center" />
</StackLayout>
</Grid>
</NavigationPage.TitleView>
</pages:MainMenuPageDetail>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
Negative margins does not help. Is there another way to have control over toolbar image in iOS?
Use this code snippet , may help
<ContentPage>
<NavigationPage.TitleView>
<StackLayout Orientation="Horizontal" VerticalOptions="Center" Spacing="10">
<Image Source="iconXamagon.png">
<Image.GestureRecognizers>
<Image.TapGestureRecognizer
Tapped="HandleTapped" />
</Image.GestureRecognizers>
</Image>
<Label Text="3.2.0" FontSize="16" TextColor="Black" VerticalTextAlignment="Center" />
</StackLayout>
</NavigationPage.TitleView>
....
If you set HasBackButton="False" for the page it should cover the whole screen, just you will have to implement the back button or the hamburger button yourself.

Nativescript-Vue IOS Safe Area Layout Issue

I have an issue with the ios Safe Area with Nativescript-Vue on iPhone X and above. I think it has something to do with the nested frames/pages setup we have. We use a custom header and then for the 'body' of the app when we want to navigate we navigate pages within the nested frame. The custom header will enter the safe area without an issue, but the bottom safe area remains.
The nested Page component itself appears to enter the safe area, but any layout inside that page appears constrained to be outside the safe area.
Here is a playground that shows what's happening: https://play.nativescript.org/?template=play-vue&id=pXmqzC&v=3
In the playground you can see this by the borders I've drawn around the Page and the StackLayout.
Here's the layout code in case you can't access the playground sample:
<template>
<Page actionBarHidden="true">
<GridLayout rows="90, *">
<StackLayout row="1" height="100%">
<Frame>
<Page actionBarHidden="true" height="100%" borderWidth="5" borderColor="red" >
<StackLayout height="100%" width="100%" horizontalAlignment="center" verticalAlignment="center" backgroundColor="green" borderWidth="5">
<Label text="Body" horizontalAlignment="center" verticalAlignment="center" />
</StackLayout>
</Page>
</Frame>
</StackLayout>
<!-- Simulates a header -->
<StackLayout row="0" height="90" width="100%" horizontalAlignment="center" verticalAlignment="center" backgroundColor="blue">
<Label text="Header" horizontalAlignment="center" verticalAlignment="center" />
</StackLayout>
</GridLayout>
</Page>
</template>
An easy fix is to remove StackLayout above Frame.
<template>
<Page actionBarHidden="true">
<GridLayout rows="90, *">
<!-- <StackLayout row="1" height="100%"> -->
<Frame row="1" borderWidth="0">
<Page actionBarHidden="true" height="100%" borderWidth="5" bordercolor="red">
<StackLayout
height="100%"
width="100%"
horizontalAlignment="center"
verticalAlignment="center"
backgroundColor="green"
borderWidth="5"
>
<Label text="Body" horizontalAlignment="center" verticalAlignment="center" />
</StackLayout>
</Page>
</Frame>
<!-- </StackLayout> -->
<!-- Simulates a header -->
<StackLayout
row="0"
height="90"
width="100%"
horizontalAlignment="center"
verticalAlignment="center"
backgroundColor="blue"
>
<Label text="Header" horizontalAlignment="center" verticalAlignment="center" />
</StackLayout>
</GridLayout>
</Page>
</template>
Things to remember,
You don't really need a StackLayout above Frame, it doesn't server any purpose right there.
Avoid setting height="100%" by default content of Page / Frame takes it's whole height, you don't have to specify in percentage, at least when it's 100
When you set verticalAlignment to center, you force the layout to fit to center on it's parent, but again why to set height to 100%, that doesn't make sense.

RadioButtons and CheckBoxes not working properly on iOS and UWP

I am working on a cross platform app using Xamarin in Visual Studio 2015. I am using XLabs.Forms v2.3.0- pre 05 and I am having problems with radio buttons and checkboxes.
Right now the checkboxes work fine on UWP but they won't show on iOS.
The radio buttons, on UWP won't work at all while on iOS only the texts gets displayed
See pictures below.
This is my code for checkboxes:
<ListView x:Name="lv_ReportQuestions">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout
Orientation="Vertical"
>
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<StackLayout WidthRequest="{Binding DisplayWidth}">
<Label HorizontalOptions="FillAndExpand" Text="{Binding ItemName}" VerticalOptions="Center" LineBreakMode="WordWrap"/>
</StackLayout>
<controls:CheckBox DefaultText="" WidthRequest="40" IsEnabled="false" IsVisible="true" Checked="true" HorizontalOptions="EndAndExpand"/>
</StackLayout>
<Label HorizontalOptions="FillAndExpand" Text="{Binding SubText}" VerticalOptions="Center"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
This is my code for radio buttons:
<Label Text="Radio Buttons"/>
<Frame
HorizontalOptions="FillAndExpand"
VerticalOptions="CenterAndExpand"
OutlineColor="#000000"
>
<controls:BindableRadioGroup x:Name="ansPicker"
IsVisible="true"/>
</Frame>
ansPicker.ItemsSource = new[]
{
"Red",
"Blue",
"Green",
"Yellow",
"Orange"
};
I have tried to follow other possible fixes, but nothing worked for me.
Xamarin.Forms does not define any CheckBox control or radio button. You can use a Switch that should do what you expect. or use library such as this

Xamarin.Forms AbsoluteLayout issue on iOS

I'm new with xamarin and I'm trying to use a searchbar with a result listview (which is hidden) on top of a main listview (ie: mobile facebook friend search)
On iOS I'm not being able to tap on the main listview because the result listview is always on top of the other one even if it's not visible.
Here is the code:
<AbsoluteLayout>
<StackLayout Orientation="Vertical" Padding="0,50,0,0">
<StackLayout Padding="20,0,0,10">
<Label Text="{Binding SelectedAddressString, StringFormat='BCLs near {0}'}" />
</StackLayout>
<ListView x:Name="iOSlstBCLs" ItemsSource="{Binding BCLList}" IsPullToRefreshEnabled="true" RefreshCommand="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing, Mode=OneWay}">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Name}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
<StackLayout Orientation="Vertical" HorizontalOptions="StartAndExpand" VerticalOptions="Fill" AbsoluteLayout.LayoutFlags="WidthProportional" AbsoluteLayout.LayoutBounds="0,0,1,1">
<SearchBar Text="{Binding SearchText, Mode=TwoWay}" Placeholder="Search" AbsoluteLayout.LayoutFlags="WidthProportional" AbsoluteLayout.LayoutBounds="0,0,1,1" />
<ListView IsVisible="{Binding IsSuggestionListVisible, Mode=OneWay}" ItemsSource="{Binding SuggestionList}" SelectedItem="{Binding SelectedAddress}" VerticalOptions="Fill" AbsoluteLayout.LayoutFlags="WidthProportional" AbsoluteLayout.LayoutBounds="0,0,AutoSize,AutoSize" BackgroundColor="White">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding formatted_address}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</AbsoluteLayout>
Any ideas?
From my experience, you should never use an Absolute Layout if at all possible. It seems like it would be better to use a Stack and place both of your other stacks within that. Then set the visibility as needed. I am not positive, but I am guessing that the Absolute Layout is messing you up.

Resources