xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.87k forks source link

[Bug] [iOS] Unable to programmatically scroll elements into view if they're behind an open picker view and at the bottom of the page. #15666

Open joshea2345 opened 1 year ago

joshea2345 commented 1 year ago

Description

Unable to programmatically scroll elements into view (using .ScrollToAsync()) if they're behind an open picker view AND they're towards the bottom of the page. However, scrolling them into view is possible to do manually with touch gestures.

Steps to Reproduce

  1. Create a scrollview. In the scrollview, add a picker & an element at the very bottom of the page.
  2. For picker's SelectedIndexChanged, try to scroll the bottom element into view.
  3. Open picker & change selected item.

Expected Behavior

Page should scroll the bottom element into view above the open picker view.

Actual Behavior

Element stays at the bottom of the page behind the picker view.

Basic Information

Screen-records

Programatic scrolling not working on changing the picker selection https://user-images.githubusercontent.com/40665312/213464980-8f71ba8d-70ef-4660-b668-49a51050ef83.mp4

Manual scrolling working by touching the screen https://user-images.githubusercontent.com/40665312/213464743-01051b95-933e-4ac8-9a37-7c1b9c66c59a.mp4

Code to recreate

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
             ios:Page.UseSafeArea="true"
             x:Class="MyApp.HomePage">

    <ContentPage.Content>
        <ScrollView x:Name="mainScrollView" VerticalOptions="FillAndExpand">
            <StackLayout Padding="30" VerticalOptions="FillAndExpand">

                <!-- Picker -->
                <Picker ItemsSource="{Binding TestList}" ItemDisplayBinding="{Binding Name}" Title="Picker" HorizontalTextAlignment="Start"
                        SelectedIndexChanged="Picker_SelectedIndexChanged"/>

                <!-- Picker -->
                <Label x:Name="showMe_Button" Text="SHOW ME" HorizontalOptions="CenterAndExpand" VerticalOptions="EndAndExpand" TextColor="Red"/>

            </StackLayout>
        </ScrollView>
    </ContentPage.Content>
</ContentPage>
using System;
using Xamarin.Forms;

namespace MyApp
{
    public partial class HomePage : ContentPage
    {
        public HomePage()
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this, false);
        }

        async void Picker_SelectedIndexChanged(System.Object sender, System.EventArgs e)
        {
            await mainScrollView.ScrollToAsync(showMe_Button, ScrollToPosition.End, true);
        }
    }
}
using System;
using System.Collections.ObjectModel;

namespace MyApp
{
    public class TestItem
    {
        public string Name { get; set; }

        public TestItem()
        {
        }
    }

    public class HomePageModel : FreshMvvm.FreshBasePageModel
    {
        public ObservableCollection<TestItem> TestList { get; set; }

        public HomePageModel()
        {
            TestList = new()
            {
                new() { Name = "Item 1" },
                new() { Name = "Item 2" },
                new() { Name = "Item 3" },
            };
        }
    }
}