[Tizen]Add Material Style Renderers (#6204)

This commit is contained in:
shmin 2019-06-01 10:42:15 +09:00 коммит произвёл Samantha Houts
Родитель 3b6462ba1f
Коммит 6b17b4570f
19 изменённых файлов: 441 добавлений и 135 удалений

Просмотреть файл

@ -28,7 +28,7 @@
</group>
<group targetFramework="tizen40">
<dependency id="Tizen.NET" version="4.0.0"/>
<dependency id="Tizen.NET.MaterialComponents" version="0.9.5-preview"/>
<dependency id="Tizen.NET.MaterialComponents" version="0.9.7-preview"/>
</group>
</dependencies>
</metadata>

Просмотреть файл

@ -11,7 +11,7 @@
<PackageReference Include="Tizen.NET" Version="4.0.0">
<ExcludeAssets>Runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="Tizen.NET.MaterialComponents" Version="0.9.5-preview" />
<PackageReference Include="Tizen.NET.MaterialComponents" Version="0.9.7-preview" />
<PackageReference Include="Tizen.NET.Sdk" Version="1.0.1" />
</ItemGroup>

Просмотреть файл

@ -83,8 +83,8 @@
<Label Text="Image" Margin="0,0,0,-10" />
<StackLayout Orientation="Horizontal">
<Button Image="bank" Text="Enabled" HorizontalOptions="FillAndExpand" />
<Button Image="bank" Text="Disabled" IsEnabled="false" HorizontalOptions="FillAndExpand" />
<Button Image="bank.png" Text="Enabled" HorizontalOptions="FillAndExpand" />
<Button Image="bank.png" Text="Disabled" IsEnabled="false" HorizontalOptions="FillAndExpand" />
</StackLayout>
<Label Text="Custom Background" Margin="0,0,0,-10" />
@ -101,8 +101,8 @@
<Label Text="Custom Text &amp; Image" Margin="0,0,0,-10" />
<StackLayout Orientation="Horizontal">
<Button Image="bank" Text="Enabled" TextColor="{StaticResource LightRedColor}" HorizontalOptions="FillAndExpand" />
<Button Image="bank" Text="Disabled" TextColor="{StaticResource LightRedColor}" IsEnabled="false" HorizontalOptions="FillAndExpand" />
<Button Image="bank.png" Text="Enabled" TextColor="{StaticResource LightRedColor}" HorizontalOptions="FillAndExpand" />
<Button Image="bank.png" Text="Disabled" TextColor="{StaticResource LightRedColor}" IsEnabled="false" HorizontalOptions="FillAndExpand" />
</StackLayout>
<Label Text="Custom Background &amp; Border" Margin="0,0,0,-10" />

Просмотреть файл

@ -0,0 +1,22 @@
using Xamarin.Forms;
using Xamarin.Forms.Platform.Tizen;
using Xamarin.Forms.Material.Tizen;
using Tizen.NET.MaterialComponents;
using TForms = Xamarin.Forms.Platform.Tizen.Forms;
[assembly: ExportRenderer(typeof(ActivityIndicator), typeof(MaterialActivityIndicatorRenderer), new[] { typeof(VisualMarker.MaterialVisual) })]
namespace Xamarin.Forms.Material.Tizen
{
public class MaterialActivityIndicatorRenderer : ActivityIndicatorRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<ActivityIndicator> e)
{
if (Control == null)
{
SetNativeControl(new MActivityIndicator(TForms.NativeParent));
}
base.OnElementChanged(e);
}
}
}

Просмотреть файл

@ -0,0 +1,19 @@
using Xamarin.Forms;
using Xamarin.Forms.Platform.Tizen;
using Xamarin.Forms.Platform.Tizen.Native;
using Xamarin.Forms.Material.Tizen;
using TForms = Xamarin.Forms.Platform.Tizen.Forms;
using XFButton = Xamarin.Forms.Button;
using EButton = ElmSharp.Button;
[assembly: ExportRenderer(typeof(XFButton), typeof(MaterialButtonRenderer), new[] { typeof(VisualMarker.MaterialVisual) })]
namespace Xamarin.Forms.Material.Tizen
{
public class MaterialButtonRenderer : ButtonRenderer
{
protected override EButton CreateNativeControl()
{
return new MaterialButton(TForms.NativeParent);
}
}
}

