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.88k forks source link

[Bug] ScrollView on iOS does not layout correctly when NavigationBar is hidden. #13744

Open modplug opened 3 years ago

modplug commented 3 years ago

Description

ScrollView on iOS does not layout correctly when NavigationBar is hidden.

Steps to Reproduce

  1. Run the repo project linked
  2. Observe the difference in behavior on Android vs iOS

Expected Behavior

The scrollview should fill the entire page and not be vertically scrollable.

Actual Behavior

When the navigation bar is hidden it leaves empty space at the top which is not getting consumed by the scrollview.

Basic Information

Screenshots

iOS: https://user-images.githubusercontent.com/789588/107773492-038e7600-6d3e-11eb-8bab-b2dff56dd7c6.mov

Android: https://user-images.githubusercontent.com/789588/107773520-0e490b00-6d3e-11eb-8b3f-e38f402a2994.mov

Reproduction Link

https://github.com/modplug/InconsistentScrollViewBehavior

Workaround

I have not been able to find a workaround. Please help 🏋️‍♂️

Huaba93 commented 3 years ago

As workaround you could create a CustomRenderer

[assembly: ExportRenderer (typeof(ScrollView), typeof(CustomScrollViewRenderer))]
namespace InconsistentScrollView.iOS
{
    public class CustomScrollViewRenderer : ScrollViewRenderer
    {
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);
            if (e.OldElement != null) {
                // Unsubscribe from event handlers and cleanup any resources
            }
            if (e.NewElement != null) {
                // Configure the native control and subscribe to event handlers
                ContentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.Never;
            }
        }
    }
}

when iOsSpecific:Page.UseSafeArea="false" is set on the PageLevel, a ScrollView should have a different ContentInsetAdjustmentBehavior.

I guess similar issues exists for CollectionView and ListView

albi005 commented 2 years ago

Doesn't seem to happen with a CollectionView, so using a CollectionView's Header instead of the ScrollView worked for me. EDIT: This doesn't work on android because of #12065