Search code examples
xamarinxamarin.formsxamarin.androidxamarin.ios

Tabs slightly move up in Xamarion Forms IOS while scrolling


I am having an issue with the Tabs while scrolling down the contentpages inside Tabs. I have TabbedPage with three ContentPages. When scrolling in the ContentPages, the tabs move a little bit up in the IOS Platform while it appears ok in Android. All the ContentPages react the same. This is my first ContentPage, but the rest has normal Grid/TableView without scroll.

<FlexLayout Direction="Column">
            <FlexLayout FlexLayout.Grow="1">
                <ScrollView>
                <Grid Padding="5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                        <StackLayout Orientation="Vertical" Grid.Row="0">
                            <StackLayout x:Name="listView" Padding="0,10,0,10"
                             BindableLayout.ItemsSource="{Binding TopPages}"
                             BindableLayout.ItemTemplate="{StaticResource PageListItemTemplate}">
                        </StackLayout>
                    </StackLayout>
                    <StackLayout Orientation="Vertical" Grid.Row="1" HeightRequest="350">
                        <StackLayout HorizontalOptions="FillAndExpand" Orientation="Horizontal">
                            <Label Text="Reciters" HorizontalOptions="StartAndExpand" Style="{StaticResource DesLabel}"/>
                            <Label Text="Show All" FontSize="Medium" 
                                    TextColor="{DynamicResource PrimaryTextColor}" HorizontalOptions="End">
                                <Label.GestureRecognizers>
                                    <TapGestureRecognizer Command="{Binding RecitersListCommand}" CommandParameter="{StaticResource TypeOne}"/>
                                </Label.GestureRecognizers>
                            </Label>
                        </StackLayout>
                        <Frame Style="{StaticResource DefaultFrame}" Padding="5">
                            <CollectionView x:Name="reciterItemView" ItemsSource="{Binding Reciters}"
                                SelectionMode="Single" ItemTemplate="{StaticResource ItemTemplate}">
                                    <CollectionView.ItemsLayout>
                                        <GridItemsLayout Orientation="Horizontal" VerticalItemSpacing="5" 
                                                 HorizontalItemSpacing="5" Span="2" />
                                    </CollectionView.ItemsLayout>
                                </CollectionView>
                        </Frame>
                    </StackLayout>
                    <StackLayout Orientation="Vertical" Grid.Row="2" HeightRequest="350">
                        <StackLayout HorizontalOptions="FillAndExpand" Orientation="Horizontal">
                            <Label Text="Translations" HorizontalOptions="StartAndExpand" Style="{StaticResource DesLabel}"/>
                            <Label Text="Show All" FontSize="Medium" TextColor="{DynamicResource PrimaryTextColor}" HorizontalOptions="End">
                                    <Label.GestureRecognizers>
                                        <TapGestureRecognizer Command="{Binding RecitersListCommand}" CommandParameter="{StaticResource TypeTwo}"/>
                                </Label.GestureRecognizers>
                            </Label>
                        </StackLayout>
                        <Frame Style="{StaticResource DefaultFrame}">
                            <CollectionView x:Name="translationItemView" ItemsSource="{Binding RecitersWithTranslation}"
                                SelectionMode="Single" ItemTemplate="{StaticResource ItemTemplate}" >
                                    <CollectionView.ItemsLayout>
                                        <GridItemsLayout Orientation="Horizontal"  Span="2" />
                                    </CollectionView.ItemsLayout>
                                </CollectionView>
                        </Frame>
                    </StackLayout>
                </Grid>
                </ScrollView>
            </FlexLayout>
            <StackLayout VerticalOptions="Center" HorizontalOptions="FillAndExpand" 
                             BackgroundColor ="{AppThemeBinding Light={StaticResource LightPageBackgroundSecondaryColor},
                                    Dark={StaticResource DarkPageBackgroundSecondaryColor}}">
                <StackLayout.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding NavigateToPlayerPageCommand}"/>
                </StackLayout.GestureRecognizers>
            </StackLayout>
        </FlexLayout>

Dark Space in the tabbed area appears while scrolling down

Resources in the Page

<DataTemplate x:Key="PageListItemTemplate">
            <StackLayout Orientation="Vertical">
                <StackLayout Orientation="Horizontal" HorizontalOptions="StartAndExpand">
                    <Label Style="{StaticResource DesLabel}" HorizontalOptions="Start" VerticalOptions="Center" Text="{Binding Title}"/>
                </StackLayout>
                <BoxView Style="{StaticResource HorizentalLine}"></BoxView>
                <StackLayout.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding BindingContext.TopPageCommand, Source={x:Reference listView}}" CommandParameter="{Binding .}"/>
                </StackLayout.GestureRecognizers>
            </StackLayout>
        </DataTemplate>
        <DataTemplate x:Key="ItemTemplate">
            <StackLayout Orientation="Vertical" HorizontalOptions="Center" Padding="0,5,0,0">
                <FFImage:CachedImage HeightRequest="100" WidthRequest="100" Source="{Binding ImagePath}" Style="{StaticResource FFImageDefaultStyleWithoutBinding}">
                    <FFImage:CachedImage.Transformations>
                        <FFimageTransformation:CircleTransformation></FFimageTransformation:CircleTransformation>
                    </FFImage:CachedImage.Transformations>
                </FFImage:CachedImage>
                <Label Text="{Binding Name}" FontSize="Small" WidthRequest="150" HorizontalTextAlignment="Center" LineBreakMode="WordWrap" />
                <StackLayout.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding BindingContext.OpenReciterChapterCommand, 
                                                    Source={x:Reference reciterItemView}}" CommandParameter="{Binding .}">
                    </TapGestureRecognizer>
                </StackLayout.GestureRecognizers>
            </StackLayout>
        </DataTemplate>

Solution

  • After Looking into every piece of my code finally I found the problem. In fact the problem is not with the design or XAML. It is with the below statement I used in App.cs.

    public App()
    {
         InitializeComponent();
    
         var navigationPage = new Xamarin.Forms.NavigationPage(new MainPage());
         navigationPage.On<iOS>().SetPrefersLargeTitles(true); // This line caused the problem.
         MainPage = navigationPage;
    }
    

    Removing that line solved the problem.