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 // FIXME: To pass touch event when Scrim is disabled.
48 // When proper way to pass touch event is introduced, this code should be fixed.
49 EnableControlState = false;
51 Scrim = CreateDefaultScrim();
55 /// Dispose DialogPage and all children on it.
57 /// <param name="type">Dispose type.</param>
58 [EditorBrowsable(EditorBrowsableState.Never)]
59 protected override void Dispose(DisposeTypes type)
66 if (type == DisposeTypes.Explicit)
70 Utility.Dispose(content);
75 Utility.Dispose(scrim);
83 /// Content of DialogPage. Content is added to Children automatically.
85 [EditorBrowsable(EditorBrowsableState.Never)]
114 content.RaiseAbove(Scrim);
120 /// Scrim of DialogPage. Scrim is added to Children automatically.
122 [EditorBrowsable(EditorBrowsableState.Never)]
151 Content.RaiseAbove(scrim);
154 if (EnableScrim != Scrim.Visibility)
156 if (EnableScrim == true)
169 /// Indicates to show scrim behind dialog.
171 [EditorBrowsable(EditorBrowsableState.Never)]
172 public bool EnableScrim
180 if (enableScrim == value)
187 if ((Scrim != null) && (enableScrim != Scrim.Visibility))
189 if (enableScrim == true)
202 /// Indicates to dismiss dialog by touching on scrim.
204 [EditorBrowsable(EditorBrowsableState.Never)]
205 public bool EnableDismissOnScrim { get; set; } = true;
208 /// The color of scrim.
210 [EditorBrowsable(EditorBrowsableState.Never)]
211 public Color ScrimColor
215 return Scrim?.BackgroundColor;
221 Scrim.BackgroundColor = value;
226 private View CreateDefaultScrim()
228 //FIXME: Needs to separate GUI implementation codes to style cs file.
229 var scrim = new VisualView();
230 scrim.BackgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.5f);
231 //FIXME: Needs to set proper size to Scrim.
232 scrim.Size = NUIApplication.GetDefaultWindow().Size;
233 scrim.TouchEvent += (object source, TouchEventArgs e) =>
235 if ((EnableDismissOnScrim == true) && (e.Touch.GetState(0) == PointStateType.Up))
237 this.Navigator.Pop();
246 /// Shows a dialog by pushing a dialog page containing dialog to default navigator.
248 /// <param name="content">The content of Dialog.</param>
249 [EditorBrowsable(EditorBrowsableState.Never)]
250 [SuppressMessage("Microsoft.Reliability",
251 "CA2000:DisposeObjectsBeforeLosingScope",
252 Justification = "The pushed views are added to NavigationPages and are disposed in Navigator.Dispose().")]
253 public static void ShowDialog(View content)
255 var dialogPage = new DialogPage()
257 Content = new Dialog()
263 NUIApplication.GetDefaultWindow().GetDefaultNavigator().Push(dialogPage);
267 /// Shows an alert dialog by pushing a page containing the alert dialog
268 /// to default navigator.
270 /// <param name="title">The title of AlertDialog.</param>
271 /// <param name="message">The message of AlertDialog.</param>
272 /// <param name="actions">The action views of AlertDialog.</param>
273 [EditorBrowsable(EditorBrowsableState.Never)]
274 [SuppressMessage("Microsoft.Reliability",
275 "CA2000:DisposeObjectsBeforeLosingScope",
276 Justification = "The pushed views are added to NavigationPages and are disposed in Navigator.Dispose().")]
277 public static void ShowAlertDialog(string title, string message, params View[] actions)
279 var dialogPage = new DialogPage()
281 Content = new AlertDialog()
289 NUIApplication.GetDefaultWindow().GetDefaultNavigator().Push(dialogPage);
293 /// Shows a menu by pushing a dialog page containing menu to default navigator.
295 /// <param name="anchor">The anchor view where menu is displayed.</param>
296 /// <param name="items">The menu items.</param>
297 [EditorBrowsable(EditorBrowsableState.Never)]
298 [SuppressMessage("Microsoft.Reliability",
299 "CA2000:DisposeObjectsBeforeLosingScope",
300 Justification = "The pushed views are added to NavigationPages and are disposed in Navigator.Dispose().")]
301 public static void ShowMenu(View anchor, params MenuItem[] items)
308 Position2D anchorPosition = new Position2D((int)(anchor?.ScreenPosition.X ?? 0), (int)(anchor?.ScreenPosition.Y ?? 0) + (anchor?.Size2D.Height ?? 0) + (anchor?.Margin.Bottom ?? 0));
310 var dialogPage = new DialogPage()
315 AnchorPosition = anchorPosition,
317 ScrimColor = Color.Transparent,
320 NUIApplication.GetDefaultWindow().GetDefaultNavigator().Push(dialogPage);
324 /// Shows a menu by pushing a dialog page containing menu to default navigator.
326 /// <param name="anchorPosition">The anchor position where menu is displayed.</param>
327 /// <param name="items">The menu items.</param>
328 [EditorBrowsable(EditorBrowsableState.Never)]
329 [SuppressMessage("Microsoft.Reliability",
330 "CA2000:DisposeObjectsBeforeLosingScope",
331 Justification = "The pushed views are added to NavigationPages and are disposed in Navigator.Dispose().")]
332 public static void ShowMenu(Position2D anchorPosition, params MenuItem[] items)
339 var dialogPage = new DialogPage()
344 AnchorPosition = anchorPosition,
346 ScrimColor = Color.Transparent,
349 NUIApplication.GetDefaultWindow().GetDefaultNavigator().Push(dialogPage);