зеркало из https://github.com/DeGsoft/maui-linux.git
[Core] LabelHandler Preview (#13764)
* LabelHandler with a subset of the properties (Text and TextColor) * Init LabelHandler * Fixed build errors * Updated TexColor property * Removed not implemented Label properties * Updated Button.Impl.cs * Updated FormsHandlers * Fix up default text color handling * Fix rebase errors and sample app * Clean up unused stuff * Fix interface structure * Fix stubs Co-authored-by: E.Z. Hart <hartez@gmail.com> Co-authored-by: Shane Neuville <shneuvil@microsoft.com>
This commit is contained in:
Родитель
4ca457d330
Коммит
505fc4b41b
|
@ -1,4 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Xamarin.Platform.Handlers;
|
using Xamarin.Platform.Handlers;
|
||||||
|
@ -10,15 +10,11 @@ namespace Xamarin.Forms
|
||||||
// This is used to register the handler version against the xplat code so that the handler version will be used
|
// This is used to register the handler version against the xplat code so that the handler version will be used
|
||||||
// when running a full Xamarin.Forms application. This lets us test the handler code inside the Control Gallery
|
// when running a full Xamarin.Forms application. This lets us test the handler code inside the Control Gallery
|
||||||
// And other scenarios
|
// And other scenarios
|
||||||
|
|
||||||
public static void InitHandlers()
|
public static void InitHandlers()
|
||||||
{
|
{
|
||||||
//Xamarin.Platform.Registrar.Handlers.Register(typeof(Slider), typeof(Xamarin.Platform.Handlers.SliderHandler));
|
Platform.Registrar.Handlers.Register(typeof(Label), typeof(LabelHandler));
|
||||||
//Xamarin.Platform.Registrar.Handlers.Register(typeof(Button), typeof(Xamarin.Platform.Handlers.ButtonHandler));
|
|
||||||
//RegistrarHandlers.Handlers.Register<Xamarin.Forms.StackLayout, Xamarin.Platform.Handlers.LayoutHandler>();
|
|
||||||
|
|
||||||
Xamarin.Platform.Registrar.Handlers.Register<VerticalStackLayout, LayoutHandler>();
|
Xamarin.Platform.Registrar.Handlers.Register<VerticalStackLayout, LayoutHandler>();
|
||||||
Xamarin.Platform.Registrar.Handlers.Register<HorizontalStackLayout, LayoutHandler>();
|
Xamarin.Platform.Registrar.Handlers.Register<HorizontalStackLayout, LayoutHandler>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,27 +1,22 @@
|
||||||
using System;
|
using Xamarin.Platform;
|
||||||
using Xamarin.Platform;
|
|
||||||
|
|
||||||
namespace Xamarin.Forms
|
namespace Xamarin.Forms
|
||||||
{
|
{
|
||||||
public partial class Button : IButton
|
public partial class Button : IButton
|
||||||
{
|
{
|
||||||
public TextAlignment HorizontalTextAlignment => throw new NotImplementedException();
|
|
||||||
|
|
||||||
public TextAlignment VerticalTextAlignment => throw new NotImplementedException();
|
|
||||||
|
|
||||||
void IButton.Clicked()
|
void IButton.Clicked()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
(this as IButtonController).SendClicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IButton.Pressed()
|
void IButton.Pressed()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
(this as IButtonController).SendPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IButton.Released()
|
void IButton.Released()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
(this as IButtonController).SendReleased();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
using Xamarin.Platform;
|
||||||
|
|
||||||
|
namespace Xamarin.Forms
|
||||||
|
{
|
||||||
|
public partial class Label : ILabel
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using Xamarin.Platform;
|
||||||
using Xamarin.Platform;
|
|
||||||
|
|
||||||
namespace Xamarin.Forms
|
namespace Xamarin.Forms
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,7 +10,7 @@ using Xamarin.Forms.Internals;
|
||||||
namespace Xamarin.Forms
|
namespace Xamarin.Forms
|
||||||
{
|
{
|
||||||
[ContentProperty("Text")]
|
[ContentProperty("Text")]
|
||||||
public class Label : View, IFontElement, ITextElement, ITextAlignmentElement, ILineHeightElement, IElementConfiguration<Label>, IDecorableTextElement, IPaddingElement
|
public partial class Label : View, IFontElement, ITextElement, ITextAlignmentElement, ILineHeightElement, IElementConfiguration<Label>, IDecorableTextElement, IPaddingElement
|
||||||
{
|
{
|
||||||
public static readonly BindableProperty HorizontalTextAlignmentProperty = TextAlignmentElement.HorizontalTextAlignmentProperty;
|
public static readonly BindableProperty HorizontalTextAlignmentProperty = TextAlignmentElement.HorizontalTextAlignmentProperty;
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,15 @@ namespace Sample
|
||||||
|
|
||||||
public virtual void Arrange(Rectangle bounds)
|
public virtual void Arrange(Rectangle bounds)
|
||||||
{
|
{
|
||||||
|
if (IsArrangeValid)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Frame = this.ComputeFrame(bounds);
|
Frame = this.ComputeFrame(bounds);
|
||||||
|
IsArrangeValid = true;
|
||||||
|
|
||||||
|
Handler?.SetFrame(Frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void InvalidateMeasure()
|
public virtual void InvalidateMeasure()
|
||||||
|
|
|
@ -3,26 +3,21 @@ using Xamarin.Platform;
|
||||||
|
|
||||||
namespace Sample
|
namespace Sample
|
||||||
{
|
{
|
||||||
public class Label : Xamarin.Forms.View, ILabel
|
public class Label : View, ILabel
|
||||||
{
|
{
|
||||||
|
public Label()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public string Text { get; set; }
|
public string Text { get; set; }
|
||||||
|
|
||||||
public Color TextColor { get; set; }
|
public Color TextColor { get; set; }
|
||||||
|
|
||||||
public Font Font { get; set; }
|
public FontAttributes FontAttributes => throw new System.NotImplementedException();
|
||||||
|
|
||||||
public string FontFamily { get; set; }
|
public string FontFamily => throw new System.NotImplementedException();
|
||||||
|
|
||||||
public double FontSize { get; set; }
|
public double FontSize => throw new System.NotImplementedException();
|
||||||
|
|
||||||
public FontAttributes FontAttributes { get; set; }
|
|
||||||
|
|
||||||
public TextTransform TextTransform { get; set; }
|
|
||||||
|
|
||||||
public TextAlignment HorizontalTextAlignment { get; set; }
|
|
||||||
|
|
||||||
public TextAlignment VerticalTextAlignment { get; set; }
|
|
||||||
|
|
||||||
public double CharacterSpacing { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,4 @@
|
||||||
using System.Collections;
|
using Xamarin.Forms;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Xamarin.Forms;
|
|
||||||
using Xamarin.Platform;
|
|
||||||
using Xamarin.Platform.Handlers;
|
using Xamarin.Platform.Handlers;
|
||||||
using RegistrarHandlers = Xamarin.Platform.Registrar;
|
using RegistrarHandlers = Xamarin.Platform.Registrar;
|
||||||
|
|
||||||
|
@ -18,23 +15,19 @@ namespace Sample
|
||||||
|
|
||||||
HasInit = true;
|
HasInit = true;
|
||||||
|
|
||||||
//RegistrarHandlers.Handlers.Register<Layout, LayoutHandler>();
|
|
||||||
|
|
||||||
RegistrarHandlers.Handlers.Register<Button, ButtonHandler>();
|
RegistrarHandlers.Handlers.Register<Button, ButtonHandler>();
|
||||||
|
RegistrarHandlers.Handlers.Register<Label, LabelHandler>();
|
||||||
RegistrarHandlers.Handlers.Register<Slider, SliderHandler>();
|
RegistrarHandlers.Handlers.Register<Slider, SliderHandler>();
|
||||||
RegistrarHandlers.Handlers.Register<VerticalStackLayout, LayoutHandler>();
|
RegistrarHandlers.Handlers.Register<VerticalStackLayout, LayoutHandler>();
|
||||||
RegistrarHandlers.Handlers.Register<HorizontalStackLayout, LayoutHandler>();
|
RegistrarHandlers.Handlers.Register<HorizontalStackLayout, LayoutHandler>();
|
||||||
RegistrarHandlers.Handlers.Register<Xamarin.Forms.FlexLayout, LayoutHandler>();
|
RegistrarHandlers.Handlers.Register<FlexLayout, LayoutHandler>();
|
||||||
RegistrarHandlers.Handlers.Register<Xamarin.Forms.StackLayout, LayoutHandler>();
|
RegistrarHandlers.Handlers.Register<Xamarin.Forms.StackLayout, LayoutHandler>();
|
||||||
//RegistrarHandlers.Handlers.Register<Entry, EntryHandler>();
|
|
||||||
RegistrarHandlers.Handlers.Register<Label, LabelHandler>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RegisterLegacyRendererAgainstFormsControl()
|
void RegisterLegacyRendererAgainstFormsControl()
|
||||||
{
|
{
|
||||||
#if MONOANDROID && !NET6_0
|
#if MONOANDROID && !NET6_0
|
||||||
|
|
||||||
// register renderer with old registrar so it can get shimmed
|
// register renderer with old registrar so it can get shimmed
|
||||||
// This will move to some extension method
|
// This will move to some extension method
|
||||||
Xamarin.Forms.Internals.Registrar.Registered.Register(
|
Xamarin.Forms.Internals.Registrar.Registered.Register(
|
||||||
|
@ -44,8 +37,7 @@ namespace Sample
|
||||||
// This registers the shim against the handler registrar
|
// This registers the shim against the handler registrar
|
||||||
// So when the handler.registrar returns the RendererToHandlerShim
|
// So when the handler.registrar returns the RendererToHandlerShim
|
||||||
// Which will then forward the request to the old registrar
|
// Which will then forward the request to the old registrar
|
||||||
Registrar.Handlers.Register<Xamarin.Forms.Button, RendererToHandlerShim>();
|
RegistrarHandlers.Handlers.Register<Xamarin.Forms.Button, RendererToHandlerShim>();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
namespace Xamarin.Platform
|
namespace Xamarin.Platform
|
||||||
{
|
{
|
||||||
public interface IButton : IText
|
public interface IButton : IView, IText
|
||||||
{
|
{
|
||||||
void Pressed();
|
void Pressed();
|
||||||
void Released();
|
void Released();
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace Xamarin.Platform
|
namespace Xamarin.Platform
|
||||||
{
|
{
|
||||||
public interface IFont : IView
|
public interface IFont
|
||||||
{
|
{
|
||||||
FontAttributes FontAttributes { get; }
|
FontAttributes FontAttributes { get; }
|
||||||
string FontFamily { get; }
|
string FontFamily { get; }
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using Xamarin.Forms;
|
||||||
using Xamarin.Forms;
|
|
||||||
|
|
||||||
namespace Xamarin.Platform
|
namespace Xamarin.Platform
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
using System;
|
using Xamarin.Forms;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Xamarin.Platform
|
namespace Xamarin.Platform
|
||||||
{
|
{
|
||||||
public interface ILabel : IText
|
public interface ILabel : IView, IText
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace Xamarin.Platform
|
||||||
|
{
|
||||||
|
public interface IPadding
|
||||||
|
{
|
||||||
|
Thickness Padding { get; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,16 +2,10 @@
|
||||||
|
|
||||||
namespace Xamarin.Platform
|
namespace Xamarin.Platform
|
||||||
{
|
{
|
||||||
public interface IText : IFont, ITextAlignment
|
public interface IText : IFont
|
||||||
{
|
{
|
||||||
string Text { get; }
|
string Text { get; }
|
||||||
|
|
||||||
Color TextColor { get; }
|
Color TextColor { get; }
|
||||||
|
|
||||||
Font Font { get; }
|
|
||||||
|
|
||||||
TextTransform TextTransform { get; }
|
|
||||||
|
|
||||||
double CharacterSpacing { get; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
using Android.Widget;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace Xamarin.Platform.Handlers
|
||||||
|
{
|
||||||
|
public partial class LabelHandler : AbstractViewHandler<ILabel, TextView>
|
||||||
|
{
|
||||||
|
static Color DefaultTextColor { get; set; }
|
||||||
|
|
||||||
|
protected override TextView CreateNativeView() => new TextView(Context);
|
||||||
|
|
||||||
|
protected override void SetupDefaults(TextView nativeView)
|
||||||
|
{
|
||||||
|
if (nativeView.TextColors == null)
|
||||||
|
{
|
||||||
|
DefaultTextColor = Color.Default;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DefaultTextColor = Color.FromUint((uint)nativeView.TextColors.DefaultColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MapText(LabelHandler handler, ILabel label)
|
||||||
|
{
|
||||||
|
ViewHandler.CheckParameters(handler, label);
|
||||||
|
|
||||||
|
handler.TypedNativeView?.UpdateText(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MapTextColor(LabelHandler handler, ILabel label)
|
||||||
|
{
|
||||||
|
ViewHandler.CheckParameters(handler, label);
|
||||||
|
|
||||||
|
handler.TypedNativeView?.UpdateTextColor(label, DefaultTextColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Xamarin.Platform.Handlers
|
||||||
|
{
|
||||||
|
public partial class LabelHandler : AbstractViewHandler<ILabel, object>
|
||||||
|
{
|
||||||
|
protected override object CreateNativeView() => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public static void MapText(IViewHandler handler, ILabel label) { }
|
||||||
|
public static void MapTextColor(IViewHandler handler, ILabel label) { }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,19 +1,6 @@
|
||||||
using System;
|
namespace Xamarin.Platform.Handlers
|
||||||
#if __IOS__
|
|
||||||
using NativeView = UIKit.UILabel;
|
|
||||||
#elif __MACOS__
|
|
||||||
using NativeView = AppKit.NSTextField;
|
|
||||||
#elif MONOANDROID
|
|
||||||
using NativeView = Android.Widget.TextView;
|
|
||||||
#elif NETCOREAPP
|
|
||||||
using NativeView = System.Windows.Controls.TextBlock;
|
|
||||||
#elif NETSTANDARD
|
|
||||||
using NativeView = System.Object;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Xamarin.Platform.Handlers
|
|
||||||
{
|
{
|
||||||
public class LabelHandler : AbstractViewHandler<ILabel, NativeView>
|
public partial class LabelHandler
|
||||||
{
|
{
|
||||||
public static PropertyMapper<ILabel, LabelHandler> LabelMapper = new PropertyMapper<ILabel, LabelHandler>(ViewHandler.ViewMapper)
|
public static PropertyMapper<ILabel, LabelHandler> LabelMapper = new PropertyMapper<ILabel, LabelHandler>(ViewHandler.ViewMapper)
|
||||||
{
|
{
|
||||||
|
@ -21,20 +8,6 @@ namespace Xamarin.Platform.Handlers
|
||||||
[nameof(ILabel.Text)] = MapText,
|
[nameof(ILabel.Text)] = MapText,
|
||||||
};
|
};
|
||||||
|
|
||||||
public static void MapTextColor(LabelHandler handler, ILabel Label)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void MapText(LabelHandler handler, ILabel label)
|
|
||||||
{
|
|
||||||
handler.TypedNativeView?.UpdateText(label);
|
|
||||||
}
|
|
||||||
#if MONOANDROID
|
|
||||||
protected override NativeView CreateNativeView() => new NativeView(this.Context);
|
|
||||||
#else
|
|
||||||
protected override NativeView CreateNativeView() => new NativeView();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public LabelHandler() : base(LabelMapper)
|
public LabelHandler() : base(LabelMapper)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
using UIKit;
|
||||||
|
|
||||||
|
namespace Xamarin.Platform.Handlers
|
||||||
|
{
|
||||||
|
public partial class LabelHandler : AbstractViewHandler<ILabel, UILabel>
|
||||||
|
{
|
||||||
|
protected override UILabel CreateNativeView() => new UILabel();
|
||||||
|
|
||||||
|
public static void MapText(LabelHandler handler, ILabel label)
|
||||||
|
{
|
||||||
|
ViewHandler.CheckParameters(handler, label);
|
||||||
|
|
||||||
|
handler.TypedNativeView?.UpdateText(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MapTextColor(LabelHandler handler, ILabel label)
|
||||||
|
{
|
||||||
|
ViewHandler.CheckParameters(handler, label);
|
||||||
|
|
||||||
|
handler.TypedNativeView?.UpdateTextColor(label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,6 @@
|
||||||
using Android.Content.Res;
|
using Android.Content.Res;
|
||||||
using Android.Graphics;
|
using Android.Graphics;
|
||||||
using Android.OS;
|
|
||||||
using Android.Views;
|
|
||||||
using Android.Widget;
|
using Android.Widget;
|
||||||
using Java.Net;
|
|
||||||
|
|
||||||
namespace Xamarin.Platform.Handlers
|
namespace Xamarin.Platform.Handlers
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
using Android.Content.Res;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using Android.Content.Res;
|
|
||||||
using AndroidX.AppCompat.Widget;
|
using AndroidX.AppCompat.Widget;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,11 @@ namespace Xamarin.Platform
|
||||||
return new ColorStateList(States, new[] { color.ToNative().ToArgb(), disabled });
|
return new ColorStateList(States, new[] { color.ToNative().ToArgb(), disabled });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Color ToColor(this uint color)
|
||||||
|
{
|
||||||
|
return Color.FromUint(color);
|
||||||
|
}
|
||||||
|
|
||||||
public static Color ToColor(this AColor color)
|
public static Color ToColor(this AColor color)
|
||||||
{
|
{
|
||||||
return Color.FromUint((uint)color.ToArgb());
|
return Color.FromUint((uint)color.ToArgb());
|
||||||
|
|
|
@ -4,7 +4,23 @@ namespace Xamarin.Platform
|
||||||
{
|
{
|
||||||
public static class LabelExtensions
|
public static class LabelExtensions
|
||||||
{
|
{
|
||||||
public static void UpdateText(this TextView textView, ILabel label) =>
|
public static void UpdateText(this TextView textView, ILabel label)
|
||||||
|
{
|
||||||
textView.Text = label.Text;
|
textView.Text = label.Text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UpdateTextColor(this TextView textView, ILabel label, Forms.Color defaultColor)
|
||||||
|
{
|
||||||
|
Forms.Color textColor = label.TextColor;
|
||||||
|
|
||||||
|
if (textColor.IsDefault)
|
||||||
|
{
|
||||||
|
textView.SetTextColor(defaultColor.ToNative());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
textView.SetTextColor(textColor.ToNative());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,5 +6,10 @@
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void UpdateTextColor(this object nothing, ILabel label)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,20 +1,27 @@
|
||||||
using System;
|
using UIKit;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using Foundation;
|
|
||||||
using UIKit;
|
|
||||||
|
|
||||||
namespace Xamarin.Platform
|
namespace Xamarin.Platform
|
||||||
{
|
{
|
||||||
public static class LabelExtensions
|
public static class LabelExtensions
|
||||||
{
|
{
|
||||||
public static void UpdateText(this UILabel label, string text)
|
public static void UpdateText(this UILabel nativeLabel, ILabel label)
|
||||||
=> label.Text = text;
|
{
|
||||||
|
nativeLabel.Text = label.Text;
|
||||||
|
}
|
||||||
|
|
||||||
public static void UpdateText(this UILabel label, NSAttributedString text)
|
public static void UpdateTextColor(this UILabel nativeLabel, ILabel label)
|
||||||
=> label.AttributedText = text;
|
{
|
||||||
|
var textColor = label.TextColor;
|
||||||
|
|
||||||
public static void UpdateText(this UILabel label, ILabel text)
|
if (textColor.IsDefault)
|
||||||
=> label.UpdateText(text.Text);
|
{
|
||||||
|
// Default value of color documented to be black in iOS docs
|
||||||
|
nativeLabel.TextColor = textColor.ToNative(ColorExtensions.LabelColor);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nativeLabel.TextColor = textColor.ToNative(textColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Android.Widget;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace Xamarin.Platform.Handlers.DeviceTests
|
||||||
|
{
|
||||||
|
public partial class LabelHandlerTests
|
||||||
|
{
|
||||||
|
TextView GetNativeLabel(LabelHandler labelHandler) =>
|
||||||
|
(TextView)labelHandler.View;
|
||||||
|
|
||||||
|
string GetNativeText(LabelHandler labelHandler) =>
|
||||||
|
GetNativeLabel(labelHandler).Text;
|
||||||
|
|
||||||
|
Color GetNativeTextColor(LabelHandler labelHandler) =>
|
||||||
|
((uint)GetNativeLabel(labelHandler).CurrentTextColor).ToColor();
|
||||||
|
|
||||||
|
Task ValidateNativeBackgroundColor(ILabel label, Color color)
|
||||||
|
{
|
||||||
|
return InvokeOnMainThreadAsync(() =>
|
||||||
|
{
|
||||||
|
GetNativeLabel(CreateHandler(label)).AssertContainsColor(color);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using Xamarin.Platform.Handlers.DeviceTests.Stubs;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Xamarin.Platform.Handlers.DeviceTests
|
||||||
|
{
|
||||||
|
public partial class LabelHandlerTests : HandlerTestBase<LabelHandler>
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task BackgroundColorInitializesCorrectly()
|
||||||
|
{
|
||||||
|
var label = new LabelStub()
|
||||||
|
{
|
||||||
|
BackgroundColor = Color.Blue,
|
||||||
|
Text = "Test"
|
||||||
|
};
|
||||||
|
|
||||||
|
await ValidateNativeBackgroundColor(label, Color.Blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task TextInitializesCorrectly()
|
||||||
|
{
|
||||||
|
var label = new LabelStub()
|
||||||
|
{
|
||||||
|
Text = "Test"
|
||||||
|
};
|
||||||
|
|
||||||
|
await ValidatePropertyInitValue(label, () => label.Text, GetNativeText, label.Text);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task TextColorInitializesCorrectly()
|
||||||
|
{
|
||||||
|
var label = new LabelStub()
|
||||||
|
{
|
||||||
|
Text = "Test",
|
||||||
|
TextColor = Color.Red
|
||||||
|
};
|
||||||
|
|
||||||
|
await ValidatePropertyInitValue(label, () => label.TextColor, GetNativeTextColor, label.TextColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UIKit;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace Xamarin.Platform.Handlers.DeviceTests
|
||||||
|
{
|
||||||
|
public partial class LabelHandlerTests
|
||||||
|
{
|
||||||
|
UILabel GetNativeLabel(LabelHandler labelHandler) =>
|
||||||
|
(UILabel)labelHandler.View;
|
||||||
|
|
||||||
|
string GetNativeText(LabelHandler labelHandler) =>
|
||||||
|
GetNativeLabel(labelHandler).Text;
|
||||||
|
|
||||||
|
Color GetNativeTextColor(LabelHandler labelHandler) =>
|
||||||
|
GetNativeLabel(labelHandler).TextColor.ToColor();
|
||||||
|
|
||||||
|
Task ValidateNativeBackgroundColor(ILabel label, Color color)
|
||||||
|
{
|
||||||
|
return InvokeOnMainThreadAsync(() =>
|
||||||
|
{
|
||||||
|
GetNativeLabel(CreateHandler(label)).AssertContainsColor(color);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,28 +1,26 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Android.Widget;
|
using Android.Widget;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Xamarin.Platform.Handlers.DeviceTests
|
namespace Xamarin.Platform.Handlers.DeviceTests
|
||||||
{
|
{
|
||||||
public partial class SliderHandlerTests
|
public partial class SliderHandlerTests
|
||||||
{
|
{
|
||||||
SeekBar GetSlider(SliderHandler sliderHandler) =>
|
SeekBar GetNativeSlider(SliderHandler sliderHandler) =>
|
||||||
((SeekBar)sliderHandler.View);
|
(SeekBar)sliderHandler.View;
|
||||||
|
|
||||||
double GetNativeProgress(SliderHandler sliderHandler) =>
|
double GetNativeProgress(SliderHandler sliderHandler) =>
|
||||||
GetSlider(sliderHandler).Progress;
|
GetNativeSlider(sliderHandler).Progress;
|
||||||
|
|
||||||
double GetNativeMaximum(SliderHandler sliderHandler) =>
|
double GetNativeMaximum(SliderHandler sliderHandler) =>
|
||||||
GetSlider(sliderHandler).Max;
|
GetNativeSlider(sliderHandler).Max;
|
||||||
|
|
||||||
|
|
||||||
Task ValidateNativeThumbColor(ISlider slider, Color color)
|
Task ValidateNativeThumbColor(ISlider slider, Color color)
|
||||||
{
|
{
|
||||||
return InvokeOnMainThreadAsync(() =>
|
return InvokeOnMainThreadAsync(() =>
|
||||||
{
|
{
|
||||||
GetSlider(CreateHandler(slider)).AssertContainsColor(color);
|
GetNativeSlider(CreateHandler(slider)).AssertContainsColor(color);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,4 @@
|
||||||
using System;
|
using System.Drawing;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xamarin.Platform.Handlers.DeviceTests.Stubs;
|
using Xamarin.Platform.Handlers.DeviceTests.Stubs;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UIKit;
|
using UIKit;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
@ -8,19 +7,18 @@ namespace Xamarin.Platform.Handlers.DeviceTests
|
||||||
{
|
{
|
||||||
public partial class SliderHandlerTests
|
public partial class SliderHandlerTests
|
||||||
{
|
{
|
||||||
UISlider GetSlider(SliderHandler sliderHandler) =>
|
UISlider GetNativeSlider(SliderHandler sliderHandler) =>
|
||||||
((UISlider)sliderHandler.View);
|
(UISlider)sliderHandler.View;
|
||||||
|
|
||||||
double GetNativeProgress(SliderHandler sliderHandler) =>
|
double GetNativeProgress(SliderHandler sliderHandler) =>
|
||||||
GetSlider(sliderHandler).Value;
|
GetNativeSlider(sliderHandler).Value;
|
||||||
|
|
||||||
double GetNativeMaximum(SliderHandler sliderHandler) =>
|
double GetNativeMaximum(SliderHandler sliderHandler) =>
|
||||||
GetSlider(sliderHandler).MaxValue;
|
GetNativeSlider(sliderHandler).MaxValue;
|
||||||
|
|
||||||
|
|
||||||
async Task ValidateNativeThumbColor(ISlider slider, Color color)
|
async Task ValidateNativeThumbColor(ISlider slider, Color color)
|
||||||
{
|
{
|
||||||
var expected = await GetValueAsync(slider, handler => GetSlider(handler).ThumbTintColor.ToColor());
|
var expected = await GetValueAsync(slider, handler => GetNativeSlider(handler).ThumbTintColor.ToColor());
|
||||||
Assert.Equal(expected, color);
|
Assert.Equal(expected, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace Xamarin.Platform.Handlers.DeviceTests.Stubs
|
||||||
|
{
|
||||||
|
public partial class LabelStub : StubBase, ILabel
|
||||||
|
{
|
||||||
|
public string Text { get; set; }
|
||||||
|
|
||||||
|
public Color TextColor { get; set; }
|
||||||
|
|
||||||
|
public FontAttributes FontAttributes => throw new System.NotImplementedException();
|
||||||
|
|
||||||
|
public string FontFamily => throw new System.NotImplementedException();
|
||||||
|
|
||||||
|
public double FontSize => throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,4 @@
|
||||||
using System;
|
using Xamarin.Forms;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using Xamarin.Forms;
|
|
||||||
using Xamarin.Platform;
|
|
||||||
using Xamarin.Platform.Handlers;
|
|
||||||
|
|
||||||
namespace Xamarin.Platform.Handlers.DeviceTests.Stubs
|
namespace Xamarin.Platform.Handlers.DeviceTests.Stubs
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,6 +8,7 @@ using Android.Util;
|
||||||
using Android.Views;
|
using Android.Views;
|
||||||
using Android.Widget;
|
using Android.Widget;
|
||||||
using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
|
using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
|
||||||
|
using Xamarin.Platform;
|
||||||
|
|
||||||
namespace Xamarin.Forms.Platform.Android
|
namespace Xamarin.Forms.Platform.Android
|
||||||
{
|
{
|
||||||
|
@ -181,6 +182,7 @@ namespace Xamarin.Forms.Platform.Android
|
||||||
Control.UpdateFlowDirection(Element);
|
Control.UpdateFlowDirection(Element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[PortHandler]
|
||||||
void UpdateColor()
|
void UpdateColor()
|
||||||
{
|
{
|
||||||
Color c = Element.TextColor;
|
Color c = Element.TextColor;
|
||||||
|
|
|
@ -6,6 +6,7 @@ using Foundation;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using CoreGraphics;
|
using CoreGraphics;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using Xamarin.Platform;
|
||||||
|
|
||||||
#if __MOBILE__
|
#if __MOBILE__
|
||||||
using UIKit;
|
using UIKit;
|
||||||
|
@ -556,6 +557,7 @@ namespace Xamarin.Forms.Platform.MacOS
|
||||||
UpdateLayout();
|
UpdateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[PortHandler]
|
||||||
void UpdateTextColor()
|
void UpdateTextColor()
|
||||||
{
|
{
|
||||||
if (IsTextFormatted)
|
if (IsTextFormatted)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче