1

Description

AbsoluteLayout child layout bounds not updated properly after translate y position when adding the child view content as ScrollView in Xamarin.Forms iOS.

Code

[XAML]

    <AbsoluteLayout AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="SizeProportional"
                    HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="LightBlue">
    <local:CustomView x:Name="viewcustom" AbsoluteLayout.LayoutFlags="SizeProportional" 
                    AbsoluteLayout.LayoutBounds="0,0,1,1" BackgroundColor="LightGray">
            <ScrollView x:Name="scrollView" >
            <StackLayout BackgroundColor="Red">
                <Button Margin="10" Text="Button 1" />
                <Button Margin="10" Text="Button 2" />
                <Button Margin="10" Text="Button 3"/>
                <Button Margin="10" Text="Button 4"/>
                <Button Margin="10" Text="Button 5"/>
                <Button Margin="10" Text="Button 6"/>
                <Button Margin="10" Text="Button 7"/>
                <Button Margin="10" Text="Button 8"/>
                <Button Margin="10" Text="Button 9"/>
                <Button Margin="10" Text="Button 10"/>
                <Button Margin="10" Text="Button 11"/>
                <Button Margin="10" Text="Button 12"/>
                <Button Margin="10" Text="Button 13"/>
                <Button Margin="10" Text="Button 14"/>
                <Button Margin="10" Text="Button 15"/>
            </StackLayout>
        </ScrollView>
 </local:CustomView>
    </AbsoluteLayout>

[CustomViewRenderer.cs]

    private void OnPanning()
    {
        var currentY = this.panGesture.TranslationInView(this).Y;
        Double screenHeigth = DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density;

        switch (this.panGesture.State)
        {
            case UIGestureRecognizerState.Changed:
                DependencyService.Get<IAnimate>().TranslateYTo(this.view, this.prevTranslatedY, currentY, 300);
                UpdateHeight(currentY, 0);
                break;

            case UIGestureRecognizerState.Ended:
                ...
                DependencyService.Get<IAnimate>().TranslateYTo(this.view, this.prevTranslatedY, currentY, 300);
                UpdateHeight(currentY, 0);
                ...
                break;
        }
    }
    private void UpdateHeight(double y, double viewY) //&& this.backdrop.IsBackLayerRevealed && !isPanningEnabled
    {
        Double screenHeigth = DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density;
        var heightPercentage = (screenHeigth - y) / screenHeigth;
        Xamarin.Forms.AbsoluteLayout.SetLayoutBounds(view, new Xamarin.Forms.Rectangle(0, viewY, 1, heightPercentage));
    }

Steps to reproduce

  1. Select the button1 then drag in downward direction.
  2. And select the same button and drag in upward direction.

Expected Behavior

The view drag with the mouse point

Actual Behavior

The view not drag with the mouse point due to bounds not updated properly.

Basic Information

VS 2019 Tested device: iPhone simulator XF version: 4.8

Output Video

OutputVideo.zip

Sample Link

AbsoluteLayoutContentScrollDemo.zip

0 Answers0