Просмотреть файл

@ -0,0 +1,33 @@
using Xamarin.Forms;
using Xamarin.Forms.Platform.Tizen;
using Xamarin.Forms.Platform.Tizen.Native;
using Xamarin.Forms.Material.Tizen;
using TForms = Xamarin.Forms.Platform.Tizen.Forms;
using XFEntry = Xamarin.Forms.Entry;
[assembly: ExportRenderer(typeof(XFEntry), typeof(MaterialEntryRenderer), new[] { typeof(VisualMarker.MaterialVisual) })]
namespace Xamarin.Forms.Material.Tizen
{
public class MaterialEntryRenderer : EntryRenderer
{
protected override ElmSharp.Entry CreateNativeControl()
{
return new MaterialEntry(TForms.NativeParent)
{
IsSingleLine = true,
};
}
protected override void UpdateTextColor()
{
if(Control is MaterialEntry me)
{
me.TextColor = Element.TextColor.ToNative();
me.TextFocusedColor = Element.TextColor.ToNative();
me.UnderlineColor = Element.TextColor.ToNative();
me.UnderlineFocusedColor = Element.TextColor.ToNative();
me.CursorColor = Element.TextColor.ToNative();
}
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
using Xamarin.Forms;
using Xamarin.Forms.Platform.Tizen;
using Xamarin.Forms.Platform.Tizen.Native;
using Xamarin.Forms.Material.Tizen;
using Xamarin.Forms.Material.Tizen.Native;
using Tizen.NET.MaterialComponents;
using TForms = Xamarin.Forms.Platform.Tizen.Forms;
@ -20,7 +20,7 @@ namespace Xamarin.Forms.Material.Tizen
{
if (Control == null)
{
SetNativeControl(new MCanvas(TForms.NativeParent));
SetNativeControl(new MaterialCanvas(TForms.NativeParent));
}
base.OnElementChanged(e);
}

Просмотреть файл

@ -9,18 +9,30 @@
<AssemblyName>Xamarin.Forms.Material</AssemblyName>
<OutputType>Library</OutputType>
<PackageId>Xamarin.Forms.Material.Tizen</PackageId>
<DefineConstants>__TIZEN__</DefineConstants>
<DefineConstants>__TIZEN__;__MATERIAL__</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Xamarin.Forms.Material.Android\MaterialColors.cs">
<Link>MaterialColors.cs</Link>
</Compile>
<Compile Include="..\Xamarin.Forms.Platform.Tizen\Native\Canvas.cs">
<Link>Native\Canvas.cs</Link>
</Compile>
<Compile Include="..\Xamarin.Forms.Platform.Tizen\Native\Button.cs">
<Link>Native\Button.cs</Link>
</Compile>
<Compile Include="..\Xamarin.Forms.Platform.Tizen\Native\Box.cs">
<Link>Native\Box.cs</Link>
</Compile>
<Compile Include="..\Xamarin.Forms.Platform.Tizen\Native\Entry.cs">
<Link>Native\Entry.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Tizen.NET" Version="4.0.0" />
<PackageReference Include="Tizen.NET.MaterialComponents" Version="0.9.5-preview" />
<PackageReference Include="Tizen.NET.MaterialComponents" Version="0.9.7-preview" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -1,5 +1,6 @@
using Xamarin.Forms.Internals;
using ElmSharp;
using EEntry = ElmSharp.Entry;
namespace Xamarin.Forms.Platform.Tizen
{
@ -63,18 +64,18 @@ namespace Xamarin.Forms.Platform.Tizen
return isSpellCheckEnabled && isTextPredictionEnabled ? InputHints.AutoComplete : InputHints.None;
}
public static void UpdateKeyboard(this Native.Entry control, Keyboard keyboard, bool isSpellCheckEnabled, bool isTextPredictionEnabled)
public static void UpdateKeyboard(this Native.IEntry control, Keyboard keyboard, bool isSpellCheckEnabled, bool isTextPredictionEnabled)
{
control.Keyboard = keyboard.ToNative();
if (keyboard is CustomKeyboard customKeyboard)
{
control.AutoCapital = customKeyboard.Flags.ToAutoCapital();
(control as EEntry).AutoCapital = customKeyboard.Flags.ToAutoCapital();
}
else
{
control.AutoCapital = AutoCapital.None;
(control as EEntry).AutoCapital = AutoCapital.None;
}
control.InputHint = keyboard.ToInputHints(isSpellCheckEnabled, isTextPredictionEnabled);
(control as EEntry).InputHint = keyboard.ToInputHints(isSpellCheckEnabled, isTextPredictionEnabled);
}
}
}

Просмотреть файл

@ -2,8 +2,20 @@ using System;
using ElmSharp;
using EBox = ElmSharp.Box;
#if __MATERIAL__
using Tizen.NET.MaterialComponents;
#endif
namespace Xamarin.Forms.Platform.Tizen.Native
{
#if __MATERIAL__
public class MaterialBox : MCard
{
public MaterialBox(EvasObject parent) : base(parent)
{
SetLayoutCallback(() => { NotifyOnLayout(); });
}
#else
/// <summary>
/// Extends the ElmSharp.Box class with functionality useful to Xamarin.Forms renderer.
/// </summary>
@ -13,20 +25,17 @@ namespace Xamarin.Forms.Platform.Tizen.Native
/// </remarks>
public class Box : EBox
{
public Box(EvasObject parent) : base(parent)
{
SetLayoutCallback(() => { NotifyOnLayout(); });
}
#endif
/// <summary>
/// The last processed geometry of the Box which was reported from the native layer.
/// </summary>
Rect _previousGeometry;
/// <summary>
/// Initializes a new instance of the <see cref="Xamarin.Forms.Platform.Tizen.Native.Box"/> class.
/// </summary>
/// <param name="parent">The parent EvasObject.</param>
public Box(EvasObject parent) : base(parent)
{
SetLayoutCallback(() => { NotifyOnLayout(); });
}
/// <summary>
/// Notifies that the layout has been updated.
/// </summary>

Просмотреть файл

@ -1,18 +1,37 @@
using System;
using ElmSharp;
using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
using EButton = ElmSharp.Button;
using EColor = ElmSharp.Color;
using ESize = ElmSharp.Size;
using TSButtonStyle = Xamarin.Forms.PlatformConfiguration.TizenSpecific.ButtonStyle;
using EButton = ElmSharp.Button;
#if __MATERIAL__
using Tizen.NET.MaterialComponents;
#endif
namespace Xamarin.Forms.Platform.Tizen.Native
{
#if __MATERIAL__
public class MaterialButton : MButton, IMeasurable, IBatchable, IButton
{
public MaterialButton(EvasObject parent) : base(parent)
{
}
#else
/// <summary>
/// Extends the EButton control, providing basic formatting features,
/// i.e. font color, size, additional image.
/// </summary>
public class Button : EButton, IMeasurable, IBatchable
public class Button : EButton, IMeasurable, IBatchable, IButton
{
/// <summary>
/// Initializes a new instance of the <see cref="Xamarin.Forms.Platform.Tizen.Native.Button"/> class.
/// </summary>
/// <param name="parent">Parent evas object.</param>
public Button(EvasObject parent) : base(parent)
{
}
#endif
/// <summary>
/// Holds the formatted text of the button.
/// </summary>
@ -23,14 +42,6 @@ namespace Xamarin.Forms.Platform.Tizen.Native
/// </summary>
Image _image;
/// <summary>
/// Initializes a new instance of the <see cref="Xamarin.Forms.Platform.Tizen.Native.Button"/> class.
/// </summary>
/// <param name="parent">Parent evas object.</param>
public Button(EvasObject parent) : base(parent)
{
}
/// <summary>
/// Gets or sets the button's text.
/// </summary>
@ -182,7 +193,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
/// </summary>
public virtual ESize Measure(int availableWidth, int availableHeight)
{
if (Style == ButtonStyle.Circle)
if (Style == TSButtonStyle.Circle)
{
return new ESize(MinimumWidth, MinimumHeight);
}
@ -276,7 +287,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
if (Style != style)
{
Style = style;
if (Style == ButtonStyle.Default)
if (Style == TSButtonStyle.Default)
_span.HorizontalTextAlignment = TextAlignment.Auto;
else
_span.HorizontalTextAlignment = TextAlignment.Center;

80
Xamarin.Forms.Platform.Tizen/Native/Canvas.cs Executable file → Normal file
Просмотреть файл

@ -2,8 +2,21 @@
using System.Collections.Specialized;
using ElmSharp;
#if __MATERIAL__
using Tizen.NET.MaterialComponents;
#endif
namespace Xamarin.Forms.Platform.Tizen.Native
{
#if __MATERIAL__
public class MaterialCanvas : MaterialBox, IContainable<EvasObject>
{
public MaterialCanvas(EvasObject parent) : base(parent)
{
Initilize();
}
#else
/// <summary>
/// A Canvas provides a class which can be a container for other controls.
/// </summary>
@ -13,17 +26,50 @@ namespace Xamarin.Forms.Platform.Tizen.Native
/// </remarks>
public class Canvas : Box, IContainable<EvasObject>
{
/// <summary>
/// The list of Views.
/// </summary>
readonly ObservableCollection<EvasObject> _children = new ObservableCollection<EvasObject>();
/// <summary>
/// Initializes a new instance of the <see cref="Xamarin.Forms.Platform.Tizen.Native.Canvas"/> class.
/// </summary>
/// <remarks>Canvas doesn't support replacing its children, this will be ignored.</remarks>
/// <param name="parent">Parent of this instance.</param>
public Canvas(EvasObject parent) : base(parent)
{
Initilize();
}
#endif
/// <summary>
/// The list of Views.
/// </summary>
readonly ObservableCollection<EvasObject> _children = new ObservableCollection<EvasObject>();
/// <summary>
/// Gets list of native elements that are placed in the canvas.
/// </summary>
public new IList<EvasObject> Children
{
get
{
return _children;
}
}
/// <summary>
/// Provides destruction for native element and contained elements.
/// </summary>
protected override void OnUnrealize()
{
foreach (var child in _children)
{
child.Unrealize();
}
base.OnUnrealize();
}
/// <summary>
/// Initializes a new instance of the the class
/// </summary>
void Initilize()
{
_children.CollectionChanged += (o, e) =>
{
@ -56,30 +102,6 @@ namespace Xamarin.Forms.Platform.Tizen.Native
};
}
/// <summary>
/// Gets list of native elements that are placed in the canvas.
/// </summary>
public new IList<EvasObject> Children
{
get
{
return _children;
}
}
/// <summary>
/// Provides destruction for native element and contained elements.
/// </summary>
protected override void OnUnrealize()
{
foreach (var child in _children)
{
child.Unrealize();
}
base.OnUnrealize();
}
/// <summary>
/// Adds a new child to a container.
/// </summary>

Просмотреть файл

@ -4,14 +4,39 @@ using EEntry = ElmSharp.Entry;
using EColor = ElmSharp.Color;
using ESize = ElmSharp.Size;
#if __MATERIAL__
using Tizen.NET.MaterialComponents;
#endif
namespace Xamarin.Forms.Platform.Tizen.Native
{
#if __MATERIAL__
public class MaterialEntry : MTextField, IMeasurable, IBatchable, IEntry
{
const int TextFieldMinimumHeight = 115;
public MaterialEntry(EvasObject parent) : base(parent)
{
Initialize();
}
#else
/// <summary>
/// Extends the Entry control, providing basic formatting features,
/// i.e. font color, size, placeholder.
/// </summary>
public class Entry : EEntry, IMeasurable, IBatchable
public class Entry : EEntry, IMeasurable, IBatchable, IEntry
{
/// <summary>
/// Initializes a new instance of the <see cref="Xamarin.Forms.Platform.Tizen.Native.MaterialEntry"/> class.
/// </summary>
/// <param name="parent">Parent evas object.</param>
public Entry(EvasObject parent) : base(parent)
{
Initialize();
}
#endif
const int VariationNormal = 0;
const int VariationSignedAndDecimal = 3;
@ -36,26 +61,6 @@ namespace Xamarin.Forms.Platform.Tizen.Native
/// </summary>
Keyboard _keyboard;
/// <summary>
/// Initializes a new instance of the <see cref="Xamarin.Forms.Platform.Tizen.Native.Entry"/> class.
/// </summary>
/// <param name="parent">Parent evas object.</param>
public Entry(EvasObject parent) : base(parent)
{
Scrollable = true;
ChangedByUser += (s, e) =>
{
_changedByUserCallbackDepth++;
Text = GetInternalText();
_changedByUserCallbackDepth--;
};
ApplyKeyboard(Keyboard.Normal);
}
/// <summary>
/// Occurs when the text has changed.
/// </summary>
@ -92,7 +97,11 @@ namespace Xamarin.Forms.Platform.Tizen.Native
/// Gets or sets the color of the text.
/// </summary>
/// <value>The color of the text.</value>
#if __MATERIAL__
public new EColor TextColor
#else
public EColor TextColor
#endif
{
get
{
@ -314,8 +323,8 @@ namespace Xamarin.Forms.Platform.Tizen.Native
else
{
// there's text in the entry, use it instead
rawSize = Native.TextHelper.GetRawTextBlockSize(this);
formattedSize = Native.TextHelper.GetFormattedTextBlockSize(this);
rawSize = TextHelper.GetRawTextBlockSize(this);
formattedSize = TextHelper.GetFormattedTextBlockSize(this);
}
// restore the original size
@ -328,21 +337,31 @@ namespace Xamarin.Forms.Platform.Tizen.Native
formattedSize.Height += verticalPadding;
formattedSize.Width += horizontalPadding;
ESize size;
// if the raw text width is larger than available width, we use the available width,
// while height is set to the smallest height value
if (rawSize.Width > availableWidth)
{
return new ESize
{
Width = availableWidth,
Height = Math.Min(formattedSize.Height, Math.Max(rawSize.Height, availableHeight)),
};
size.Width = availableWidth;
size.Height = Math.Min(formattedSize.Height, Math.Max(rawSize.Height, availableHeight));
}
else
{
// width is fine, return the formatted text size
return formattedSize;
size = formattedSize;
}
#if __MATERIAL__
// for adapting material style,
// the height of the entry should be bigger than minimun size defined by Tizen.NET.Material.Components
if (size.Height < TextFieldMinimumHeight)
{
size.Height = TextFieldMinimumHeight;
}
#endif
return size;
}
protected virtual void OnTextChanged(string oldValue, string newValue)
@ -350,6 +369,22 @@ namespace Xamarin.Forms.Platform.Tizen.Native
TextChanged?.Invoke(this, new TextChangedEventArgs(oldValue, newValue));
}
void Initialize()
{
Scrollable = true;
ChangedByUser += (s, e) =>
{
_changedByUserCallbackDepth++;
Text = GetInternalText();
_changedByUserCallbackDepth--;
};
ApplyKeyboard(Keyboard.Normal);
}
void IBatchable.OnBatchCommitted()
{
ApplyTextAndStyle();
@ -386,7 +421,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
/// <returns>The internal text representation.</returns>
string GetInternalText()
{
return Entry.ConvertMarkupToUtf8(base.Text);
return EEntry.ConvertMarkupToUtf8(base.Text);
}
/// <summary>
@ -439,7 +474,11 @@ namespace Xamarin.Forms.Platform.Tizen.Native
/// <param name="markupText">Markup text to be used as a placeholder.</param>
protected virtual void SetInternalPlaceholderAndStyle(string markupText)
{
#if __MATERIAL__
base.Label = markupText;
#else
SetPartText("elm.guide", markupText ?? "");
#endif
}
}
}

Просмотреть файл

@ -0,0 +1,24 @@
using EColor = ElmSharp.Color;
using ESize = ElmSharp.Size;
namespace Xamarin.Forms.Platform.Tizen.Native
{
public interface IButton
{
string Text { get; set; }
double FontSize { get; set; }
FontAttributes FontAttributes { get; set; }
string FontFamily { get; set; }
EColor TextColor { get; set; }
Image Image { get; set; }
ESize Measure(int availableWidth, int availableHeight);
void UpdateStyle(string style);
}
}

Просмотреть файл

@ -0,0 +1,29 @@
using System;
using EColor = ElmSharp.Color;
namespace Xamarin.Forms.Platform.Tizen.Native
{
public interface IEntry
{
double FontSize { get; set; }
FontAttributes FontAttributes { get; set; }
string FontFamily { get; set; }
EColor TextColor { get; set; }
TextAlignment HorizontalTextAlignment { get; set; }
string Placeholder { get; set; }
EColor PlaceholderColor { get; set; }
string FontWeight { get; set; }
Keyboard Keyboard { get; set; }
event EventHandler<TextChangedEventArgs> TextChanged;
}
}

Просмотреть файл

@ -233,7 +233,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
if (LineHeight != -1.0d)
{
_formattingString.Append($"linerelsize={(int)(LineHeight*100)}%");
_formattingString.Append($"linerelsize={(int)(LineHeight * 100)}%");
}
switch (LineBreakMode)

Просмотреть файл

@ -8,7 +8,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
/// <summary>
/// The Text Helper contains functions that assist in working with text-able objects.
/// </summary>
internal static class TextHelper
public static class TextHelper
{
/// <summary>
/// Gets the size of raw text block.

Просмотреть файл

@ -1,9 +1,11 @@
using System;
using Xamarin.Forms.Platform.Tizen.Native;
using EButton = ElmSharp.Button;
using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.VisualElement;
namespace Xamarin.Forms.Platform.Tizen
{
public class ButtonRenderer : ViewRenderer<Button, Native.Button>
public class ButtonRenderer : ViewRenderer<Button, EButton>
{
public ButtonRenderer()
{
@ -22,10 +24,7 @@ namespace Xamarin.Forms.Platform.Tizen
{
if (Control == null)
{
if (Device.Idiom == TargetIdiom.Watch)
SetNativeControl(new Native.Watch.WatchButton(Forms.NativeParent));
else
SetNativeControl(new Native.Button(Forms.NativeParent));
SetNativeControl(CreateNativeControl());
Control.Clicked += OnButtonClicked;
Control.Pressed += OnButtonPressed;
@ -34,9 +33,27 @@ namespace Xamarin.Forms.Platform.Tizen
base.OnElementChanged(e);
}
protected virtual EButton CreateNativeControl()
{
if (Device.Idiom == TargetIdiom.Watch)
return new Native.Watch.WatchButton(Forms.NativeParent);
else
return new Native.Button(Forms.NativeParent);
}
protected override Size MinimumSize()
{
return Control.Measure(Control.MinimumWidth, Control.MinimumHeight).ToDP();
Size measured;
if(Control is IMeasurable im)
{
measured = im.Measure(Control.MinimumWidth, Control.MinimumHeight).ToDP();
}
else
{
measured = base.MinimumSize();
}
return measured;
}
protected override void UpdateThemeStyle()
@ -44,7 +61,7 @@ namespace Xamarin.Forms.Platform.Tizen
var style = Specific.GetStyle(Element);
if (!string.IsNullOrEmpty(style))
{
Control.UpdateStyle(style);
(Control as IButton)?.UpdateStyle(style);
((IVisualElementController)Element).NativeSizeChanged();
}
}
@ -80,40 +97,56 @@ namespace Xamarin.Forms.Platform.Tizen
void UpdateText()
{
Control.Text = Element.Text ?? "";
(Control as IButton).Text = Element.Text ?? "";
}
void UpdateFontSize()
{
Control.FontSize = Element.FontSize;
//(Control as IButton).FontSize = Element.FontSize;
if (Control is IButton ib)
{
ib.FontSize = Element.FontSize;
}
}
void UpdateFontAttributes()
{
Control.FontAttributes = Element.FontAttributes;
if (Control is IButton ib)
{
ib.FontAttributes = Element.FontAttributes;
}
}
void UpdateFontFamily()
{
Control.FontFamily = Element.FontFamily;
if (Control is IButton ib)
{
ib.FontFamily = Element.FontFamily;
}
}
void UpdateTextColor()
{
Control.TextColor = Element.TextColor.ToNative();
if (Control is IButton ib)
{
ib.TextColor = Element.TextColor.ToNative();
}
}
void UpdateBitmap()
{
if (!Element.ImageSource.IsNullOrEmpty())
if (Control is IButton ib)
{
Control.Image = new Native.Image(Control);
_ = Control.Image.LoadFromImageSourceAsync(Element.ImageSource);
}
else
{
Control.Image = null;
}
if (Element.ImageSource != null)
{
ib.Image = new Native.Image(Control);
var task = ib.Image.LoadFromImageSourceAsync(Element.ImageSource);
}
else
{
ib.Image = null;
}
}
}
void UpdateBorder()

Просмотреть файл

@ -1,9 +1,11 @@
using System;
using IEntry = Xamarin.Forms.Platform.Tizen.Native.IEntry;
using EEntry = ElmSharp.Entry;
using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.Entry;
namespace Xamarin.Forms.Platform.Tizen
{
public class EntryRenderer : ViewRenderer<Entry, Native.Entry>
public class EntryRenderer : ViewRenderer<Entry, EEntry>
{
public EntryRenderer()
{
@ -30,30 +32,45 @@ namespace Xamarin.Forms.Platform.Tizen
{
if (Control == null)
{
var entry = new Native.EditfieldEntry(Forms.NativeParent)
{
IsSingleLine = true,
};
var entry = CreateNativeControl();
entry.SetVerticalTextAlignment("elm.text", 0.5);
entry.SetVerticalTextAlignment("elm.guide", 0.5);
entry.TextChanged += OnTextChanged;
entry.Activated += OnCompleted;
entry.CursorChanged += OnCursorChanged;
if (entry is IEntry ie)
{
ie.TextChanged += OnTextChanged;
}
entry.PrependMarkUpFilter(MaxLengthFilter);
SetNativeControl(entry);
}
base.OnElementChanged(e);
}
protected virtual EEntry CreateNativeControl()
{
return new Native.EditfieldEntry(Forms.NativeParent)
{
IsSingleLine = true,
};
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (null != Control)
{
Control.TextChanged -= OnTextChanged;
Control.Activated -= OnCompleted;
Control.CursorChanged -= OnCursorChanged;
if (Control is IEntry ie)
{
ie.TextChanged -= OnTextChanged;
}
}
}
@ -62,7 +79,17 @@ namespace Xamarin.Forms.Platform.Tizen
protected override Size MinimumSize()
{
return (Control as Native.IMeasurable).Measure(Control.MinimumWidth, Control.MinimumHeight).ToDP();
Size measured;
if (Control is Native.IMeasurable im)
{
measured = im.Measure(Control.MinimumWidth, Control.MinimumHeight).ToDP();
}
else
{
measured = base.MinimumSize();
}
return measured;
}
void OnTextChanged(object sender, EventArgs e)
@ -92,36 +119,52 @@ namespace Xamarin.Forms.Platform.Tizen
}
}
void UpdateTextColor()
protected virtual void UpdateTextColor()
{
Control.TextColor = Element.TextColor.ToNative();
if (Control is IEntry ie)
{
ie.TextColor = Element.TextColor.ToNative();
}
}
void UpdateFontSize()
{
Control.FontSize = Element.FontSize;
if (Control is IEntry ie)
{
ie.FontSize = Element.FontSize;
}
}
void UpdateFontFamily()
{
Control.FontFamily = Element.FontFamily;
if (Control is IEntry ie)
{
ie.FontFamily = Element.FontFamily;
}
}
void UpdateFontAttributes()
{
Control.FontAttributes = Element.FontAttributes;
if (Control is IEntry ie)
{
ie.FontAttributes = Element.FontAttributes;
}
}
void UpdateHorizontalTextAlignment()
{
Control.HorizontalTextAlignment = Element.HorizontalTextAlignment.ToNative();
if (Control is IEntry ie)
{
ie.HorizontalTextAlignment = Element.HorizontalTextAlignment.ToNative();
}
}
void UpdateKeyboard(bool initialize)
{
if (initialize && Element.Keyboard == Keyboard.Default)
return;
Control.UpdateKeyboard(Element.Keyboard, Element.IsSpellCheckEnabled, Element.IsTextPredictionEnabled);
(Control as IEntry)?.UpdateKeyboard(Element.Keyboard, Element.IsSpellCheckEnabled, Element.IsTextPredictionEnabled);
}
void UpdateIsSpellCheckEnabled()
@ -131,17 +174,26 @@ namespace Xamarin.Forms.Platform.Tizen
void UpdatePlaceholder()
{
Control.Placeholder = Element.Placeholder;
if (Control is IEntry ie)
{
ie.Placeholder = Element.Placeholder;
}
}
void UpdatePlaceholderColor()
{
Control.PlaceholderColor = Element.PlaceholderColor.ToNative();
if (Control is IEntry ie)
{
ie.PlaceholderColor = Element.PlaceholderColor.ToNative();
}
}
void UpdateFontWeight()
{
Control.FontWeight = Specific.GetFontWeight(Element);
if (Control is IEntry ie)
{
ie.FontWeight = Specific.GetFontWeight(Element);
}
}
void UpdateMaxLength()