Skip to content

Commit

Permalink
Setup legacy mappers (#18087)
Browse files Browse the repository at this point in the history
* Route Controls Mapper to Core Mapper

* Update ControlsMapper.cs

* - fix test
  • Loading branch information
PureWeen authored Oct 24, 2023
1 parent 296588c commit d5cb0cd
Show file tree
Hide file tree
Showing 24 changed files with 271 additions and 33 deletions.
3 changes: 2 additions & 1 deletion src/Controls/src/Core/Application/Application.Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#nullable disable
using System;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls
{
public partial class Application
{
[Obsolete("Use ApplicationHandler.Mapper instead.")]
public static IPropertyMapper<IApplication, ApplicationHandler> ControlsApplicationMapper =
new PropertyMapper<Application, ApplicationHandler>(ApplicationHandler.Mapper);
new ControlsMapper<Application, ApplicationHandler>(ApplicationHandler.Mapper);

internal static new void RemapForControls()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Controls/src/Core/Button/Button.Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Maui.Controls.Compatibility;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Handlers;

Expand All @@ -15,7 +16,7 @@ public partial class Button
/// The property mapper that maps the abstract properties to the platform-specific methods for further processing.
/// </summary>
[Obsolete("Use ButtonHandler.Mapper instead.")]
public static IPropertyMapper<IButton, ButtonHandler> ControlsButtonMapper = new PropertyMapper<Button, ButtonHandler>(ButtonHandler.Mapper);
public static IPropertyMapper<IButton, ButtonHandler> ControlsButtonMapper = new ControlsMapper<Button, ButtonHandler>(ButtonHandler.Mapper);

internal new static void RemapForControls()
{
Expand Down
44 changes: 44 additions & 0 deletions src/Controls/src/Core/Compatibility/ControlsMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.Maui.Controls.Compatibility
{
[Obsolete("Delete this for .NET9")]
class ControlsMapper<TVirtualView, TViewHandler> : IPropertyMapper<TVirtualView, TViewHandler>
where TVirtualView : IElement
where TViewHandler : IElementHandler
{
IPropertyMapper<IElement, IElementHandler> _propertyMapper;

public ControlsMapper(IPropertyMapper<IElement, IElementHandler> propertyMapper) : base()
{
_propertyMapper = propertyMapper;
}

public void Add(string key, Action<TViewHandler, TVirtualView> action)
{
_propertyMapper.ReplaceMapping(key, action);
}

public IEnumerable<string> GetKeys()
{
return _propertyMapper.GetKeys();
}

public Action<IElementHandler, IElement>? GetProperty(string key)
{
return _propertyMapper.GetProperty(key);
}

public void UpdateProperties(IElementHandler elementHandler, IElement virtualView)
{
_propertyMapper.UpdateProperties(elementHandler, virtualView);
}

public void UpdateProperty(IElementHandler elementHandler, IElement virtualView, string property)
{
_propertyMapper.UpdateProperty(elementHandler, virtualView, property);
}
}
}
3 changes: 2 additions & 1 deletion src/Controls/src/Core/DatePicker/DatePicker.Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#nullable disable
using System;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls
{
public partial class DatePicker
{
[Obsolete("Use DatePickerHandler.Mapper instead.")]
public static IPropertyMapper<IDatePicker, DatePickerHandler> ControlsDatePickerMapper = new PropertyMapper<DatePicker, DatePickerHandler>(DatePickerHandler.Mapper);
public static IPropertyMapper<IDatePicker, DatePickerHandler> ControlsDatePickerMapper = new ControlsMapper<DatePicker, DatePickerHandler>(DatePickerHandler.Mapper);

internal static new void RemapForControls()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Controls/src/Core/Editor/Editor.Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#nullable disable
using System;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls
{
public partial class Editor
{
[Obsolete("Use EditorHandler.Mapper instead.")]
public static IPropertyMapper<IEditor, EditorHandler> ControlsEditorMapper =
new PropertyMapper<Editor, EditorHandler>(EditorHandler.Mapper);
new ControlsMapper<Editor, EditorHandler>(EditorHandler.Mapper);

internal static new void RemapForControls()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Controls/src/Core/Element/Element.Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable disable
using System;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Controls.Compatibility;


namespace Microsoft.Maui.Controls
Expand All @@ -11,7 +12,7 @@ public partial class Element
/// Maps UI information to platform-specific implementations for accessibility services
/// </summary>
[Obsolete("Use ViewHandler.ViewMapper instead.")]
public static IPropertyMapper<Maui.IElement, IElementHandler> ControlsElementMapper = new PropertyMapper<IElement, IElementHandler>(ViewHandler.ViewMapper);
public static IPropertyMapper<Maui.IElement, IElementHandler> ControlsElementMapper = new ControlsMapper<IElement, IElementHandler>(ViewHandler.ViewMapper);

internal static void RemapForControls()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Controls/src/Core/Entry/Entry.Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#nullable disable
using System;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls
{
public partial class Entry
{
[Obsolete("Use EntryHandler.Mapper instead.")]
public static IPropertyMapper<IEntry, EntryHandler> ControlsEntryMapper =
new PropertyMapper<Entry, EntryHandler>(EntryHandler.Mapper);
new ControlsMapper<Entry, EntryHandler>(EntryHandler.Mapper);

internal static new void RemapForControls()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Controls/src/Core/FlyoutPage/FlyoutPage.Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls
{
/// <include file="../../../docs/Microsoft.Maui.Controls/FlyoutPage.xml" path="Type[@FullName='Microsoft.Maui.Controls.FlyoutPage']/Docs/*" />
public partial class FlyoutPage
{
[Obsolete("Use FlyoutViewHandler.Mapper instead.")]
public static IPropertyMapper<IFlyoutView, FlyoutViewHandler> ControlsFlyoutPageMapper = new PropertyMapper<IFlyoutView, FlyoutViewHandler>(FlyoutViewHandler.Mapper);
public static IPropertyMapper<IFlyoutView, FlyoutViewHandler> ControlsFlyoutPageMapper = new ControlsMapper<IFlyoutView, FlyoutViewHandler>(FlyoutViewHandler.Mapper);

internal new static void RemapForControls()
{
Expand Down
5 changes: 4 additions & 1 deletion src/Controls/src/Core/Label/Label.Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable disable
using System;
using System.Collections.Generic;
using Microsoft.Maui.Controls.Compatibility;
using Microsoft.Maui.Handlers;

namespace Microsoft.Maui.Controls
Expand All @@ -8,7 +10,8 @@ namespace Microsoft.Maui.Controls
public partial class Label
{
[Obsolete("Use LabelHandler.Mapper instead.")]
public static IPropertyMapper<ILabel, LabelHandler> ControlsLabelMapper = new PropertyMapper<Label, LabelHandler>(LabelHandler.Mapper);
public static IPropertyMapper<ILabel, LabelHandler> ControlsLabelMapper =
new ControlsMapper<ILabel, LabelHandler>(LabelHandler.Mapper);

internal static new void RemapForControls()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#nullable disable
using System;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls
{
public partial class NavigationPage
{
[Obsolete("Use NavigationViewHandler.Mapper instead.")]
public static IPropertyMapper<IStackNavigationView, NavigationViewHandler> ControlsNavigationPageMapper =
new PropertyMapper<NavigationPage, NavigationViewHandler>(NavigationViewHandler.Mapper);
new ControlsMapper<NavigationPage, NavigationViewHandler>(NavigationViewHandler.Mapper);

internal static new void RemapForControls()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Controls/src/Core/Picker/Picker.Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#nullable disable
using System;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls
{
public partial class Picker
{
[Obsolete("Use PickerHandler.Mapper instead.")]
public static IPropertyMapper<IPicker, PickerHandler> ControlsPickerMapper = new PropertyMapper<Picker, PickerHandler>(PickerHandler.Mapper);
public static IPropertyMapper<IPicker, PickerHandler> ControlsPickerMapper = new ControlsMapper<Picker, PickerHandler>(PickerHandler.Mapper);

internal static new void RemapForControls()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Controls/src/Core/RadioButton/RadioButton.Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable disable
using System;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls
{
Expand All @@ -10,7 +11,7 @@ public partial class RadioButton

[Obsolete("Use RadioButtonHandler.Mapper instead.")]
public static IPropertyMapper<RadioButton, RadioButtonHandler> ControlsRadioButtonMapper =
new PropertyMapper<RadioButton, RadioButtonHandler>(RadioButtonHandler.Mapper);
new ControlsMapper<RadioButton, RadioButtonHandler>(RadioButtonHandler.Mapper);

internal new static void RemapForControls()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Controls/src/Core/RefreshView/RefreshView.Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#nullable disable
using System;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls
{
public partial class RefreshView
{
[Obsolete("Use RefreshViewHandler.Mapper instead.")]
public static IPropertyMapper<IRefreshView, RefreshViewHandler> ControlsRefreshViewMapper = new PropertyMapper<RefreshView, RefreshViewHandler>(RefreshViewHandler.Mapper);
public static IPropertyMapper<IRefreshView, RefreshViewHandler> ControlsRefreshViewMapper = new ControlsMapper<RefreshView, RefreshViewHandler>(RefreshViewHandler.Mapper);

internal static new void RemapForControls()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Controls/src/Core/ScrollView/ScrollView.Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#nullable disable
using System;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls
{
public partial class ScrollView
{
[Obsolete("Use ScrollViewHandler.Mapper instead.")]
public static IPropertyMapper<IScrollView, ScrollViewHandler> ControlsScrollViewMapper =
new PropertyMapper<ScrollView, ScrollViewHandler>(ScrollViewHandler.Mapper);
new ControlsMapper<ScrollView, ScrollViewHandler>(ScrollViewHandler.Mapper);

internal static new void RemapForControls()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Controls/src/Core/SearchBar/SearchBar.Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#nullable disable
using System;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls
{
public partial class SearchBar
{
[Obsolete("Use SearchBarHandler.Mapper instead.")]
public static IPropertyMapper<ISearchBar, SearchBarHandler> ControlsSearchBarMapper =
new PropertyMapper<SearchBar, SearchBarHandler>(SearchBarHandler.Mapper);
new ControlsMapper<SearchBar, SearchBarHandler>(SearchBarHandler.Mapper);

internal static new void RemapForControls()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Controls/src/Core/Shape/Shape.Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls.Shapes
{
public partial class Shape
{
[Obsolete("Use ShapeViewHandler.Mapper instead.")]
public static IPropertyMapper<IShapeView, IShapeViewHandler> ControlsShapeViewMapper = new PropertyMapper<IShapeView, IShapeViewHandler>(ShapeViewHandler.Mapper);
public static IPropertyMapper<IShapeView, IShapeViewHandler> ControlsShapeViewMapper = new ControlsMapper<IShapeView, IShapeViewHandler>(ShapeViewHandler.Mapper);

internal new static void RemapForControls()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Controls/src/Core/TabbedPage/TabbedPage.Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls
{
public partial class TabbedPage
{
[Obsolete("Use TabbedViewHandler.Mapper instead.")]
public static IPropertyMapper<ITabbedView, ITabbedViewHandler> ControlsTabbedPageMapper = new PropertyMapper<TabbedPage, ITabbedViewHandler>(TabbedViewHandler.Mapper);
public static IPropertyMapper<ITabbedView, ITabbedViewHandler> ControlsTabbedPageMapper = new ControlsMapper<TabbedPage, ITabbedViewHandler>(TabbedViewHandler.Mapper);

internal new static void RemapForControls()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Controls/src/Core/TimePicker/TimePicker.Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#nullable disable
using System;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls
{
public partial class TimePicker
{
[Obsolete("Use TimePickerHandler.Mapper instead.")]
public static IPropertyMapper<ITimePicker, TimePickerHandler> ControlsTimePickerMapper = new PropertyMapper<TimePicker, TimePickerHandler>(TimePickerHandler.Mapper);
public static IPropertyMapper<ITimePicker, TimePickerHandler> ControlsTimePickerMapper = new ControlsMapper<TimePicker, TimePickerHandler>(TimePickerHandler.Mapper);

internal static new void RemapForControls()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Controls/src/Core/Toolbar/Toolbar.Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls
{
Expand All @@ -14,7 +15,7 @@ public partial class Toolbar

[Obsolete("Use ToolbarHandler.Mapper instead.")]
public static IPropertyMapper<Toolbar, ToolbarHandler> ControlsToolbarMapper =
new PropertyMapper<Toolbar, ToolbarHandler>(ToolbarHandler.Mapper);
new ControlsMapper<Toolbar, ToolbarHandler>(ToolbarHandler.Mapper);

internal static void RemapForControls()
{
Expand Down
33 changes: 21 additions & 12 deletions src/Controls/src/Core/VisualElement/VisualElement.Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
#nullable disable
using System;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls
{
/// <include file="../../../docs/Microsoft.Maui.Controls/VisualElement.xml" path="Type[@FullName='Microsoft.Maui.Controls.VisualElement']/Docs/*" />
public partial class VisualElement
{
[Obsolete("Use ViewHandler.ViewMapper instead.")]
public static IPropertyMapper<IView, IViewHandler> ControlsVisualElementMapper = new PropertyMapper<IView, IViewHandler>(Element.ControlsElementMapper);
public static IPropertyMapper<IView, IViewHandler> ControlsVisualElementMapper = new ControlsMapper<IView, IViewHandler>(Element.ControlsElementMapper);


internal static new void RemapForControls()
{
RemapForControls(ViewHandler.ViewMapper, ViewHandler.ViewCommandMapper);
}

internal static void RemapForControls(
IPropertyMapper<IView, IViewHandler> viewMapper,
CommandMapper<IView, IViewHandler> commandMapper)
{
#if WINDOWS
ViewHandler.ViewMapper.ReplaceMapping<IView, IViewHandler>(PlatformConfiguration.WindowsSpecific.VisualElement.AccessKeyHorizontalOffsetProperty.PropertyName, MapAccessKeyHorizontalOffset);
ViewHandler.ViewMapper.ReplaceMapping<IView, IViewHandler>(PlatformConfiguration.WindowsSpecific.VisualElement.AccessKeyPlacementProperty.PropertyName, MapAccessKeyPlacement);
ViewHandler.ViewMapper.ReplaceMapping<IView, IViewHandler>(PlatformConfiguration.WindowsSpecific.VisualElement.AccessKeyProperty.PropertyName, MapAccessKey);
ViewHandler.ViewMapper.ReplaceMapping<IView, IViewHandler>(PlatformConfiguration.WindowsSpecific.VisualElement.AccessKeyVerticalOffsetProperty.PropertyName, MapAccessKeyVerticalOffset);
viewMapper.ReplaceMapping<IView, IViewHandler>(PlatformConfiguration.WindowsSpecific.VisualElement.AccessKeyHorizontalOffsetProperty.PropertyName, MapAccessKeyHorizontalOffset);
viewMapper.ReplaceMapping<IView, IViewHandler>(PlatformConfiguration.WindowsSpecific.VisualElement.AccessKeyPlacementProperty.PropertyName, MapAccessKeyPlacement);
viewMapper.ReplaceMapping<IView, IViewHandler>(PlatformConfiguration.WindowsSpecific.VisualElement.AccessKeyProperty.PropertyName, MapAccessKey);
viewMapper.ReplaceMapping<IView, IViewHandler>(PlatformConfiguration.WindowsSpecific.VisualElement.AccessKeyVerticalOffsetProperty.PropertyName, MapAccessKeyVerticalOffset);
#endif
ViewHandler.ViewMapper.ReplaceMapping<IView, IViewHandler>(nameof(BackgroundColor), MapBackgroundColor);
ViewHandler.ViewMapper.ReplaceMapping<IView, IViewHandler>(nameof(Page.BackgroundImageSource), MapBackgroundImageSource);
ViewHandler.ViewMapper.ReplaceMapping<IView, IViewHandler>(SemanticProperties.DescriptionProperty.PropertyName, MapSemanticPropertiesDescriptionProperty);
ViewHandler.ViewMapper.ReplaceMapping<IView, IViewHandler>(SemanticProperties.HintProperty.PropertyName, MapSemanticPropertiesHintProperty);
ViewHandler.ViewMapper.ReplaceMapping<IView, IViewHandler>(SemanticProperties.HeadingLevelProperty.PropertyName, MapSemanticPropertiesHeadingLevelProperty);
viewMapper.ReplaceMapping<IView, IViewHandler>(nameof(BackgroundColor), MapBackgroundColor);
viewMapper.ReplaceMapping<IView, IViewHandler>(nameof(Page.BackgroundImageSource), MapBackgroundImageSource);
viewMapper.ReplaceMapping<IView, IViewHandler>(SemanticProperties.DescriptionProperty.PropertyName, MapSemanticPropertiesDescriptionProperty);
viewMapper.ReplaceMapping<IView, IViewHandler>(SemanticProperties.HintProperty.PropertyName, MapSemanticPropertiesHintProperty);
viewMapper.ReplaceMapping<IView, IViewHandler>(SemanticProperties.HeadingLevelProperty.PropertyName, MapSemanticPropertiesHeadingLevelProperty);

ViewHandler.ViewMapper.AppendToMapping<VisualElement, IViewHandler>(nameof(IViewHandler.ContainerView), MapContainerView);
viewMapper.AppendToMapping<VisualElement, IViewHandler>(nameof(IViewHandler.ContainerView), MapContainerView);

ViewHandler.ViewCommandMapper.ModifyMapping<VisualElement, IViewHandler>(nameof(IView.Focus), MapFocus);
commandMapper.ModifyMapping<VisualElement, IViewHandler>(nameof(IView.Focus), MapFocus);
}

public static void MapBackgroundColor(IViewHandler handler, IView view) =>
Expand Down
Loading

0 comments on commit d5cb0cd

Please sign in to comment.