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

Interfaced handlers for Label, NavigationView, Page #4841

Merged
merged 6 commits into from
Feb 23, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Controls/src/Core/HandlerImpl/Label/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.Maui.Controls
public partial class Label
{
/// <include file="../../../../docs/Microsoft.Maui.Controls/Label.xml" path="//Member[@MemberName='ControlsLabelMapper']/Docs" />
public static IPropertyMapper<ILabel, LabelHandler> ControlsLabelMapper = new PropertyMapper<Label, LabelHandler>(LabelHandler.LabelMapper)
public static IPropertyMapper<ILabel, LabelHandler> ControlsLabelMapper = new PropertyMapper<Label, LabelHandler>(LabelHandler.Mapper)
{
[nameof(TextType)] = MapTextType,
[nameof(Text)] = MapText,
Expand All @@ -26,7 +26,7 @@ public partial class Label
// ILabel does not include the TextType property, so we map it here to handle HTML text
// And we map some of the other property handlers to Controls-specific versions that avoid stepping on HTML text settings

LabelHandler.LabelMapper = ControlsLabelMapper;
LabelHandler.Mapper = ControlsLabelMapper;
}
}
}
18 changes: 18 additions & 0 deletions src/Core/src/Handlers/Label/ILabelHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#if __IOS__ || MACCATALYST
using PlatformView = Microsoft.Maui.Platform.MauiLabel;
#elif MONOANDROID
using PlatformView = AndroidX.AppCompat.Widget.AppCompatTextView;
#elif WINDOWS
using PlatformView = Microsoft.UI.Xaml.Controls.TextBlock;
#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID)
using PlatformView = System.Object;
#endif

namespace Microsoft.Maui.Handlers
{
public partial interface ILabelHandler : IViewHandler
{
new ILabel VirtualView { get; }
new PlatformView PlatformView { get; }
}
}
23 changes: 11 additions & 12 deletions src/Core/src/Handlers/Label/LabelHandler.Android.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Android.Views;
using Android.Widget;
using AndroidX.AppCompat.Widget;
using Microsoft.Maui.Graphics;

Expand Down Expand Up @@ -58,59 +57,59 @@ void SetupDefaults(AppCompatTextView platformView)
LineSpacingMultDefault = platformView.LineSpacingMultiplier;
}

public static void MapText(LabelHandler handler, ILabel label)
public static void MapText(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateTextPlainText(label);
}

public static void MapTextColor(LabelHandler handler, ILabel label)
public static void MapTextColor(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateTextColor(label, DefaultTextColor);
}

public static void MapCharacterSpacing(LabelHandler handler, ILabel label)
public static void MapCharacterSpacing(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateCharacterSpacing(label);
}

public static void MapHorizontalTextAlignment(LabelHandler handler, ILabel label)
public static void MapHorizontalTextAlignment(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateHorizontalTextAlignment(label);
}

public static void MapVerticalTextAlignment(LabelHandler handler, ILabel label)
public static void MapVerticalTextAlignment(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateVerticalTextAlignment(label);
}

public static void MapLineBreakMode(LabelHandler handler, ILabel label)
public static void MapLineBreakMode(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateLineBreakMode(label);
}

public static void MapMaxLines(LabelHandler handler, ILabel label)
public static void MapMaxLines(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateMaxLines(label);
}

public static void MapPadding(LabelHandler handler, ILabel label)
public static void MapPadding(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdatePadding(label);
}

public static void MapTextDecorations(LabelHandler handler, ILabel label)
public static void MapTextDecorations(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateTextDecorations(label);
}

public static void MapFont(LabelHandler handler, ILabel label)
public static void MapFont(ILabelHandler handler, ILabel label)
{
var fontManager = handler.GetRequiredService<IFontManager>();

handler.PlatformView?.UpdateFont(label, fontManager);
}

