From 8cb2ca8bfc3fd67494ee19ad71a8f6b84c8b3302 Mon Sep 17 00:00:00 2001 From: Jaehyun Cho Date: Wed, 14 Apr 2021 16:57:19 +0900 Subject: [PATCH] Revert "Revert "[NUI] Dialog and AlertDialog code refactoring with adding DialogPage"" This reverts commit 357f3d0b82bd7a184f02abf6286ebcd1eaddbf6f. --- src/Tizen.NUI.Components/Controls/AlertDialog.cs | 625 +++++++++------------ src/Tizen.NUI.Components/Controls/Dialog.cs | 214 ++----- .../Controls/Navigation/DialogPage.cs | 269 +++++++++ .../Controls/Navigation/Navigator.cs | 114 +--- .../Tizen.NUI.Samples/Samples/AlertDialogSample.cs | 20 +- .../Tizen.NUI.Samples/Samples/DialogSample.cs | 8 +- 6 files changed, 593 insertions(+), 657 deletions(-) create mode 100755 src/Tizen.NUI.Components/Controls/Navigation/DialogPage.cs diff --git a/src/Tizen.NUI.Components/Controls/AlertDialog.cs b/src/Tizen.NUI.Components/Controls/AlertDialog.cs index 6e42b4c..988e95a 100755 --- a/src/Tizen.NUI.Components/Controls/AlertDialog.cs +++ b/src/Tizen.NUI.Components/Controls/AlertDialog.cs @@ -1,5 +1,5 @@ /* - * Copyright(c) 2020 Samsung Electronics Co., Ltd. + * Copyright(c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,154 +17,95 @@ using System; using System.ComponentModel; +using System.Collections.Generic; using Tizen.NUI.BaseComponents; namespace Tizen.NUI.Components { /// - /// Types of the action button of AlertDialog. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public enum AlertDialogActionButtonType - { - /// - /// Type of the positive action button. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - Positive, - - /// - /// Type of the negative action button. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - Negative - } - - /// /// AlertDialog class shows a dialog with title, message and action buttons. /// [EditorBrowsable(EditorBrowsableState.Never)] - public class AlertDialog : Dialog + public class AlertDialog : Control { private string title = null; private string message = null; - private View popupTitle = null; - private View popupContent = null; - private View popupAction = null; + private View titleContent = null; + private View content = null; + private View actionContent = null; + private IEnumerable actionContentViews = null; private View defaultTitleContent = null; private View defaultContent = null; private View defaultActionContent = null; - private Button positiveButton = null; - private Button negativeButton = null; - - /// - /// Creates a new instance of AlertDialog. - /// - /// The title of AlertDialog. - /// The message of AlertDialog. - /// The positive button text in the action content of AlertDialog. - /// The clicked callback of the positive button in the action content of AlertDialog. - /// The negative button text in the action content of AlertDialog. - /// The clicked callback of the negative button in the action content of AlertDialog. - [EditorBrowsable(EditorBrowsableState.Never)] - public AlertDialog(string title, string message, string positiveButtonText, EventHandler positiveButtonClickedHandler, string negativeButtonText = null, EventHandler negativeButtonClickedHandler = null) : base() - { - //Content is initialized to add TitleContent, BodyContent and ActionContent. - //FIXME: Needs to separate GUI implementation codes to style cs file. - InitContent(); - - //Title setter calls TitleContent setter if TitleContent is null. - Title = title; - - //Message setter calls BodyContent setter if BodyContent is null. - Message = message; - - ActionContent = CreateActionContent(positiveButtonText, positiveButtonClickedHandler, negativeButtonText, negativeButtonClickedHandler); - } - - /// - /// Creates a new instance of AlertDialog. - /// - /// The message of AlertDialog. - /// The positive button text in the action content of AlertDialog. - /// The clicked callback of the positive button in the action content of AlertDialog. - /// The negative button text in the action content of AlertDialog. - /// The clicked callback of the negative button in the action content of AlertDialog. - [EditorBrowsable(EditorBrowsableState.Never)] - public AlertDialog(string message, string positiveButtonText, EventHandler positiveButtonClickedHandler, string negativeButtonText = null, EventHandler negativeButtonClickedHandler = null) : this(null, message, positiveButtonText, positiveButtonClickedHandler, negativeButtonText, negativeButtonClickedHandler) - { - } - /// /// Creates a new instance of AlertDialog. /// - /// The title of AlertDialog. - /// The message of AlertDialog. [EditorBrowsable(EditorBrowsableState.Never)] - public AlertDialog(string title, string message) : this(title, message, null, null, null, null) + public AlertDialog() : base() { + Initialize(); } /// - /// Creates a new instance of AlertDialog. - /// - /// The message of AlertDialog. - [EditorBrowsable(EditorBrowsableState.Never)] - public AlertDialog(string message) : this(null, message) - { - } - - /// - /// Creates a new instance of AlertDialog. + /// Dispose AlertDialog and all children on it. /// - /// The title content of AlertDialog. - /// The content of AlertDialog. - /// The action content of AlertDialog. + /// Dispose type. [EditorBrowsable(EditorBrowsableState.Never)] - public AlertDialog(View titleContent, View bodyContent, View actionContent) : base() + protected override void Dispose(DisposeTypes type) { - //Content is initialized to add TitleContent, BodyContent and ActionContent. - //FIXME: Needs to separate GUI implementation codes to style cs file. - InitContent(); + if (disposed) + { + return; + } - TitleContent = titleContent; + if (type == DisposeTypes.Explicit) + { + if (titleContent != null) + { + Utility.Dispose(titleContent); + } - BodyContent = bodyContent; + if (content != null) + { + Utility.Dispose(content); + } - ActionContent = actionContent; - } + if (actionContent != null) + { + Utility.Dispose(actionContent); + } + } - /// - /// Creates a new instance of AlertDialog. - /// - /// The content of AlertDialog. - /// The action content of AlertDialog. - [EditorBrowsable(EditorBrowsableState.Never)] - public AlertDialog(View bodyContent, View actionContent) : this(null, bodyContent, actionContent) - { + base.Dispose(type); } /// - /// Creates a new instance of AlertDialog. + /// Title text of AlertDialog. /// - /// The content of AlertDialog. [EditorBrowsable(EditorBrowsableState.Never)] - public AlertDialog(View bodyContent = null) : this(bodyContent, null) - { - } - - private void InitContent() + public string Title { - var content = new Control(); + get + { + return title; + } + set + { + if (title == value) + { + return; + } - var linearLayout = new LinearLayout(); - linearLayout.LinearOrientation = LinearLayout.Orientation.Vertical; - content.Layout = linearLayout; + title = value; - Content = content; + if (TitleContent is TextLabel textLabel) + { + textLabel.Text = title; + } + } } /// @@ -175,425 +116,369 @@ namespace Tizen.NUI.Components { get { - return popupTitle; + return titleContent; } set { - if (popupTitle == value) + if (titleContent == value) { return; } - if (popupTitle != null) + if (titleContent != null) { - Remove(popupTitle); + Remove(titleContent); } - popupTitle = value; - if (popupTitle == null) + titleContent = value; + if (titleContent == null) { return; } + if (titleContent is TextLabel textLabel) + { + textLabel.Text = Title; + } + ResetContent(); } } /// - /// BodyContent of AlertDialog. BodyContent is added to Children automatically. + /// Message text of AlertDialog. /// [EditorBrowsable(EditorBrowsableState.Never)] - public View BodyContent + public string Message { get { - return popupContent; + return message; } set { - if (popupContent == value) + if (message == value) { return; } - if (popupContent != null) - { - Remove(popupContent); - } + message = value; - popupContent = value; - if (popupContent == null) + if (Content is TextLabel textLabel) { - return; + textLabel.Text = message; } - - ResetContent(); } } /// - /// Action content of AlertDialog. ActionContent is added to Children automatically. + /// Content of AlertDialog. Content is added to Children automatically. /// [EditorBrowsable(EditorBrowsableState.Never)] - public View ActionContent + public View Content { get { - return popupAction; + return content; } set { - if (popupAction == value) + if (content == value) { return; } - if (popupAction != null) + if (content != null) { - Remove(popupAction); + Remove(content); } - popupAction = value; - if (popupAction == null) + content = value; + if (content == null) { return; } - ResetContent(); - } - } - - private void ResetContent() - { - if (Content == null) - { - return; - } - - //To keep the order of TitleContent, BodyContent and ActionContent, - //the existing contents are removed and added again. - if (popupTitle != null) - { - Content.Remove(popupTitle); - } - - if (popupContent != null) - { - Content.Remove(popupContent); - } - - if (popupAction != null) - { - Content.Remove(popupAction); - } - - if (popupTitle != null) - { - Content.Add(popupTitle); - } - - if (popupContent != null) - { - Content.Add(popupContent); - } + if (content is TextLabel textLabel) + { + textLabel.Text = message; + } - if (popupAction != null) - { - Content.Add(popupAction); + ResetContent(); } } /// - /// Title text of AlertDialog. + /// Action views of AlertDialog. + /// Action views are added to ActionContent of AlertDialog. /// [EditorBrowsable(EditorBrowsableState.Never)] - public string Title + public IEnumerable Actions { get { - return title; + return actionContentViews; } set { - if (title == value) + if (ActionContent == null) { + actionContentViews = value; return; } - title = value; - if (title == null) + if (actionContentViews != null) { - if (TitleContent != null) + foreach (var oldAction in actionContentViews) { - //TitleContent setter calls Remove(popupTitle). - TitleContent = null; + if (ActionContent.Children?.Contains(oldAction) == true) + { + ActionContent.Children.Remove(oldAction); + } } } - else + + actionContentViews = value; + + if (actionContentViews == null) { - if (TitleContent == null) - { - TitleContent = CreateTitleContent(title); - } - else if (TitleContent == defaultTitleContent) - { - //Sets text if TitleContent is not set by user. - ((TextLabel)TitleContent).Text = title; - } + return; + } + + foreach (var action in actionContentViews) + { + ActionContent.Add(action); } } } /// - /// Message text of AlertDialog. + /// Action content of AlertDialog. ActionContent is added to Children automatically. /// [EditorBrowsable(EditorBrowsableState.Never)] - public string Message + public View ActionContent { - get - { - return message; - } - set - { - if (message == value) + get + { + return actionContent; + } + set + { + if (actionContent == value) + { + return; + } + + var oldActionContent = actionContent; + actionContent = value; + + // Add views first before remove previous action content + // not to cause Garbage Collector collects views. + if ((actionContent != null) && (Actions != null)) { - return; + foreach (var action in Actions) + { + actionContent.Add(action); + } } - message = value; - if (message == null) + if (oldActionContent != null) { - if (BodyContent != null) - { - //BodyContent setter calls Remove(popupContent). - BodyContent = null; - } + Remove(oldActionContent); } - else + + if (actionContent == null) { - if (BodyContent == null) - { - BodyContent = CreateContent(message); - } - else if (BodyContent == defaultContent) - { - //Sets text if BodyContent is not set by user. - ((TextLabel)BodyContent).Text = message; - } + return; } + + ResetContent(); } } /// - /// Sets action button in the action content of AlertDialog. + /// AccessibilityGetName. /// - /// The type of action button. - /// The text of action button in the action content of AlertDialog. - /// The clicked callback of the action button in the action content of AlertDialog. [EditorBrowsable(EditorBrowsableState.Never)] - public void SetActionButton(AlertDialogActionButtonType type, string text, EventHandler clickedHandler) + protected override string AccessibilityGetName() { - if (ActionContent == null) + if (!String.IsNullOrEmpty(Title)) { - if (type == AlertDialogActionButtonType.Positive) - { - ActionContent = CreateActionContent(text, clickedHandler, null, null); - } - else - { - ActionContent = CreateActionContent(null, null, text, clickedHandler); - } + return Title; } - else if (ActionContent == defaultActionContent) + else { - //To keep the order of negativeButton and positiveButton, - //positiveButton is always removed. - if (positiveButton != null) - { - ActionContent.Remove(positiveButton); - } + return Message; + } + } - if (type == AlertDialogActionButtonType.Negative) + /// + /// Default title content of AlertDialog. + /// If Title is set, then default title content is automatically displayed. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + protected View DefaultTitleContent + { + get + { + if (defaultTitleContent == null) { - if (negativeButton != null) - { - ActionContent.Remove(negativeButton); - } + defaultTitleContent = CreateDefaultTitleContent(); + } - negativeButton = CreateActionButton(text, clickedHandler); - if (negativeButton != null) - { - ActionContent.Add(negativeButton); + return defaultTitleContent; + } + } - if (positiveButton != null) - { - ActionContent.Add(positiveButton); - } - } - } - else + /// + /// Default content of AlertDialog. + /// If Message is set, then default content is automatically displayed. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + protected View DefaultContent + { + get + { + if (defaultContent == null) { - positiveButton = CreateActionButton(text, clickedHandler); - if (positiveButton != null) - { - ActionContent.Add(positiveButton); - } + defaultContent = CreateDefaultContent(); } + + return defaultContent; } } - private TextLabel CreateTitleContent(string text) + /// + /// Default action content of AlertDialog. + /// If Actions are set, then default action content is automatically displayed. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + protected View DefaultActionContent { - if (text == null) + get { - return null; - } - - //FIXME: Needs to separate GUI implementation codes to style cs file. - var titleContent = new TextLabel(text); - titleContent.HorizontalAlignment = HorizontalAlignment.Center; - titleContent.VerticalAlignment = VerticalAlignment.Center; - titleContent.BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); - titleContent.Size = new Size(360, 80); - - defaultTitleContent = titleContent; + if (defaultActionContent == null) + { + defaultActionContent = CreateDefaultActionContent(); + } - return titleContent; + return defaultActionContent; + } } - private TextLabel CreateContent(string message) + private void Initialize() { - if (message == null) + Layout = new LinearLayout() { - return null; - } + LinearOrientation = LinearLayout.Orientation.Vertical, + }; - //FIXME: Needs to separate GUI implementation codes to style cs file. - var messageContent = new TextLabel(message); - messageContent.HorizontalAlignment = HorizontalAlignment.Center; - messageContent.VerticalAlignment = VerticalAlignment.Center; - messageContent.BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); - messageContent.Size = new Size(360, 200); + this.Relayout += OnRelayout; + + TitleContent = DefaultTitleContent; - defaultContent = messageContent; + Content = DefaultContent; - return messageContent; + ActionContent = DefaultActionContent; } - private Button CreateActionButton(string text, EventHandler clickedHandler) + private void ResetContent() { - if (text == null) + //To keep the order of TitleContent, Content and ActionContent, + //the existing contents are removed and added again. + if (titleContent != null) { - return null; + Remove(titleContent); } - //FIXME: Needs to separate GUI implementation codes to style cs file. - var actionButton = new Button(); - actionButton.Text = text; - actionButton.Size = new Size(120, 80); - - if (clickedHandler != null) + if (content != null) { - actionButton.Clicked += clickedHandler; + Remove(content); } - return actionButton; - } - - private View CreateActionContent(string positiveButtonText, EventHandler positiveButtonClickedHandler, string negativeButtonText, EventHandler negativeButtonClickedHandler) - { - if ((negativeButtonText == null) && (positiveButtonText == null)) + if (actionContent != null) { - return null; + Remove(actionContent); } - //FIXME: Needs to separate GUI implementation codes to style cs file. - var actionContent = new Control(); - actionContent.BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); - actionContent.Size = new Size(360, 80); - - //FIXME: Needs to separate GUI implementation codes to style cs file. - var actionLayout = new LinearLayout(); - actionLayout.LinearOrientation = LinearLayout.Orientation.Horizontal; - actionLayout.LinearAlignment = LinearLayout.Alignment.CenterHorizontal; - actionLayout.CellPadding = new Size2D(10, 0); - actionContent.Layout = actionLayout; - - negativeButton = CreateActionButton(negativeButtonText, negativeButtonClickedHandler); - if (negativeButton != null) + if (titleContent != null) { - actionContent.Add(negativeButton); + Add(titleContent); } - positiveButton = CreateActionButton(positiveButtonText, positiveButtonClickedHandler); - if (positiveButton != null) + if (content != null) { - actionContent.Add(positiveButton); + Add(content); } - defaultActionContent = actionContent; - - return actionContent; + if (actionContent != null) + { + Add(actionContent); + } } - /// - /// Dispose AlertDialog and all children on it. - /// - /// Dispose type. - [EditorBrowsable(EditorBrowsableState.Never)] - protected override void Dispose(DisposeTypes type) + private TextLabel CreateDefaultTitleContent() { - if (disposed) + //FIXME: Needs to separate GUI implementation codes to style cs file. + return new TextLabel() { - return; - } + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f), + Size = new Size(360, 80), + }; + } - if (type == DisposeTypes.Explicit) + private TextLabel CreateDefaultContent() + { + //FIXME: Needs to separate GUI implementation codes to style cs file. + return new TextLabel() { - if (popupTitle != null) - { - Utility.Dispose(popupTitle); - } - - if (popupContent != null) - { - Utility.Dispose(popupContent); - } + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f), + Size = new Size(360, 200), + }; + } - if (popupAction != null) + private View CreateDefaultActionContent() + { + //FIXME: Needs to separate GUI implementation codes to style cs file. + return new Control() + { + BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f), + Size = new Size(360, 80), + Layout = new LinearLayout() { - if (positiveButton != null) - { - Utility.Dispose(positiveButton); - } - - if (negativeButton != null) - { - Utility.Dispose(negativeButton); - } - - Utility.Dispose(popupAction); - } - } + LinearOrientation = LinearLayout.Orientation.Horizontal, + LinearAlignment = LinearLayout.Alignment.CenterHorizontal, + CellPadding = new Size2D(10, 0), + }, + }; + } - base.Dispose(type); + private void OnRelayout(object sender, EventArgs e) + { + //FIXME: Needs to separate GUI implementation codes to style cs file. + CalculatePosition(); } - /// - /// AccessibilityGetName. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - protected override string AccessibilityGetName() + private void CalculatePosition() { - if (!String.IsNullOrEmpty(Title)) + var size = Size2D; + var parent = GetParent(); + Size2D parentSize; + + if ((parent != null) && (parent is View)) { - return Title; + parentSize = ((View)parent).Size; } else { - return Message; + parentSize = NUIApplication.GetDefaultWindow().Size; } + + Position2D = new Position2D((parentSize.Width - size.Width) / 2, (parentSize.Height - size.Height) / 2); } } } diff --git a/src/Tizen.NUI.Components/Controls/Dialog.cs b/src/Tizen.NUI.Components/Controls/Dialog.cs index e430044..5abe7eb 100755 --- a/src/Tizen.NUI.Components/Controls/Dialog.cs +++ b/src/Tizen.NUI.Components/Controls/Dialog.cs @@ -1,5 +1,5 @@ /* - * Copyright(c) 2020 Samsung Electronics Co., Ltd. + * Copyright(c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,217 +27,77 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public class Dialog : Control { - private View popupContent = null; - private View scrim = null; - private bool enableScrim = true; + private View content = null; /// /// Creates a new instance of Dialog. /// - /// The content to set to Content of Dialog. [EditorBrowsable(EditorBrowsableState.Never)] - public Dialog(View content = null) : base() + public Dialog() : base() { - EnableScrim = true; - EnableDismissOnScrim = true; + Layout = new AbsoluteLayout(); - //FIXME: Needs to separate GUI implementation codes to style cs file. - var scrim = new VisualView(); - scrim.BackgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.5f); - //FIXME: Needs to set proper size to Scrim. - scrim.Size = NUIApplication.GetDefaultWindow().Size; - scrim.TouchEvent += (object source, TouchEventArgs e) => - { - if ((EnableDismissOnScrim == true) && (e.Touch.GetState(0) == PointStateType.Up)) - { - //TODO: To show hide animation. - this.Hide(); - this.Dispose(); - } - return true; - }; - - Scrim = scrim; - - if (content != null) - { - content.RaiseAbove(scrim); - Content = content; - } + this.Relayout += OnRelayout; } /// - /// Popup content of Dialog. Content is added to Children automatically. + /// Dispose Dialog and all children on it. /// + /// Dispose type. [EditorBrowsable(EditorBrowsableState.Never)] - public View Content - { - get - { - return popupContent; - } - set - { - if (popupContent == value) - { - return; - } - - if (popupContent != null) - { - Remove(popupContent); - } - - popupContent = value; - if (popupContent == null) - { - return; - } - - popupContent.Relayout += PopupContentRelayout; - - //FIXME: Needs to separate GUI implementation codes to style cs file. - CalculateContentPosition(); - - Add(popupContent); - - if (Scrim != null) - { - popupContent.RaiseAbove(Scrim); - } - } - } - - private void PopupContentRelayout(object sender, EventArgs e) - { - //FIXME: Needs to separate GUI implementation codes to style cs file. - CalculateContentPosition(); - } - - private void CalculateContentPosition() + protected override void Dispose(DisposeTypes type) { - var size = popupContent.Size2D; - var parent = GetParent(); - Size2D parentSize; - - if ((parent != null) && (parent is View)) - { - parentSize = ((View)parent).Size; - } - else + if (disposed) { - parentSize = NUIApplication.GetDefaultWindow().Size; + return; } - popupContent.Position2D = new Position2D((parentSize.Width - size.Width) / 2, (parentSize.Height - size.Height) / 2); - } - - /// - /// Indicates to show scrim behind popup content. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool EnableScrim - { - get - { - return enableScrim; - } - set + if (type == DisposeTypes.Explicit) { - if (enableScrim == value) - { - return; - } + this.Relayout -= OnRelayout; - enableScrim = value; - - if ((Scrim != null) && (enableScrim != Scrim.Visibility)) + if (content != null) { - if (enableScrim) - { - Scrim.Show(); - } - else - { - Scrim.Hide(); - } + Utility.Dispose(content); } } - } - /// - /// Indicates to dismiss popup content by touching on scrim. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool EnableDismissOnScrim { get; set; } + base.Dispose(type); + } /// - /// Scrim covers background behind popup content. + /// Popup content of Dialog. Content is added to Children automatically. /// [EditorBrowsable(EditorBrowsableState.Never)] - protected internal View Scrim + public View Content { get { - return scrim; + return content; } set { - if (scrim == value) + if (content == value) { return; } - if (scrim != null) + if (content != null) { - Remove(scrim); + Remove(content); } - scrim = value; - if (scrim == null) + content = value; + if (content == null) { return; } - Add(scrim); - - if (Content != null) - { - Content.RaiseAbove(scrim); - } + Add(content); } } /// - /// Dispose Dialog and all children on it. - /// - /// Dispose type. - [EditorBrowsable(EditorBrowsableState.Never)] - protected override void Dispose(DisposeTypes type) - { - if (disposed) - { - return; - } - - if (type == DisposeTypes.Explicit) - { - if (popupContent != null) - { - popupContent.Relayout -= PopupContentRelayout; - Utility.Dispose(popupContent); - } - - if (scrim != null) - { - Utility.Dispose(scrim); - } - } - - base.Dispose(type); - } - - /// /// Initialize AT-SPI object. /// [EditorBrowsable(EditorBrowsableState.Never)] @@ -259,5 +119,29 @@ namespace Tizen.NUI.Components states.Set(AccessibilityState.Modal, true); return states; } + + private void OnRelayout(object sender, EventArgs e) + { + //FIXME: Needs to separate GUI implementation codes to style cs file. + CalculateContentPosition(); + } + + private void CalculateContentPosition() + { + var size = Size2D; + var parent = GetParent(); + Size2D parentSize; + + if ((parent != null) && (parent is View)) + { + parentSize = ((View)parent).Size; + } + else + { + parentSize = NUIApplication.GetDefaultWindow().Size; + } + + Position2D = new Position2D((parentSize.Width - size.Width) / 2, (parentSize.Height - size.Height) / 2); + } } } diff --git a/src/Tizen.NUI.Components/Controls/Navigation/DialogPage.cs b/src/Tizen.NUI.Components/Controls/Navigation/DialogPage.cs new file mode 100755 index 0000000..268b69f --- /dev/null +++ b/src/Tizen.NUI.Components/Controls/Navigation/DialogPage.cs @@ -0,0 +1,269 @@ +/* + * Copyright(c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using System.ComponentModel; +using Tizen.NUI.BaseComponents; +using System.Diagnostics.CodeAnalysis; + +namespace Tizen.NUI.Components +{ + /// + /// The DialogPage class is a class which shows a dialog on the page. + /// DialogPage contains dialog and dimmed scrim behind the dialog. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class DialogPage : Page + { + private View content = null; + private View scrim = null; + private bool enableScrim = true; + + /// + /// Creates a new instance of a DialogPage. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public DialogPage() : base() + { + Layout = new AbsoluteLayout(); + + // DialogPage fills to parent by default. + WidthResizePolicy = ResizePolicyType.FillToParent; + HeightResizePolicy = ResizePolicyType.FillToParent; + + Scrim = CreateDefaultScrim(); + } + + /// + /// Dispose DialogPage and all children on it. + /// + /// Dispose type. + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void Dispose(DisposeTypes type) + { + if (disposed) + { + return; + } + + if (type == DisposeTypes.Explicit) + { + if (content != null) + { + Utility.Dispose(content); + } + + if (scrim != null) + { + Utility.Dispose(scrim); + } + } + + base.Dispose(type); + } + + /// + /// Content of DialogPage. Content is added to Children automatically. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public View Content + { + get + { + return content; + } + set + { + if (content == value) + { + return; + } + + if (content != null) + { + Remove(content); + } + + content = value; + if (content == null) + { + return; + } + + Add(content); + + if (Scrim != null) + { + content.RaiseAbove(Scrim); + } + } + } + + /// + /// Scrim of DialogPage. Scrim is added to Children automatically. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + protected View Scrim + { + get + { + return scrim; + } + set + { + if (scrim == value) + { + return; + } + + if (scrim != null) + { + Remove(scrim); + } + + scrim = value; + if (scrim == null) + { + return; + } + + Add(scrim); + + if (Content != null) + { + Content.RaiseAbove(scrim); + } + + if (EnableScrim != Scrim.Visibility) + { + if (EnableScrim == true) + { + scrim.Show(); + } + else + { + scrim.Hide(); + } + } + } + } + + /// + /// Indicates to show scrim behind dialog. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public bool EnableScrim + { + get + { + return enableScrim; + } + set + { + if (enableScrim == value) + { + return; + } + + enableScrim = value; + + if ((Scrim != null) && (enableScrim != Scrim.Visibility)) + { + if (enableScrim == true) + { + Scrim.Show(); + } + else + { + Scrim.Hide(); + } + } + } + } + + /// + /// Indicates to dismiss dialog by touching on scrim. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public bool EnableDismissOnScrim { get; set; } + + private View CreateDefaultScrim() + { + //FIXME: Needs to separate GUI implementation codes to style cs file. + var scrim = new VisualView(); + scrim.BackgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.5f); + //FIXME: Needs to set proper size to Scrim. + scrim.Size = NUIApplication.GetDefaultWindow().Size; + scrim.TouchEvent += (object source, TouchEventArgs e) => + { + if ((EnableDismissOnScrim == true) && (e.Touch.GetState(0) == PointStateType.Up)) + { + this.Navigator.Pop(); + } + return true; + }; + + return scrim; + } + + /// + /// Shows a dialog by pushing a dialog page containing dialog to default navigator. + /// + /// The content of Dialog. + [EditorBrowsable(EditorBrowsableState.Never)] + [SuppressMessage("Microsoft.Reliability", + "CA2000:DisposeObjectsBeforeLosingScope", + Justification = "The pushed views are added to NavigationPages and are disposed in Navigator.Dispose().")] + public static void ShowDialog(View content) + { + var dialogPage = new DialogPage() + { + Content = new Dialog() + { + Content = content, + }, + }; + + NUIApplication.GetDefaultWindow().GetDefaultNavigator().Push(dialogPage); + } + + /// + /// Shows an alert dialog by pushing a page containing the alert dialog + /// to default navigator. + /// + /// The title of AlertDialog. + /// The message of AlertDialog. + /// The action views of AlertDialog. + [EditorBrowsable(EditorBrowsableState.Never)] + [SuppressMessage("Microsoft.Reliability", + "CA2000:DisposeObjectsBeforeLosingScope", + Justification = "The pushed views are added to NavigationPages and are disposed in Navigator.Dispose().")] + public static void ShowAlertDialog(string title, string message, params View[] actions) + { + var dialogPage = new DialogPage() + { + Content = new AlertDialog() + { + Title = title, + Message = message, + Actions = actions, + }, + }; + + NUIApplication.GetDefaultWindow().GetDefaultNavigator().Push(dialogPage); + } + } +} diff --git a/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs b/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs index 65105bd..97a4bb1 100755 --- a/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs +++ b/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs @@ -18,8 +18,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; -using Tizen.NUI.BaseComponents; namespace Tizen.NUI.Components { @@ -531,87 +529,6 @@ namespace Tizen.NUI.Components } /// - /// Shows a dialog by pushing a page containing dialog to default navigator. - /// - /// The content of Dialog. - [EditorBrowsable(EditorBrowsableState.Never)] - [SuppressMessage("Microsoft.Reliability", - "CA2000:DisposeObjectsBeforeLosingScope", - Justification = "The pushed views are added to NavigationPages and are disposed in Navigator.Dispose().")] - public static void ShowDialog(View content = null) - { - var window = NUIApplication.GetDefaultWindow(); - var defaultNavigator = window.GetDefaultNavigator(); - - var dialog = new Dialog(content); - SetDialogScrim(dialog); - - // FIXME: Needs to use DialogPage. - var dialogPage = new ContentPage() - { - Content = dialog, - }; - defaultNavigator.Push(dialogPage); - } - - /// - /// Shows an alert dialog by pushing a page containing the alert dialog - /// to default navigator. - /// - /// The title content of AlertDialog. - /// The content of AlertDialog. - /// The action content of AlertDialog. - [EditorBrowsable(EditorBrowsableState.Never)] - [SuppressMessage("Microsoft.Reliability", - "CA2000:DisposeObjectsBeforeLosingScope", - Justification = "The pushed views are added to NavigationPages and are disposed in Navigator.Dispose().")] - public static void ShowAlertDialog(View titleContent, View content, View actionContent) - { - var window = NUIApplication.GetDefaultWindow(); - var defaultNavigator = window.GetDefaultNavigator(); - - var dialog = new AlertDialog(titleContent, content, actionContent); - SetDialogScrim(dialog); - - // FIXME: Needs to use DialogPage. - var dialogPage = new ContentPage() - { - Content = dialog, - }; - defaultNavigator.Push(dialogPage); - } - - /// - /// Shows an alert dialog by pushing a page containing the alert dialog - /// to default navigator. - /// - /// The title of AlertDialog. - /// The message of AlertDialog. - /// The positive button text in the action content of AlertDialog. - /// The clicked callback of the positive button in the action content of AlertDialog. - /// The negative button text in the action content of AlertDialog. - /// The clicked callback of the negative button in the action content of AlertDialog. - [EditorBrowsable(EditorBrowsableState.Never)] - [SuppressMessage("Microsoft.Reliability", - "CA2000:DisposeObjectsBeforeLosingScope", - Justification = "The pushed views are added to NavigationPages and are disposed in Navigator.Dispose().")] - public static void ShowAlertDialog(string title = null, string message = null, string positiveButtonText = null, EventHandler positiveButtonClickedHandler = null, string negativeButtonText = null, EventHandler negativeButtonClickedHandler = null) - { - var window = NUIApplication.GetDefaultWindow(); - var defaultNavigator = window.GetDefaultNavigator(); - - var dialog = new AlertDialog(title, message, positiveButtonText, positiveButtonClickedHandler, negativeButtonText, negativeButtonClickedHandler); - SetDialogScrim(dialog); - - // FIXME: Needs to use DialogPage. - var dialogPage = new ContentPage() - { - Content = dialog, - }; - defaultNavigator.Push(dialogPage); - } - - /// /// Create Transition between currentTopPage and newTopPage /// /// The top page of Navigator. @@ -684,35 +601,6 @@ namespace Tizen.NUI.Components return newTransitionSet; } - private static void SetDialogScrim(Dialog dialog) - { - if (dialog == null) - { - return; - } - - var window = NUIApplication.GetDefaultWindow(); - var defaultNavigator = window.GetDefaultNavigator(); - var defaultScrim = dialog.Scrim; - - //Copies default scrim's GUI properties. - var scrim = new VisualView(); - scrim.BackgroundColor = defaultScrim.BackgroundColor; - scrim.Size = defaultScrim.Size; - scrim.TouchEvent += (object source, View.TouchEventArgs e) => - { - if (e.Touch.GetState(0) == PointStateType.Up) - { - defaultNavigator.Pop(); - } - - return true; - }; - - dialog.Scrim = scrim; - } - - /// /// Retrieve Tagged Views in the view tree. /// @@ -746,4 +634,4 @@ namespace Tizen.NUI.Components TransitionFinished?.Invoke(this, new EventArgs()); } } -} //namespace Tizen.NUI +} diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/AlertDialogSample.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/AlertDialogSample.cs index a29559b..4e1c57c 100755 --- a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/AlertDialogSample.cs +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/AlertDialogSample.cs @@ -20,18 +20,28 @@ namespace Tizen.NUI.Samples HeightResizePolicy = ResizePolicyType.FillToParent }; + var positiveButton = new Button() + { + Text = "Yes", + }; + positiveButton.Clicked += (object sender, ClickedEventArgs e) => { window.GetDefaultNavigator().Pop(); }; + + var negativeButton = new Button() + { + Text = "No", + }; + negativeButton.Clicked += (object sender, ClickedEventArgs e) => { window.GetDefaultNavigator().Pop(); }; + button.Clicked += (object sender, ClickedEventArgs e) => { - Navigator.ShowAlertDialog("Title", "Message", - "Yes", (object sender2, ClickedEventArgs e2) => { window.GetDefaultNavigator().Pop(); }, - "No", (object sender2, ClickedEventArgs e2) => { window.GetDefaultNavigator().Pop(); }); + DialogPage.ShowAlertDialog("Title", "Message", positiveButton, negativeButton); }; - var dialogPage = new ContentPage() + var page = new ContentPage() { Content = button, }; - window.GetDefaultNavigator().Push(dialogPage); + window.GetDefaultNavigator().Push(page); } public void Deactivate() diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/DialogSample.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/DialogSample.cs index 4cc24b6..8d191c1 100755 --- a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/DialogSample.cs +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/DialogSample.cs @@ -27,17 +27,17 @@ namespace Tizen.NUI.Samples BackgroundColor = Color.White, Size = new Size(180, 180), HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Center + VerticalAlignment = VerticalAlignment.Center, }; - Navigator.ShowDialog(textLabel); + DialogPage.ShowDialog(textLabel); }; - var dialogPage = new ContentPage() + var page = new ContentPage() { Content = button, }; - window.GetDefaultNavigator().Push(dialogPage); + window.GetDefaultNavigator().Push(page); } public void Deactivate() -- 2.7.4