dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.03k stars 1.73k forks source link

Horizontal layout position not updated correctly while dynamically updated in windows platform #6946

Open Sasikumar3595 opened 2 years ago

Sasikumar3595 commented 2 years ago

Description

We are creating an application with a custom layout and pan gesture. Pan gesture is used to update the layout position based on pan position. but the layout is not updated while updated with the latest position.

Replication sample code:


public partial class MainPage : ContentPage
{
    public MainPage()
    {
 InitializeComponent();
DemoGrid demoGrid = new DemoGrid();
        this.Content = demoGrid;
    }
}

public class DemoGrid : Layout
{

    public DemoGrid()
    {
        this.BackgroundColor = Colors.Red;
        for (int i = 0; i < 3; i++)
        {
            Grid grid = new Grid();
            grid.Margin = new Thickness(5);
            grid.Background = Colors.Blue;
            this.Add(grid);
        }

        PanGestureRecognizer panGesture = new PanGestureRecognizer();
        panGesture.PanUpdated += PanGesture_PanUpdated;
        this.GestureRecognizers.Add(panGesture);
    }

    double position = 0;
    Point? touchPoint = null;
    private void PanGesture_PanUpdated(object sender, PanUpdatedEventArgs e)
    {
        System.Diagnostics.Debug.WriteLine("Status: " + e.StatusType);
        if (e.StatusType == GestureStatus.Started)
        {
            this.touchPoint = new Point(e.TotalX, e.TotalY);
        }
        else if (e.StatusType == GestureStatus.Running)
        {

            if (this.touchPoint == null)
            {
                this.touchPoint = new Point(e.TotalX, e.TotalY);
            }

            this.position = e.TotalX - this.touchPoint.Value.X;
            this.ArrangeChildren(new Rect(0, 0, this.Width, this.Height));
        }
        else if (e.StatusType == GestureStatus.Completed || e.StatusType == GestureStatus.Canceled)
        {
            this.position = 0;
            this.ArrangeChildren(new Rect(0, 0, this.Width, this.Height));
        }
    }

    public Size ArrangeChildren(Rect bounds)
    {
        double xPosition = position;
        double yPosition = 0;
        double childWidth = bounds.Width;
        double childHeight = bounds.Height / 3;
        foreach (var child in this.Children)
        {
            child.Arrange(new Rect(xPosition, yPosition, childWidth, childHeight));
            yPosition += childHeight;
        }

        return bounds.Size;
    }

    public Size Measure(double widthConstraint, double heightConstraint)
    {
        double width = widthConstraint;
        double height = heightConstraint;
        double childWidth = width;
        double childHeight = height / 3;
        foreach (var child in this.Children)
        {
            child.Measure(childWidth, childHeight);
        }

        return new Size(childWidth, childHeight);
    }

    protected override ILayoutManager CreateLayoutManager()
    {
        return new DemoGridManager(this);
    }
}

class DemoGridManager : LayoutManager
{
    DemoGrid gridView;
    public DemoGridManager(DemoGrid grid) : base(grid)
    {
        this.gridView = grid;
    }

    public override Size ArrangeChildren(Rect bounds)
    {
        return gridView.ArrangeChildren(bounds);
    }

    public override Size Measure(double widthConstraint, double heightConstraint)
    {
        return gridView.Measure(widthConstraint, heightConstraint);

    }
}

Steps to Reproduce

  1. Run the sample with below-attached code
  2. Swipe the layout but the layout was not updated with the latest pan position

Version with bug

Release Candidate 2 (current)

Last version that worked well

Preview 14

Affected platforms

Windows

Affected platform versions

Windows SDK 10.0.19041

Did you find any workaround?

No

Relevant log output

Not Applicable
XamlTest commented 2 years ago

Verified this issue with Visual Studio Enterprise 17.3.0 Preview 1.0 [32427.455.main]. Repro on Windows. Sample Project: 6946.zip

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

XamlTest commented 1 year ago

Verified this on Visual Studio Enterprise 17.6.0 Preview 5.0. Repro on Windows 11 with below Project: 6946.zip

Layout