public static void MapLineHeight(LabelHandler handler, ILabel label)
public static void MapLineHeight(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateLineHeight(label);
}
Expand Down
22 changes: 11 additions & 11 deletions src/Core/src/Handlers/Label/LabelHandler.Standard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ public partial class LabelHandler : ViewHandler<ILabel, object>
{
protected override object CreatePlatformView() => throw new NotImplementedException();

public static void MapText(IViewHandler handler, ILabel label) { }
public static void MapTextColor(IViewHandler handler, ILabel label) { }
public static void MapCharacterSpacing(IViewHandler handler, ILabel label) { }
public static void MapFont(LabelHandler handler, ILabel label) { }
public static void MapHorizontalTextAlignment(LabelHandler handler, ILabel label) { }
public static void MapVerticalTextAlignment(LabelHandler handler, ILabel label) { }
public static void MapLineBreakMode(LabelHandler handler, ILabel label) { }
public static void MapTextDecorations(LabelHandler handler, ILabel label) { }
public static void MapMaxLines(IViewHandler handler, ILabel label) { }
public static void MapPadding(LabelHandler handler, ILabel label) { }
public static void MapLineHeight(LabelHandler handler, ILabel label) { }
public static void MapText(ILabelHandler handler, ILabel label) { }
public static void MapTextColor(ILabelHandler handler, ILabel label) { }
public static void MapCharacterSpacing(ILabelHandler handler, ILabel label) { }
public static void MapFont(ILabelHandler handler, ILabel label) { }
public static void MapHorizontalTextAlignment(ILabelHandler handler, ILabel label) { }
public static void MapVerticalTextAlignment(ILabelHandler handler, ILabel label) { }
public static void MapLineBreakMode(ILabelHandler handler, ILabel label) { }
public static void MapTextDecorations(ILabelHandler handler, ILabel label) { }
public static void MapMaxLines(ILabelHandler handler, ILabel label) { }
public static void MapPadding(ILabelHandler handler, ILabel label) { }
public static void MapLineHeight(ILabelHandler handler, ILabel label) { }
}
}
26 changes: 13 additions & 13 deletions src/Core/src/Handlers/Label/LabelHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,55 @@ public partial class LabelHandler : ViewHandler<ILabel, TextBlock>
VirtualView?.Background != null ||
base.NeedsContainer;

public static void MapBackground(LabelHandler handler, ILabel label)
public static void MapBackground(ILabelHandler handler, ILabel label)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));

handler.ToPlatform().UpdateBackground(label);
}

public static void MapOpacity(LabelHandler handler, ILabel label)
public static void MapOpacity(ILabelHandler handler, ILabel label)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));
handler.PlatformView.UpdateOpacity(label);
handler.ToPlatform().UpdateOpacity(label);
}

public static void MapText(LabelHandler handler, ILabel label) =>
public static void MapText(ILabelHandler handler, ILabel label) =>
handler.PlatformView?.UpdateText(label);

public static void MapTextColor(LabelHandler handler, ILabel label) =>
public static void MapTextColor(ILabelHandler handler, ILabel label) =>
handler.PlatformView?.UpdateTextColor(label);

public static void MapCharacterSpacing(LabelHandler handler, ILabel label) =>
public static void MapCharacterSpacing(ILabelHandler handler, ILabel label) =>
handler.PlatformView?.UpdateCharacterSpacing(label);

public static void MapFont(LabelHandler handler, ILabel label)
public static void MapFont(ILabelHandler handler, ILabel label)
{
var fontManager = handler.GetRequiredService<IFontManager>();

handler.PlatformView?.UpdateFont(label, fontManager);
}

public static void MapHorizontalTextAlignment(LabelHandler handler, ILabel label) =>
public static void MapHorizontalTextAlignment(ILabelHandler handler, ILabel label) =>
handler.PlatformView?.UpdateHorizontalTextAlignment(label);

public static void MapVerticalTextAlignment(LabelHandler handler, ILabel label) =>
public static void MapVerticalTextAlignment(ILabelHandler handler, ILabel label) =>
handler.PlatformView?.UpdateVerticalTextAlignment(label);

public static void MapLineBreakMode(LabelHandler handler, ILabel label) =>
public static void MapLineBreakMode(ILabelHandler handler, ILabel label) =>
handler.PlatformView?.UpdateLineBreakMode(label);

public static void MapTextDecorations(LabelHandler handler, ILabel label) =>
public static void MapTextDecorations(ILabelHandler handler, ILabel label) =>
handler.PlatformView?.UpdateTextDecorations(label);

public static void MapMaxLines(LabelHandler handler, ILabel label) =>
public static void MapMaxLines(ILabelHandler handler, ILabel label) =>
handler.PlatformView?.UpdateMaxLines(label);

public static void MapPadding(LabelHandler handler, ILabel label) =>
public static void MapPadding(ILabelHandler handler, ILabel label) =>
handler.PlatformView?.UpdatePadding(label);

public static void MapLineHeight(LabelHandler handler, ILabel label) =>
public static void MapLineHeight(ILabelHandler handler, ILabel label) =>
handler.PlatformView?.UpdateLineHeight(label);
}
}
30 changes: 23 additions & 7 deletions src/Core/src/Handlers/Label/LabelHandler.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#nullable enable
#if __IOS__ || MACCATALYST
using PlatformView = Microsoft.Maui.Platform.MauiLabel;
#elif MONOANDROID
using PlatformView = AndroidX.AppCompat.Widget.AppCompatTextView;
#elif WINDOWS
using PlatformView = Microsoft.UI.Xaml.Controls.TextBlock;
#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID)
using PlatformView = System.Object;
#endif

