Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Tizen] Adds RadioButton #10237

Merged
merged 1 commit into from
Apr 9, 2020
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: 0 additions & 4 deletions Stubs/Xamarin.Forms.Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ internal class _ButtonRenderer { }
[RenderWith(typeof(ImageButtonRenderer))]
internal class _ImageButtonRenderer { }

#if __ANDROID__
[RenderWith(typeof(RadioButtonRenderer))]
#elif !TIZEN4_0
[RenderWith(typeof(RadioButtonRenderer))]
#endif
internal class _RadioButtonRenderer { }

[RenderWith (typeof (TableViewRenderer))]
Expand Down
1 change: 1 addition & 0 deletions Xamarin.Forms.Platform.Tizen/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
[assembly: ExportRenderer(typeof(RefreshView), typeof(RefreshViewRenderer))]
[assembly: ExportRenderer(typeof(MediaElement), typeof(MediaElementRenderer))]
[assembly: ExportRenderer(typeof(IndicatorView), typeof(IndicatorViewRenderer))]
[assembly: ExportRenderer(typeof(RadioButton), typeof(RadioButtonRenderer))]

[assembly: ExportImageSourceHandler(typeof(FileImageSource), typeof(FileImageSourceHandler))]
[assembly: ExportImageSourceHandler(typeof(StreamImageSource), typeof(StreamImageSourceHandler))]
Expand Down
117 changes: 117 additions & 0 deletions Xamarin.Forms.Platform.Tizen/Renderers/RadioButtonRenderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System;
using ElmSharp;
using ESize = ElmSharp.Size;
using TSpan = Xamarin.Forms.Platform.Tizen.Native.Span;

namespace Xamarin.Forms.Platform.Tizen
{
public class RadioButtonRenderer : ViewRenderer<RadioButton, Radio>
{
readonly TSpan _span = new TSpan();
public RadioButtonRenderer()
{
RegisterPropertyHandler(RadioButton.IsCheckedProperty, UpdateIsChecked);
RegisterPropertyHandler(RadioButton.TextProperty, UpdateText);
RegisterPropertyHandler(RadioButton.TextColorProperty, UpdateTextColor);
RegisterPropertyHandler(RadioButton.FontProperty, UpdateFont);
}

protected override void OnElementChanged(ElementChangedEventArgs<RadioButton> e)
{
if (Control == null)
{
SetNativeControl(new Radio(Forms.NativeParent) { StateValue = 1 });
Control.ValueChanged += OnValueChanged;
}
base.OnElementChanged(e);
ApplyTextAndStyle();
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
if (Control != null)
{
Control.ValueChanged -= OnValueChanged;
}
}
base.Dispose(disposing);
}

protected override Size MinimumSize()
{
return Measure(Control.MinimumWidth, Control.MinimumHeight).ToDP();
}

protected override ESize Measure(int availableWidth, int availableHeight)
{
var size = Control.Geometry;
Control.Resize(availableWidth, size.Height);
var formattedSize = Control.EdjeObject["elm.text"].TextBlockFormattedSize;
Control.Resize(size.Width, size.Height);
return new ESize()
{
Width = Control.MinimumWidth + formattedSize.Width,
Height = Math.Max(Control.MinimumHeight, formattedSize.Height),
};
}

void OnValueChanged(object sender, EventArgs e)
{
Element.SetValueFromRenderer(RadioButton.IsCheckedProperty, Control.GroupValue == 1 ? true : false);
}

void UpdateIsChecked()
{
Control.GroupValue = Element.IsChecked ? 1 : 0;
}

void UpdateText(bool isInitialized)
{
_span.Text = Element.Text;
if (!isInitialized)
ApplyTextAndStyle();
}

void UpdateTextColor(bool isInitialized)
{
_span.ForegroundColor = Element.TextColor.ToNative();
if (!isInitialized)
ApplyTextAndStyle();
}

void UpdateFont(bool isInitialized)
{
_span.FontSize = Element.FontSize;
_span.FontAttributes = Element.FontAttributes;
_span.FontFamily = Element.FontFamily;
if (!isInitialized)
ApplyTextAndStyle();
}

void ApplyTextAndStyle()
{
SetInternalTextAndStyle(_span.GetDecoratedText(), _span.GetStyle());
}

void SetInternalTextAndStyle(string formattedText, string textStyle)
{
string emission = "elm,state,text,visible";
if (string.IsNullOrEmpty(formattedText))
{
formattedText = null;
textStyle = null;
emission = "elm,state,text,hidden";
}
Control.Text = formattedText;

var textblock = Control.EdjeObject["elm.text"];
if (textblock != null)
{
textblock.TextStyle = textStyle;
}
Control.EdjeObject.EmitSignal(emission, "elm");
}
}
}
1 change: 1 addition & 0 deletions Xamarin.Forms.Platform.Tizen/StaticRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public static void RegisterHandlers(Dictionary<Type, Func<IRegisterable>> custom
Registered.Register(typeof(RefreshView), () => new RefreshViewRenderer());
Registered.Register(typeof(MediaElement), () => new MediaElementRenderer());
Registered.Register(typeof(IndicatorView), () => new IndicatorViewRenderer());
Registered.Register(typeof(RadioButton), () => new RadioButtonRenderer());

//ImageSourceHandlers
Registered.Register(typeof(FileImageSource), () => new FileImageSourceHandler());
Expand Down