From 58052227ac97dc0da89968689e209cdd27cef13a Mon Sep 17 00:00:00 2001 From: zhouleonlei <56956725+zhouleonlei@users.noreply.github.com> Date: Wed, 18 Dec 2019 12:14:35 +0800 Subject: [PATCH] [NUI] Refine Toast and Remove Toast from the Window after hidden (#1199) --- .../Attributes/ToastAttributes.cs | 49 +++----- src/Tizen.NUI.Components/Controls/Toast.cs | 138 +++++---------------- 2 files changed, 45 insertions(+), 142 deletions(-) diff --git a/src/Tizen.NUI.Components/Attributes/ToastAttributes.cs b/src/Tizen.NUI.Components/Attributes/ToastAttributes.cs index ec1ca60..8d47fe9 100755 --- a/src/Tizen.NUI.Components/Attributes/ToastAttributes.cs +++ b/src/Tizen.NUI.Components/Attributes/ToastAttributes.cs @@ -53,40 +53,24 @@ namespace Tizen.NUI.Components } /// - /// Gets or sets background image Style. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public ImageViewStyle Background - { - get; - set; - } - - /// - /// Gets or sets text Style. + /// Gets or sets toast show duration time. /// /// 6 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] - public TextLabelStyle Text + public uint? Duration { get; set; } /// - /// Gets or sets toast show duration time. + /// Text's Style. /// /// 6 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] - public uint? Duration - { - get; - set; - } + public TextLabelStyle Text { get; set; } /// /// Style's clone function. @@ -100,12 +84,7 @@ namespace Tizen.NUI.Components ToastStyle toastStyle = bindableObject as ToastStyle; if (toastStyle != null) { - if (toastStyle.Background!= null) - { - Background.CopyFrom(toastStyle.Background); - } - - if (toastStyle.Text!= null) + if (null != toastStyle.Text) { Text.CopyFrom(toastStyle.Text); } @@ -115,15 +94,17 @@ namespace Tizen.NUI.Components private void InitSubStyle() { - if (Background== null) + Text = new TextLabelStyle() { - Background= new ImageViewStyle(); - } - - if (Text== null) - { - Text= new TextLabelStyle(); - } + PositionUsesPivotPoint = true, + ParentOrigin = Tizen.NUI.ParentOrigin.Center, + PivotPoint = Tizen.NUI.PivotPoint.Center, + WidthResizePolicy = ResizePolicyType.FillToParent, + HeightResizePolicy = ResizePolicyType.FillToParent, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + TextColor = Color.White + }; } } } diff --git a/src/Tizen.NUI.Components/Controls/Toast.cs b/src/Tizen.NUI.Components/Controls/Toast.cs index 56c8a59..b77a349 100755 --- a/src/Tizen.NUI.Components/Controls/Toast.cs +++ b/src/Tizen.NUI.Components/Controls/Toast.cs @@ -37,8 +37,7 @@ namespace Tizen.NUI.Components if (newValue != null) { instance.strText = (string)(newValue); - instance.textLabel.Text = instance.strText; - instance.UpdateText(); + instance.Style.Text.Text = instance.strText; } }, defaultValueCreator: (bindable) => @@ -75,20 +74,10 @@ namespace Tizen.NUI.Components } private Window window = null; - protected TextLabel[] textLabels = null; - - /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - protected TextLabel textLabel = null; - + protected TextLabel[] textLabels = null; + private TextLabel textLabel = null; private string strText = null; - private NPatchVisual toastBackground = null; private Timer timer = null; - private string[] textArray = null; - - private readonly int maxTextAreaWidth = 808; - private readonly int textPaddingLeft = 96; - private readonly int textPaddingTop = 38; private readonly uint duration = 3000; /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -134,23 +123,8 @@ namespace Tizen.NUI.Components /// 6 public string[] TextArray { - get - { - return textArray; - } - set - { - if (null != value) - { - textArray = value; - string message = ""; - foreach (string text in textArray) - { - message += text + "\n"; - } - Message = message; - } - } + get; + set; } /// @@ -237,6 +211,7 @@ namespace Tizen.NUI.Components window.Add(this); this.Position.X = (window.Size.Width - this.Size.Width) / 2; this.Position.Y = (window.Size.Height - this.Size.Height) / 2; + timer.Start(); } /// @@ -269,28 +244,9 @@ namespace Tizen.NUI.Components } set { - if (null != value) + if (null != value && null != Style.Text) { - //CreateTextAttributes(); Style.Text.Padding.CopyFrom(value); - - //if (null == textPadding) - //{ - // textPadding = new Extents((ushort start, ushort end, ushort top, ushort bottom) => - // { - // toastAttributes.TextAttributes.Padding.Start = start; - // toastAttributes.TextAttributes.Padding.End = end; - // toastAttributes.TextAttributes.Padding.Top = top; - // toastAttributes.TextAttributes.Padding.Bottom = bottom; - // RelayoutRequest(); - // }, value.Start, value.End, value.Top, value.Bottom); - //} - //else - //{ - // textPadding.CopyFrom(value); - //} - - //RelayoutRequest(); } } } @@ -323,6 +279,24 @@ namespace Tizen.NUI.Components } } + [EditorBrowsable(EditorBrowsableState.Never)] + public override void ApplyStyle(ViewStyle viewStyle) + { + base.ApplyStyle(viewStyle); + + ToastStyle toastStyle = viewStyle as ToastStyle; + + if (null != toastStyle) + { + if (null == textLabel) + { + textLabel = new TextLabel(); + this.Add(textLabel); + } + textLabel.ApplyStyle(toastStyle.Text); + } + } + /// /// Dispose ToastPopup. /// @@ -355,40 +329,6 @@ namespace Tizen.NUI.Components } /// - /// Relayout control's elements - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - private void UpdateText() - { - if (window == null) - { - //return; - } - - int _textPaddingLeft = Style.Text?.Padding.Start ?? textPaddingLeft; - int _textPaddingRight = Style.Text?.Padding.End ?? _textPaddingLeft; - int _textPaddingTop = Style.Text?.Padding.Top ?? textPaddingTop; - int _textPaddingBottom = Style.Text?.Padding.Bottom ?? _textPaddingTop; - - int _textAreaWidth = (int)Size.Width - _textPaddingLeft - _textPaddingRight; - int _textAreaHeight = (int)Size.Height - _textPaddingTop - _textPaddingBottom; - _textAreaWidth = _textAreaWidth > maxTextAreaWidth ? maxTextAreaWidth : _textAreaWidth; - if (textLabel != null) - { - textLabel.Position = new Position(_textPaddingLeft, _textPaddingTop); - textLabel.Size = new Size(_textAreaWidth, _textAreaHeight); - if (LayoutDirection == ViewLayoutDirectionType.RTL) - { - textLabel.ParentOrigin = Tizen.NUI.ParentOrigin.TopRight; - textLabel.PivotPoint = Tizen.NUI.PivotPoint.TopRight; - textLabel.PositionUsesPivotPoint = true; - } - } - } - - /// /// Get Toast attribues. /// /// 6 @@ -401,25 +341,15 @@ namespace Tizen.NUI.Components private void Initialize() { - toastBackground = new NPatchVisual(); - if (toastBackground == null) - { - throw new Exception("Toast background is null."); - } - SetToastBackground(); - - textLabel = new TextLabel(); if (null == textLabel) { - throw new Exception("Toast textLabel is null."); + textLabel = new TextLabel(); + this.Add(textLabel); } - textLabel.TextColor = Color.White; - this.Add(textLabel); this.VisibilityChanged += OnVisibilityChanged; timer = new Timer(Style.Duration ?? duration); timer.Tick += OnTick; - timer.Start(); } private bool OnTick(object sender, EventArgs e) @@ -432,21 +362,13 @@ namespace Tizen.NUI.Components { if (true == e.Visibility) { + window?.Add(this); timer.Start(); } - } - - private void SetToastBackground() - { - if (null != Style?.Background?.ResourceUrl) - { - toastBackground.URL = Style.Background.ResourceUrl.All; - } - if (null != Style?.Background?.Border) + else { - toastBackground.Border = Style.Background.Border.All; + window?.Remove(this); } - this.Background = toastBackground.OutputVisualMap; } } } -- 2.7.4