2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.ComponentModel;
19 using Tizen.NUI.BaseComponents;
20 using System.Diagnostics.CodeAnalysis;
22 namespace Tizen.NUI.Components
25 /// The DialogPage class is a class which shows a dialog on the page.
26 /// DialogPage contains dialog and dimmed scrim behind the dialog.
28 [EditorBrowsable(EditorBrowsableState.Never)]
29 public class DialogPage : Page
31 private View content = null;
32 private View scrim = null;
33 private bool enableScrim = true;
36 /// Creates a new instance of a DialogPage.
38 [EditorBrowsable(EditorBrowsableState.Never)]
39 public DialogPage() : base()
41 Layout = new AbsoluteLayout();
43 // DialogPage fills to parent by default.
44 WidthResizePolicy = ResizePolicyType.FillToParent;
45 HeightResizePolicy = ResizePolicyType.FillToParent;
47 Scrim = CreateDefaultScrim();
51 /// Dispose DialogPage and all children on it.
53 /// <param name="type">Dispose type.</param>
54 [EditorBrowsable(EditorBrowsableState.Never)]
55 protected override void Dispose(DisposeTypes type)
62 if (type == DisposeTypes.Explicit)
66 Utility.Dispose(content);
71 Utility.Dispose(scrim);
79 /// Content of DialogPage. Content is added to Children automatically.
81 [EditorBrowsable(EditorBrowsableState.Never)]
110 content.RaiseAbove(Scrim);
116 /// Scrim of DialogPage. Scrim is added to Children automatically.
118 [EditorBrowsable(EditorBrowsableState.Never)]
147 Content.RaiseAbove(scrim);
150 if (EnableScrim != Scrim.Visibility)
152 if (EnableScrim == true)
165 /// Indicates to show scrim behind dialog.
167 [EditorBrowsable(EditorBrowsableState.Never)]
168 public bool EnableScrim
176 if (enableScrim == value)
183 if ((Scrim != null) && (enableScrim != Scrim.Visibility))
185 if (enableScrim == true)
198 /// Indicates to dismiss dialog by touching on scrim.
200 [EditorBrowsable(EditorBrowsableState.Never)]
201 public bool EnableDismissOnScrim { get; set; }
203 private View CreateDefaultScrim()
205 //FIXME: Needs to separate GUI implementation codes to style cs file.
206 var scrim = new VisualView();
207 scrim.BackgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.5f);
208 //FIXME: Needs to set proper size to Scrim.
209 scrim.Size = NUIApplication.GetDefaultWindow().Size;
210 scrim.TouchEvent += (object source, TouchEventArgs e) =>
212 if ((EnableDismissOnScrim == true) && (e.Touch.GetState(0) == PointStateType.Up))
214 this.Navigator.Pop();
223 /// Shows a dialog by pushing a dialog page containing dialog to default navigator.
225 /// <param name="content">The content of Dialog.</param>
226 [EditorBrowsable(EditorBrowsableState.Never)]
227 [SuppressMessage("Microsoft.Reliability",
228 "CA2000:DisposeObjectsBeforeLosingScope",
229 Justification = "The pushed views are added to NavigationPages and are disposed in Navigator.Dispose().")]
230 public static void ShowDialog(View content)
232 var dialogPage = new DialogPage()
234 Content = new Dialog()
240 NUIApplication.GetDefaultWindow().GetDefaultNavigator().Push(dialogPage);
244 /// Shows an alert dialog by pushing a page containing the alert dialog
245 /// to default navigator.
247 /// <param name="title">The title of AlertDialog.</param>
248 /// <param name="message">The message of AlertDialog.</param>
249 /// <param name="actions">The action views of AlertDialog.</param>
250 [EditorBrowsable(EditorBrowsableState.Never)]
251 [SuppressMessage("Microsoft.Reliability",
252 "CA2000:DisposeObjectsBeforeLosingScope",
253 Justification = "The pushed views are added to NavigationPages and are disposed in Navigator.Dispose().")]
254 public static void ShowAlertDialog(string title, string message, params View[] actions)
256 var dialogPage = new DialogPage()
258 Content = new AlertDialog()
266 NUIApplication.GetDefaultWindow().GetDefaultNavigator().Push(dialogPage);