summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs127
1 files changed, 127 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs
new file mode 100644
index 00000000..95828c04
--- /dev/null
+++ b/Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs
@@ -0,0 +1,127 @@
+using System;
+using EColor = ElmSharp.Color;
+
+namespace Xamarin.Forms.Platform.Tizen
+{
+ public class EntryRenderer : ViewRenderer<Entry, Native.Entry>, IDisposable
+ {
+ static readonly EColor s_defaultTextColor = EColor.Black;
+
+ static readonly EColor s_defaultPlaceholderColor = EColor.Gray;
+
+ public EntryRenderer()
+ {
+ RegisterPropertyHandler(Entry.IsPasswordProperty, UpdateIsPassword);
+ RegisterPropertyHandler(Entry.TextProperty, UpdateText);
+ RegisterPropertyHandler(Entry.TextColorProperty, UpdateTextColor);
+ RegisterPropertyHandler(Entry.FontSizeProperty, UpdateFontSize);
+ RegisterPropertyHandler(Entry.FontFamilyProperty, UpdateFontFamily);
+ RegisterPropertyHandler(Entry.FontAttributesProperty, UpdateFontAttributes);
+ RegisterPropertyHandler(Entry.HorizontalTextAlignmentProperty, UpdateHorizontalTextAlignment);
+ RegisterPropertyHandler(Entry.KeyboardProperty, UpdateKeyboard);
+ RegisterPropertyHandler(Entry.PlaceholderProperty, UpdatePlaceholder);
+ RegisterPropertyHandler(Entry.PlaceholderColorProperty, UpdatePlaceholderColor);
+ }
+
+ protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
+ {
+ if (Control == null)
+ {
+ var entry = new Native.Entry(Forms.Context.MainWindow)
+ {
+ IsSingleLine = true,
+ PropagateEvents = false,
+ };
+ SetNativeControl(entry);
+ }
+
+ if (e.OldElement != null)
+ {
+ Control.TextChanged -= EntryChangedHandler;
+ Control.Activated -= EntryCompletedHandler;
+ }
+
+ if (e.NewElement != null)
+ {
+ Control.TextChanged += EntryChangedHandler;
+ Control.Activated += EntryCompletedHandler;
+ }
+
+ base.OnElementChanged(e);
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (null != Control)
+ {
+ Control.TextChanged -= EntryChangedHandler;
+ Control.Activated -= EntryCompletedHandler;
+ }
+
+ base.Dispose(disposing);
+ }
+
+ void EntryChangedHandler(object sender, EventArgs e)
+ {
+ Element.Text = Control.Text;
+ }
+
+ void EntryCompletedHandler(object sender, EventArgs e)
+ {
+ //TODO Consider if any other object should overtake focus
+ Control.SetFocus(false);
+
+ ((IEntryController)Element).SendCompleted();
+ }
+
+ void UpdateIsPassword()
+ {
+ Control.IsPassword = Element.IsPassword;
+ }
+
+ void UpdateText()
+ {
+ Control.Text = Element.Text;
+ }
+
+ void UpdateTextColor()
+ {
+ Control.TextColor = Element.TextColor.IsDefault ? s_defaultTextColor : Element.TextColor.ToNative();
+ }
+
+ void UpdateFontSize()
+ {
+ Control.FontSize = Element.FontSize;
+ }
+
+ void UpdateFontFamily()
+ {
+ Control.FontFamily = Element.FontFamily;
+ }
+
+ void UpdateFontAttributes()
+ {
+ Control.FontAttributes = Element.FontAttributes;
+ }
+
+ void UpdateHorizontalTextAlignment()
+ {
+ Control.HorizontalTextAlignment = Element.HorizontalTextAlignment.ToNative();
+ }
+
+ void UpdateKeyboard()
+ {
+ Control.Keyboard = Element.Keyboard.ToNative();
+ }
+
+ void UpdatePlaceholder()
+ {
+ Control.Placeholder = Element.Placeholder;
+ }
+
+ void UpdatePlaceholderColor()
+ {
+ Control.PlaceholderColor = Element.PlaceholderColor.IsDefault ? s_defaultPlaceholderColor : Element.PlaceholderColor.ToNative();
+ }
+ }
+}