-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Handlers] Make sure to update Content on handlers when the ControlTemplate changes #7235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5001153
[Handlers] Make sure to update Content on handlers when the ControlTe…
rmarinho b7e587b
Merge branch 'main' into fix-4135
rmarinho e0c22c1
[DeviceTests] Fix tests NRE
rmarinho 5ca4bae
[DeviceTests] Add device tests for ControlTemplate updates on Content…
rmarinho 11ac75a
Update handler value after calling base ApplyTemplate
rmarinho 16d5e65
[Tests] Fix get childcount when there's no child
rmarinho 9bcfd37
Merge branch 'main' into fix-4135
rmarinho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/Controls/src/Core/HandlerImpl/ContentView/ContentView.Impl.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| namespace Microsoft.Maui.Controls | ||
| { | ||
| public partial class ContentView : IContentView | ||
| { | ||
| object IContentView.Content => Content; | ||
| IView IContentView.PresentedContent => ((this as IControlTemplated).TemplateRoot as IView) ?? Content; | ||
|
|
||
| protected override void OnApplyTemplate() | ||
| { | ||
| base.OnApplyTemplate(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we swap the order of these two? I realize |
||
| Handler?.UpdateValue(nameof(Content)); | ||
| } | ||
| } | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
src/Controls/tests/DeviceTests/Elements/ContentView/ContentViewTests.Android.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using Microsoft.Maui.Handlers; | ||
| using Microsoft.Maui.Platform; | ||
|
|
||
| namespace Microsoft.Maui.DeviceTests | ||
| { | ||
| public partial class ContentViewTests | ||
| { | ||
| static int GetChildCount(ContentViewHandler contentViewHandler) | ||
| { | ||
| return contentViewHandler.PlatformView.ChildCount; | ||
| } | ||
|
|
||
| static int GetContentChildCount(ContentViewHandler contentViewHandler) | ||
| { | ||
| if (contentViewHandler.PlatformView.GetChildAt(0) is LayoutViewGroup childLayoutViewGroup) | ||
| return childLayoutViewGroup.ChildCount; | ||
| else | ||
| return 0; | ||
| } | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
src/Controls/tests/DeviceTests/Elements/ContentView/ContentViewTests.Windows.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using Microsoft.Maui.Handlers; | ||
| using Microsoft.Maui.Platform; | ||
|
|
||
| namespace Microsoft.Maui.DeviceTests | ||
| { | ||
| public partial class ContentViewTests | ||
| { | ||
| static int GetChildCount(ContentViewHandler contentViewHandler) | ||
| { | ||
| return contentViewHandler.PlatformView.Children.Count; | ||
| } | ||
|
|
||
| static int GetContentChildCount(ContentViewHandler contentViewHandler) | ||
| { | ||
| if (contentViewHandler.PlatformView.Children[0] is LayoutPanel childLayoutPanel) | ||
| return childLayoutPanel.Children.Count; | ||
| else | ||
| return 0; | ||
| } | ||
| } | ||
| } |
55 changes: 55 additions & 0 deletions
55
src/Controls/tests/DeviceTests/Elements/ContentView/ContentViewTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Maui.Controls; | ||
| using Microsoft.Maui.Handlers; | ||
| using Microsoft.Maui.Hosting; | ||
| using Microsoft.Maui.Platform; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Maui.DeviceTests | ||
| { | ||
| [Category(TestCategory.ContentView)] | ||
| public partial class ContentViewTests : HandlerTestBase | ||
| { | ||
| void SetupBuilder() | ||
| { | ||
| EnsureHandlerCreated(builder => | ||
| { | ||
| builder.ConfigureMauiHandlers(handlers => | ||
| { | ||
| handlers.AddHandler<Label, LabelHandler>(); | ||
| handlers.AddHandler<IContentView, ContentViewHandler>(); | ||
| handlers.AddHandler<Grid, LayoutHandler>(); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| [Fact("ContentView updating it's ControlTemplate works")] | ||
| public async Task ControlTemplateUpdates() | ||
| { | ||
| SetupBuilder(); | ||
| var child = new Label { Text = "Content 1" }; | ||
| var contentView = new Microsoft.Maui.Controls.ContentView(); | ||
| var header = new Label { Text = "Header" }; | ||
| var footer = new Label { Text = "Footer" }; | ||
| var presenter = new ContentPresenter(); | ||
| var grid = new Grid(); | ||
|
|
||
| var contentViewHandler = await CreateHandlerAsync<ContentViewHandler>(contentView); | ||
|
|
||
| await InvokeOnMainThreadAsync(() => | ||
| { | ||
| contentView.Content = child; | ||
| Assert.True(GetChildCount(contentViewHandler) == 1); | ||
rmarinho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Assert.True(GetContentChildCount(contentViewHandler) == 0); | ||
| grid.Children.Add(header); | ||
| grid.Children.Add(presenter); | ||
| grid.Children.Add(footer); | ||
| var dataTemplate = new ControlTemplate(() => grid); | ||
| contentView.ControlTemplate = dataTemplate; | ||
| Assert.True(GetChildCount(contentViewHandler) == 1); | ||
| Assert.True(GetContentChildCount(contentViewHandler) == 3); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
src/Controls/tests/DeviceTests/Elements/ContentView/ContentViewTests.iOS.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using Microsoft.Maui.Handlers; | ||
|
|
||
| namespace Microsoft.Maui.DeviceTests | ||
| { | ||
| public partial class ContentViewTests | ||
| { | ||
| static int GetChildCount(ContentViewHandler contentViewHandler) | ||
| { | ||
| return contentViewHandler.PlatformView.Subviews.Length; | ||
| } | ||
|
|
||
| static int GetContentChildCount(ContentViewHandler contentViewHandler) | ||
| { | ||
| return contentViewHandler.PlatformView.Subviews[0].Subviews.Length; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.