From 217712866c28213ec574662eef9a65764577f15f Mon Sep 17 00:00:00 2001 From: darkleem Date: Wed, 21 Jun 2017 15:43:46 +0900 Subject: fix Date/TimePicker crash and handle issue - TASK=TCAP-2529 - editfield style handle issue(opacity, enabled..) Change-Id: Ie07113aa5d1f625a6dcc69492d38c5ca1d98aad1 Signed-off-by: darkleem --- .../Native/EditfieldEntry.cs | 49 ++++++++++++++++++++++ .../Renderers/DatePickerRenderer.cs | 31 +++++++------- .../Renderers/TimePickerRenderer.cs | 35 +++++++--------- 3 files changed, 81 insertions(+), 34 deletions(-) create mode 100644 Xamarin.Forms.Platform.Tizen/Native/EditfieldEntry.cs (limited to 'Xamarin.Forms.Platform.Tizen') diff --git a/Xamarin.Forms.Platform.Tizen/Native/EditfieldEntry.cs b/Xamarin.Forms.Platform.Tizen/Native/EditfieldEntry.cs new file mode 100644 index 00000000..0091d253 --- /dev/null +++ b/Xamarin.Forms.Platform.Tizen/Native/EditfieldEntry.cs @@ -0,0 +1,49 @@ +using ElmSharp; +using System; +using ELayout = ElmSharp.Layout; + +namespace Xamarin.Forms.Platform.Tizen.Native +{ + public class EditfieldEntry : Native.Entry, IMeasurable + { + ELayout _editfieldLayout; + int _heightPadding = 0; + + public EditfieldEntry(EvasObject parent) : base(parent) + { + } + + protected override IntPtr CreateHandle(EvasObject parent) + { + var bg = new ELayout(parent); + bg.SetTheme("layout", "background", "default"); + _editfieldLayout = new ELayout(parent); + _editfieldLayout.SetTheme("layout", "editfield", "singleline"); + + Handle = base.CreateHandle(parent); + _editfieldLayout.SetPartContent("elm.swallow.content", this); + bg.SetPartContent("elm.swallow.content", _editfieldLayout); + + // The minimun size for the Content area of an Editfield. This is used to calculate the size when layouting. + _heightPadding = _editfieldLayout.EdjeObject["elm.swallow.content"].Geometry.Height; + return bg; + } + + public new ElmSharp.Size Measure(int availableWidth, int availableHeight) + { + var textBlockSize = base.Measure(availableWidth, availableHeight); + + // Calculate the minimum size by adding the width of a TextBlock and an Editfield. + textBlockSize.Width += _editfieldLayout.MinimumWidth; + + // If the height of a TextBlock is shorter than Editfield, use the minimun height of the Editfield. + // Or add the height of the EditField to the TextBlock + if (textBlockSize.Height < _editfieldLayout.MinimumHeight) + textBlockSize.Height = _editfieldLayout.MinimumHeight; + else + textBlockSize.Height += _heightPadding; + + return textBlockSize; + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/DatePickerRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/DatePickerRenderer.cs index fefadcc7..2fa86a57 100644 --- a/Xamarin.Forms.Platform.Tizen/Renderers/DatePickerRenderer.cs +++ b/Xamarin.Forms.Platform.Tizen/Renderers/DatePickerRenderer.cs @@ -1,13 +1,11 @@ using System; -using ELayout = ElmSharp.Layout; namespace Xamarin.Forms.Platform.Tizen { - public class DatePickerRenderer : ViewRenderer + public class DatePickerRenderer : ViewRenderer { //TODO need to add internationalization support const string DialogTitle = "Choose Date"; - Native.Entry _realControl = null; public DatePickerRenderer() { @@ -20,31 +18,34 @@ namespace Xamarin.Forms.Platform.Tizen { if (Control == null) { - var layout = new ELayout(Forms.Context.MainWindow); - layout.SetTheme("layout", "editfield", "singleline"); - _realControl = new Native.Entry(layout) + var entry = new Native.EditfieldEntry(Forms.Context.MainWindow) { IsSingleLine = true, HorizontalTextAlignment = Native.TextAlignment.Center, }; - _realControl.AllowFocus(false); - layout.SetPartContent("elm.swallow.content", _realControl); - SetNativeControl(layout); + entry.SetVerticalTextAlignment("elm.text", 0.5); + entry.AllowFocus(false); + SetNativeControl(entry); } if (e.OldElement != null) { - _realControl.Clicked -= ClickedHandler; + Control.Clicked -= ClickedHandler; } if (e.NewElement != null) { - _realControl.Clicked += ClickedHandler; + Control.Clicked += ClickedHandler; } base.OnElementChanged(e); } + protected override Size MinimumSize() + { + return Control.Measure(Control.MinimumWidth, Control.MinimumHeight).ToDP(); + } + void ClickedHandler(object sender, EventArgs e) { Native.DateTimePickerDialog dialog = new Native.DateTimePickerDialog(Forms.Context.MainWindow) @@ -61,7 +62,7 @@ namespace Xamarin.Forms.Platform.Tizen void DialogDateTimeChangedHandler(object sender, Native.DateChangedEventArgs dcea) { Element.Date = dcea.NewDate; - _realControl.Text = dcea.NewDate.ToString(Element.Format); + Control.Text = dcea.NewDate.ToString(Element.Format); } void DialogDismissedHandler(object sender, EventArgs e) @@ -73,12 +74,12 @@ namespace Xamarin.Forms.Platform.Tizen void UpdateDate() { - _realControl.Text = Element.Date.ToString(Element.Format); + Control.Text = Element.Date.ToString(Element.Format); } void UpdateTextColor() { - _realControl.TextColor = Element.TextColor.ToNative(); + Control.TextColor = Element.TextColor.ToNative(); } } -} +} \ No newline at end of file diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/TimePickerRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/TimePickerRenderer.cs index 547f9312..6c517c9d 100644 --- a/Xamarin.Forms.Platform.Tizen/Renderers/TimePickerRenderer.cs +++ b/Xamarin.Forms.Platform.Tizen/Renderers/TimePickerRenderer.cs @@ -1,20 +1,16 @@ using System; using System.Globalization; -using ELayout = ElmSharp.Layout; namespace Xamarin.Forms.Platform.Tizen { - public class TimePickerRenderer : ViewRenderer + public class TimePickerRenderer : ViewRenderer { //TODO need to add internationalization support const string DialogTitle = "Choose Time"; static readonly string s_defaultFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern; - string _format; - TimeSpan _time; - Native.Entry _realControl; public TimePickerRenderer() { @@ -27,35 +23,37 @@ namespace Xamarin.Forms.Platform.Tizen { if (Control == null) { - var layout = new ELayout(Forms.Context.MainWindow); - layout.SetTheme("layout", "editfield", "singleline"); - _realControl = new Native.Entry(layout) + var entry = new Native.EditfieldEntry(Forms.Context.MainWindow) { IsSingleLine = true, HorizontalTextAlignment = Native.TextAlignment.Center, }; - _realControl.AllowFocus(false); - layout.SetPartContent("elm.swallow.content", _realControl); - SetNativeControl(layout); + entry.SetVerticalTextAlignment("elm.text", 0.5); + entry.AllowFocus(false); + SetNativeControl(entry); } if (e.OldElement != null) { - _realControl.Clicked -= ClickedHandler; + Control.Clicked -= ClickedHandler; } if (e.NewElement != null) { _time = DateTime.Now.TimeOfDay; - _format = s_defaultFormat; UpdateTimeAndFormat(); - _realControl.Clicked += ClickedHandler; + Control.Clicked += ClickedHandler; } base.OnElementChanged(e); } + protected override Size MinimumSize() + { + return Control.Measure(Control.MinimumWidth, Control.MinimumHeight).ToDP(); + } + void ClickedHandler(object o, EventArgs e) { Native.DateTimePickerDialog dialog = new Native.DateTimePickerDialog(Forms.Context.MainWindow) @@ -63,7 +61,7 @@ namespace Xamarin.Forms.Platform.Tizen Title = DialogTitle }; - dialog.InitializeTimePicker(_time, _format); + dialog.InitializeTimePicker(_time, null); dialog.DateTimeChanged += DialogDateTimeChangedHandler; dialog.Dismissed += DialogDismissedHandler; dialog.Show(); @@ -84,13 +82,12 @@ namespace Xamarin.Forms.Platform.Tizen void UpdateFormat() { - _format = Element.Format ?? s_defaultFormat; UpdateTimeAndFormat(); } void UpdateTextColor() { - _realControl.TextColor = Element.TextColor.ToNative(); + Control.TextColor = Element.TextColor.ToNative(); } void UpdateTime() @@ -102,7 +99,7 @@ namespace Xamarin.Forms.Platform.Tizen void UpdateTimeAndFormat() { // Xamarin using DateTime formatting (https://developer.xamarin.com/api/property/Xamarin.Forms.TimePicker.Format/) - _realControl.Text = new DateTime(_time.Ticks).ToString(_format); + Control.Text = new DateTime(_time.Ticks).ToString(Element.Format ?? s_defaultFormat); } } -} +} \ No newline at end of file -- cgit v1.2.3