diff options
-rw-r--r-- | .nuspec/Xamarin.Forms.Maps.Tizen.nuspec | 2 | ||||
-rw-r--r-- | .nuspec/Xamarin.Forms.Platform.Tizen.nuspec | 2 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.Tizen/Native/EditfieldEntry.cs | 49 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.Tizen/Renderers/DatePickerRenderer.cs | 31 | ||||
-rwxr-xr-x[-rw-r--r--] | Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs | 144 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.Tizen/Renderers/TimePickerRenderer.cs | 35 |
6 files changed, 137 insertions, 126 deletions
diff --git a/.nuspec/Xamarin.Forms.Maps.Tizen.nuspec b/.nuspec/Xamarin.Forms.Maps.Tizen.nuspec index 2277d0b0..7b9b1f2b 100644 --- a/.nuspec/Xamarin.Forms.Maps.Tizen.nuspec +++ b/.nuspec/Xamarin.Forms.Maps.Tizen.nuspec @@ -13,7 +13,7 @@ <description>Xamarin.Forms.Maps Renderer for Tizen .NET</description> <copyright>Copyright 2013-2017</copyright> <dependencies> - <dependency id="Xamarin.Forms.Maps$IdAppend$" version="$version$" /> + <dependency id="Xamarin.Forms.Maps" version="2.3.5.233-pre1" /> <dependency id="ElmSharp" version="1.2.1" /> <dependency id="Tizen.Location" version="1.0.8" /> <dependency id="Tizen.Maps" version="1.0.11" /> diff --git a/.nuspec/Xamarin.Forms.Platform.Tizen.nuspec b/.nuspec/Xamarin.Forms.Platform.Tizen.nuspec index 95d2e3fe..a500ace1 100644 --- a/.nuspec/Xamarin.Forms.Platform.Tizen.nuspec +++ b/.nuspec/Xamarin.Forms.Platform.Tizen.nuspec @@ -13,7 +13,7 @@ <description>Xamarin Forms Renderer to build native UIs for Tizen .NET</description> <copyright>Copyright 2013-2017</copyright> <dependencies> - <dependency id="Xamarin.Forms$IdAppend$" version="$version$" /> + <dependency id="Xamarin.Forms" version="2.3.5.233-pre1" /> <dependency id="ElmSharp" version="1.2.1" /> <dependency id="Tizen.Applications.Common" version="1.5.8" /> <dependency id="Tizen.Applications.UI" version="1.5.8" /> 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<DatePicker, ELayout> + public class DatePickerRenderer : ViewRenderer<DatePicker, Native.EditfieldEntry> { //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/TabbedPageRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs index 34e0235e..d2661197 100644..100755 --- a/Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs +++ b/Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs @@ -6,18 +6,15 @@ using EToolbarItem = ElmSharp.ToolbarItem; using EToolbarItemEventArgs = ElmSharp.ToolbarItemEventArgs; using EColor = ElmSharp.Color; using Xamarin.Forms.PlatformConfiguration.TizenSpecific; -using Xamarin.Forms.Internals; namespace Xamarin.Forms.Platform.Tizen { public class TabbedPageRenderer : VisualElementRenderer<TabbedPage>, IVisualElementRenderer { - Box _outterLayout; - Box _innerBox; - Scroller _scroller; + Box _box; Toolbar _toolbar; + EvasObject _content; Dictionary<EToolbarItem, Page> _itemToItemPage = new Dictionary<EToolbarItem, Page>(); - IReadOnlyCollection<Element> Pages => (Element as IElementController).LogicalChildren; public TabbedPageRenderer() { @@ -25,6 +22,7 @@ namespace Xamarin.Forms.Platform.Tizen RegisterPropertyHandler(TabbedPage.TitleProperty, UpdateTitle); //Register for current page change property RegisterPropertyHandler("CurrentPage", CurrentPageChanged); + //TODO renderer should add item on EFL toolbar when new Page is added to TabbedPage RegisterPropertyHandler(TabbedPage.BarBackgroundColorProperty, UpdateBarBackgroundColor); } @@ -33,7 +31,7 @@ namespace Xamarin.Forms.Platform.Tizen if (_toolbar == null) { //Create box that holds toolbar and selected content - _outterLayout = new Box(Forms.Context.MainWindow) + _box = new Box(Forms.Context.MainWindow) { AlignmentX = -1, AlignmentY = -1, @@ -41,9 +39,9 @@ namespace Xamarin.Forms.Platform.Tizen WeightY = 1, IsHorizontal = false, }; - _outterLayout.Show(); + _box.Show(); - //Create toolbar that is placed inside the _outterLayout + //Create toolbar that is placed inside the _box _toolbar = new Toolbar(Forms.Context.MainWindow) { AlignmentX = -1, @@ -53,91 +51,37 @@ namespace Xamarin.Forms.Platform.Tizen if (Device.Idiom == TargetIdiom.Phone) { - //Set ShrinkMode to Expand as defauly only for Mobile profile + //Set ShrinkMode to Expand as default only for Mobile profile _toolbar.ShrinkMode = ToolbarShrinkMode.Expand; } else if (Device.Idiom == TargetIdiom.TV) { - //According to TV UX Guideline, toolbar style should be set to "tabbar_with_title" in case of TabbedPage only for TV profile. + //According to TV UX Guideleine, toolbar style should be set to "tabbar_with_title" in case of TabbedPage _toolbar.Style = "tabbar_with_title"; } _toolbar.Show(); - //Add callback for Toolbar item selection - _toolbar.Selected += OnToolbarItemSelected; - _outterLayout.PackEnd(_toolbar); + //Add callback for item selection + _toolbar.Selected += OnCurrentPageChanged; + _box.PackEnd(_toolbar); - _scroller = new Scroller(_outterLayout) - { - AlignmentX = -1, - AlignmentY = -1, - WeightX = 1, - WeightY = 1, - HorizontalPageScrollLimit = 1, - ScrollBlock = ScrollBlock.Vertical, - HorizontalScrollBarVisiblePolicy = ScrollBarVisiblePolicy.Invisible - }; - _scroller.SetPageSize(1.0, 1.0); - _scroller.PageScrolled += OnItemPageScrolled; - _scroller.Resized += OnScrollerResized; - - _innerBox = new Box(Forms.Context.MainWindow) - { - AlignmentX = -1, - AlignmentY = -1, - WeightX = 1, - WeightY = 1, - IsHorizontal = true, - }; - _scroller.SetContent(_innerBox); - _scroller.Show(); - - _outterLayout.PackEnd(_scroller); - - SetNativeControl(_outterLayout); + SetNativeControl(_box); UpdateTitle(); } base.OnElementChanged(e); } - void OnScrollerResized(object sender, System.EventArgs e) - { - foreach (var item in _itemToItemPage) - { - var nativeView = Platform.GetRenderer(item.Value).NativeView; - nativeView.MinimumWidth = _scroller.Geometry.Width; - nativeView.MinimumHeight = _scroller.Geometry.Height; - } - int index = Pages.IndexOf(_itemToItemPage[_toolbar.SelectedItem]); - _scroller.ScrollTo(index, 0, true); - } - - void OnItemPageScrolled(object sender, System.EventArgs e) - { - Page newPage = Element.GetPageByIndex(_scroller.HorizontalPageIndex); - foreach (var pair in _itemToItemPage) - { - if (pair.Value == newPage) - { - pair.Key.IsSelected = true; - return; - } - } - - } - protected override void Dispose(bool disposing) { - if (_outterLayout != null) + if (_box != null) { - _outterLayout.Unrealize(); - _outterLayout = null; + _box.Unrealize(); + _box = null; } if (_toolbar != null) { - _toolbar.Selected -= OnToolbarItemSelected; - _scroller.PageScrolled -= OnItemPageScrolled; + _toolbar.Selected -= OnCurrentPageChanged; _toolbar.Unrealize(); _toolbar = null; @@ -147,7 +91,7 @@ namespace Xamarin.Forms.Platform.Tizen protected override void OnElementReady() { - FillToolbarAndContents(); + FillToolbar(); base.OnElementReady(); } @@ -200,53 +144,73 @@ namespace Xamarin.Forms.Platform.Tizen } } - void FillToolbarAndContents() + void FillToolbar() { + var logicalChildren = (Element as IElementController).LogicalChildren; + //add items to toolbar - foreach (Page child in Pages) + foreach (Page child in logicalChildren) { + var childRenderer = Platform.GetRenderer(child); + if (childRenderer != null) + { + childRenderer.NativeView.Hide(); + } + EToolbarItem toolbarItem = _toolbar.Append(child.Title, string.IsNullOrEmpty(child.Icon) ? null : ResourcePath.GetPath(child.Icon)); if (Element.BarBackgroundColor != Color.Default) { toolbarItem.SetPartColor("bg", _toolbar.BackgroundColor); } _itemToItemPage.Add(toolbarItem, child); - - var childContent = Platform.GetOrCreateRenderer(child).NativeView; - _innerBox.PackEnd(childContent); - if (Element.CurrentPage == child) { //select item on the toolbar and fill content toolbarItem.IsSelected = true; + CreateNewPage(); } child.PropertyChanged += OnPageTitleChanged; } } - void OnToolbarItemSelected(object sender, EToolbarItemEventArgs e) + void OnCurrentPageChanged(object sender, EToolbarItemEventArgs e) { if (_toolbar.SelectedItem == null) return; - var oldPage = Element.CurrentPage; - var newPage = _itemToItemPage[_toolbar.SelectedItem]; + var selectedContent = Platform.GetRenderer(_itemToItemPage[e.Item]).NativeView; - if (oldPage == newPage) + if (selectedContent == _content) return; - oldPage?.SendDisappearing(); - - Element.CurrentPage = newPage; - newPage?.SendAppearing(); + //detach content from view without EvasObject changes + if (_content != null) + { + //hide content that should not be visible + _content.Hide(); + //unpack content that is hiden an prepare for new content + _box.UnPack(_content); + Element.CurrentPage?.SendDisappearing(); + } + Element.CurrentPage = _itemToItemPage[_toolbar.SelectedItem]; + CreateNewPage(); + } - int index = MultiPage<Page>.GetIndex(newPage); - _scroller.ScrollTo(index, 0, true); + void CreateNewPage() + { + //create EvasObject using renderer and remember to not destroy + //it for better performance (create once) + _content = Platform.GetOrCreateRenderer(Element.CurrentPage).NativeView; + _content.SetAlignment(-1, -1); + _content.SetWeight(1, 1); + _content.Show(); + _box.PackEnd(_content); + Element.CurrentPage?.SendAppearing(); } void CurrentPageChanged() { - foreach (var pair in _itemToItemPage) + foreach (KeyValuePair<EToolbarItem, Page> pair in _itemToItemPage) { if (pair.Value == Element.CurrentPage) { 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<TimePicker, ELayout> + public class TimePickerRenderer : ViewRenderer<TimePicker, Native.EditfieldEntry> { //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 |