namespace Microsoft.Maui.Handlers
{
public partial class LabelHandler
public partial class LabelHandler : ILabelHandler
{
public static IPropertyMapper<ILabel, LabelHandler> LabelMapper = new PropertyMapper<ILabel, LabelHandler>(ViewHandler.ViewMapper)
public static IPropertyMapper<ILabel, ILabelHandler> Mapper = new PropertyMapper<ILabel, ILabelHandler>(ViewHandler.ViewMapper)
{
#if WINDOWS || __IOS__
[nameof(ILabel.Background)] = MapBackground,
Expand All @@ -22,21 +32,27 @@ public partial class LabelHandler
[nameof(ILabel.TextDecorations)] = MapTextDecorations,
};

public static CommandMapper<IActivityIndicator, ILabelHandler> CommandMapper = new(ViewCommandMapper)
{
};

static LabelHandler()
{
#if __IOS__
LabelMapper.PrependToMapping(nameof(IView.FlowDirection), (h, __) => h.UpdateValue(nameof(ITextAlignment.HorizontalTextAlignment)));
Mapper.PrependToMapping(nameof(IView.FlowDirection), (h, __) => h.UpdateValue(nameof(ITextAlignment.HorizontalTextAlignment)));
#endif
}

public LabelHandler() : base(LabelMapper)
public LabelHandler() : base(Mapper)
{

}

public LabelHandler(IPropertyMapper? mapper = null) : base(mapper ?? LabelMapper)
public LabelHandler(IPropertyMapper? mapper = null) : base(mapper ?? Mapper)
{

}

ILabel ILabelHandler.VirtualView => VirtualView;

PlatformView ILabelHandler.PlatformView => PlatformView;
}
}
26 changes: 13 additions & 13 deletions src/Core/src/Handlers/Label/LabelHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,72 @@ public partial class LabelHandler : ViewHandler<ILabel, MauiLabel>
VirtualView?.Background != null ||
base.NeedsContainer;

public static void MapBackground(LabelHandler handler, ILabel label)
public static void MapBackground(ILabelHandler handler, ILabel label)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));

handler.ToPlatform().UpdateBackground(label);
}

public static void MapText(LabelHandler handler, ILabel label)
public static void MapText(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateTextPlainText(label);

// Any text update requires that we update any attributed string formatting
MapFormatting(handler, label);
}

public static void MapTextColor(LabelHandler handler, ILabel label)
public static void MapTextColor(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateTextColor(label);
}

public static void MapCharacterSpacing(LabelHandler handler, ILabel label)
public static void MapCharacterSpacing(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateCharacterSpacing(label);
}

public static void MapHorizontalTextAlignment(LabelHandler handler, ILabel label)
public static void MapHorizontalTextAlignment(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateHorizontalTextAlignment(label);
}

[MissingMapper]
public static void MapVerticalTextAlignment(LabelHandler handler, ILabel label) { }
public static void MapVerticalTextAlignment(ILabelHandler handler, ILabel label) { }

public static void MapLineBreakMode(LabelHandler handler, ILabel label)
public static void MapLineBreakMode(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateLineBreakMode(label);
}

public static void MapMaxLines(LabelHandler handler, ILabel label)
public static void MapMaxLines(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateMaxLines(label);
}

public static void MapPadding(LabelHandler handler, ILabel label)
public static void MapPadding(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdatePadding(label);
}

public static void MapTextDecorations(LabelHandler handler, ILabel label)
public static void MapTextDecorations(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateTextDecorations(label);
}

public static void MapFont(LabelHandler handler, ILabel label)
public static void MapFont(ILabelHandler handler, ILabel label)
{
var fontManager = handler.GetRequiredService<IFontManager>();

handler.PlatformView?.UpdateFont(label, fontManager);
}

public static void MapLineHeight(LabelHandler handler, ILabel label)
public static void MapLineHeight(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateLineHeight(label);
}

public static void MapFormatting(LabelHandler handler, ILabel label)
public static void MapFormatting(ILabelHandler handler, ILabel label)
{
// Update all of the attributed text formatting properties
handler.PlatformView?.UpdateLineHeight(label);
Expand Down
18 changes: 18 additions & 0 deletions src/Core/src/Handlers/NavigationPage/INavigationViewHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#if __IOS__ || MACCATALYST
using PlatformView = UIKit.UIView;
#elif MONOANDROID
using PlatformView = Android.Views.View;
#elif WINDOWS
using PlatformView = Microsoft.UI.Xaml.Controls.Frame;
#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID)
using PlatformView = System.Object;
#endif

namespace Microsoft.Maui.Handlers
{
public partial interface INavigationViewHandler : IViewHandler
{
new IStackNavigationView VirtualView { get; }
new PlatformView PlatformView { get; }
}
}
Loading