Skip to content

fix(commandbar): Fix rendering issues with commandbar - #13214

Closed
ramezgerges wants to merge 6 commits into
unoplatform:masterfrom
ramezgerges:commandbar_arrange
Closed

ramezgerges wants to merge 6 commits into
unoplatform:masterfrom
ramezgerges:commandbar_arrange

Conversation

@ramezgerges

@ramezgerges ramezgerges commented Aug 11, 2023 •

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): closes #13213

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

What is the new behavior?

Copilot Summary

🤖 Generated by Copilot at 275d34b

This pull request improves the layout and positioning of the CommandBar and Popup controls. It fixes a bug in the CommandBar overflow popup and adds a feature to the Popup custom layouter.

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

Internal Issue (If applicable):

@ramezgerges
ramezgerges marked this pull request as draft August 15, 2023 19:30
@ramezgerges

Copy link
Copy Markdown
Contributor Author

There seems to be a new problem with the CommandBar expanding down. The LayoutRoot Grid is not collapsing after it's opened.

There's an animation in the template that updates the Clip.Transform.Y of the LayoutRoot but that animation is never triggered. The problem is that there's a condition at

|| (boundProperty.DataContext is Transform transform && transform.View != null)

that doesn't trigger the animation if the View is null, which is the case here since the Transform is affecting a Clip area, and not a view. It's not very clear atm why the condition is present.

@dr1rrb

dr1rrb commented Aug 16, 2023 •

Copy link
Copy Markdown
Member

It's not very clear atm why the condition is present.

Because when animation was implemented few years ago, they assumed that an animation and transforms was tightly link to a view (and a single view) ... which is wrong (both can be re-used to animate/transform multiple dependency objects).

But here the only effect is that the animation is considered as "dependent" (understand "will invalidate the layout") ... which is indeed probably the case on uno, but not on windows (cf. https://learn.microsoft.com/en-us/windows/uwp/debug-test-perf/optimize-animations-and-media#use-independent-instead-of-dependent-animations). We should just match the windows behavior and allow animations on the Clip property even if not flagged with the AllowDependentAnimations.

(Note: As a test to validate that it's the only issue, you can change the template to set the AllowDependentAnimations flag to true)

Create Universal Windows Platform (UWP) apps with smooth animations, high frame rate, and high-performance media capture and playback.

… measured by the parent during the layout cycle
@ramezgerges

ramezgerges commented Aug 22, 2023 •

Copy link
Copy Markdown
Contributor Author

@carldebilly @dr1rrb

The previous fix had the problem of measuring elements multiple times. The new fix keeps state of which element(s) are currently being measured as part of the layout cycle and which are just getting measure due to any random call. Measure calls now only invalidate flags if they happen during a Parent's Measure call and that parent itself recursively satisfies this same condition. There are almost definitely some edge cases (although nothing that I can immediately think of), but I guess this should make sense for the overwhelming majority of cases.

Some tests like When_InvalidatingMeasureExplicitly and When_InvalidatingMeasureAndArrangeByChangingSizeTwice explicitly test that flags are cleared on any Measure() call (not just as a part of layout cycle), so these will be changed once the changes get positively reviewed

Comment on lines +256 to +268
var disposables = new List<IDisposable>();
// This checks makes sure that this is part of the layout cycle,
// and not just a random call to a parent's Measure()
if (partOfLayoutCycle)
{
foreach (var child in GetChildren())
{
child.CurrentlyBeingMeasuredByParentInLayoutCycle = true;
disposables.Add(Disposable.Create(() => child.CurrentlyBeingMeasuredByParentInLayoutCycle = false));
}
}
MeasureCore(availableSize);
disposables.ForEach(d => d.Dispose());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var disposables = new List<IDisposable>();
// This checks makes sure that this is part of the layout cycle,
// and not just a random call to a parent's Measure()
if (partOfLayoutCycle)
{
foreach (var child in GetChildren())
{
child.CurrentlyBeingMeasuredByParentInLayoutCycle = true;
disposables.Add(Disposable.Create(() => child.CurrentlyBeingMeasuredByParentInLayoutCycle = false));
}
}
MeasureCore(availableSize);
disposables.ForEach(d => d.Dispose());
UIElement[] children = null;
// This checks makes sure that this is part of the layout cycle,
// and not just a random call to a parent's Measure()
if (partOfLayoutCycle)
{
children = GetChildren().ToArray();
foreach (var child in children)
{
child.CurrentlyBeingMeasuredByParentInLayoutCycle = true;
}
}
MeasureCore(availableSize);
if (partOfLayoutCycle)
{
foreach (var child in children)
{
child.CurrentlyBeingMeasuredByParentInLayoutCycle = false;
}
}

@dr1rrb dr1rrb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +256 to +261
var disposables = new List<IDisposable>();
// This checks makes sure that this is part of the layout cycle,
// and not just a random call to a parent's Measure()
if (partOfLayoutCycle)
{
foreach (var child in GetChildren())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really worried about the perf impact of this: Creating a new list on each measure, adding an enumeration of the Children collection and finally enumerating the newly created collection ... I would rather check in the child.Measure if the direct parent is CurrentlyBeingMeasuredByParentInLayoutCycle.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll also need to add runtime or unit tests to validate that specific behavior on simple controls, as this could regress easily :)

@carldebilly
carldebilly self-requested a review August 23, 2023 13:00

@Youssef1313 Youssef1313 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the measure changes are the correct changes.

I investigated this, and to me it's looking like an animations issue.

Doing the following change will make the CommanrBar expand properly

image

We need to discuss this more.

Comment on lines +74 to +75
// Uno specific
private readonly SerialDisposable m_contentRootRenderTransformChangedEventHandler = new SerialDisposable();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, these changes that are related to invalidating popup panel arrange can go into a separate PR. Also, I'd prefer us to open an issue to track removing this Uno-specific code

@ramezgerges

Copy link
Copy Markdown
Contributor Author

I don't think the measure changes are the correct changes.

I investigated this, and to me it's looking like an animations issue.

Doing the following change will make the CommanrBar expand properly

image

We need to discuss this more.

No, that's completely unrelated. The measure changes are needed because the first time the popup is opened, it opens with an incorrect width. The clipping issue is not related and I don't think changing the template instead of fixing the root cause is a good idea.

@Youssef1313

Copy link
Copy Markdown
Member

the first time the popup is opened, it opens with an incorrect width.

I can't reproduce this.


The clipping issue is not related and I don't think changing the template instead of fixing the root cause is a good idea.

Per my findings, the clipping issue appears to be an animations bug. Changing the template is definitely not the correct fix, but it can serve as a temporary workaround if we couldn't fix the animations issue.

@Youssef1313

Copy link
Copy Markdown
Member

PR #15620 combined with #15619 should fix the issue.

@ramezgerges
ramezgerges deleted the commandbar_arrange branch March 3, 2024 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CommandBar Popup renders incorrectly on initial load, and has wrong vertical offset on all loads

5 participants