Skip to content
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

Use PrependToMapping method to replace Window MapTitle method #15041

Merged
merged 5 commits into from May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions eng/pipelines/common/device-tests-steps.yml
Expand Up @@ -62,13 +62,13 @@ steps:
inputs:
testResultsFormat: xUnit
testResultsFiles: '$(TestResultsDirectory)/**/TestResults.xml'
testRunTitle: '$(System.PhaseName)'
testRunTitle: '$(System.PhaseName) (attempt: $(System.JobAttempt))'

- task: PublishBuildArtifacts@1
displayName: Publish Artifacts
condition: always()
inputs:
artifactName: $(System.PhaseName)
artifactName: $(System.PhaseName)_attempt_$(System.JobAttempt)

# This must always be placed as the last step in the job
- template: agent-rebooter/mac.v1.yml@yaml-templates
Expand Down
Expand Up @@ -17,6 +17,7 @@ public static void MapContent(WindowHandler handler, IWindow view)
{
}

[Obsolete]
public static void MapContent(IWindowHandler handler, IWindow view)
{
}
Expand Down
13 changes: 4 additions & 9 deletions src/Controls/src/Core/HandlerImpl/Window/Window.Windows.cs
Expand Up @@ -17,16 +17,11 @@ void UpdateTitleBarDragRectangles(Rect[] titleBarDragRectangles)
Handler?.UpdateValue(nameof(IWindow.TitleBarDragRectangles));
}

static void MapWindowTitle(IWindowHandler handler, IWindow window)
static void MapTitle(IWindowHandler handler, Window window)
{
if (window is Window controlsWindow)
{
handler
.PlatformView
.UpdateTitle(window, controlsWindow.GetCurrentlyPresentedMauiContext());
}

WindowHandler.MapTitle(handler, window);
handler
.PlatformView
.UpdateTitle(window, window.GetCurrentlyPresentedMauiContext());
}

Rect[] IWindow.TitleBarDragRectangles
Expand Down
20 changes: 7 additions & 13 deletions src/Controls/src/Core/HandlerImpl/Window/Window.cs
Expand Up @@ -6,26 +6,20 @@ namespace Microsoft.Maui.Controls
{
public partial class Window
{
[Obsolete("Use WindowHandler.Mapper instead.")]
public static IPropertyMapper<IWindow, WindowHandler> ControlsWindowMapper =
new PropertyMapper<IWindow, WindowHandler>(WindowHandler.Mapper);
new PropertyMapper<Window, WindowHandler>(WindowHandler.Mapper);

// ControlsWindowMapper incorrectly typed to WindowHandler
static IPropertyMapper<IWindow, IWindowHandler> Mapper =
new PropertyMapper<IWindow, IWindowHandler>(ControlsWindowMapper)
{
internal static void RemapForControls()
{
#if ANDROID
// This property is also on the Application Mapper since that's where the attached property exists
[PlatformConfiguration.AndroidSpecific.Application.WindowSoftInputModeAdjustProperty.PropertyName] = MapWindowSoftInputModeAdjust,
// This property is also on the Application Mapper since that's where the attached property exists
WindowHandler.Mapper.ReplaceMapping<IWindow, IWindowHandler>(PlatformConfiguration.AndroidSpecific.Application.WindowSoftInputModeAdjustProperty.PropertyName, MapWindowSoftInputModeAdjust);
#endif

#if WINDOWS
[nameof(ITitledElement.Title)] = MapWindowTitle
WindowHandler.Mapper.PrependToMapping<Window, IWindowHandler>(nameof(ITitledElement.Title), MapTitle);
#endif
};

internal static void RemapForControls()
{
WindowHandler.Mapper = Mapper;
}
}
}
Expand Up @@ -85,5 +85,52 @@ public async Task WindowTitleSetToModalTitleContainer()
Assert.Equal(modalNavigationRootManager.WindowTitle, mauiWindow.Title);
});
}

[Fact]
public async Task WindowTitleIsCorrectAfterPushAndPop()
{
const string OriginalTitle = "Original Title";
const string UpdatedTitle = "Updated Title";

SetupBuilder();

var navPage = new NavigationPage(new ContentPage());
var window = new Window(navPage) { Title = OriginalTitle };

await CreateHandlerAndAddToWindow(window,
(Func<IWindowHandler, Task>)(async (handler) =>
{
var mauiWindow = handler.PlatformView;
var currentPage = navPage.CurrentPage;
var modalPage = new ContentPage();

await currentPage.Navigation.PushModalAsync(modalPage);
await OnLoadedAsync(modalPage);

var currentNavigationRootManager = currentPage
.FindMauiContext()
.GetNavigationRootManager();
var modalNavigationRootManager = modalPage
.FindMauiContext()
.GetNavigationRootManager();

Assert.Equal(OriginalTitle, mauiWindow.Title);
Assert.Equal(OriginalTitle, currentNavigationRootManager.WindowTitle);
Assert.Equal(OriginalTitle, modalNavigationRootManager.WindowTitle);

window.Title = UpdatedTitle;

Assert.Equal(UpdatedTitle, mauiWindow.Title);
Assert.Equal(UpdatedTitle, currentNavigationRootManager.WindowTitle);
Assert.Equal(UpdatedTitle, modalNavigationRootManager.WindowTitle);

await currentPage.Navigation.PopModalAsync();
await OnUnloadedAsync(modalPage);

Assert.Equal(UpdatedTitle, mauiWindow.Title);
Assert.Equal(UpdatedTitle, currentNavigationRootManager.WindowTitle);
Assert.Equal(UpdatedTitle, modalNavigationRootManager.WindowTitle);
}));
}
}
}