From 214d3926d900c75526c16cffb53339dc9b9bc261 Mon Sep 17 00:00:00 2001 From: Enzo Batista <111511512+Enzo707@users.noreply.github.com> Date: Tue, 6 Jun 2023 18:33:41 -0300 Subject: [PATCH] DYN-5296 setting dynamic height for notification center popup (#14014) * feat:dynamic height for notification center popup * docs(NotificationCenterController): add summary for UpdateNotificationWindowSize() --- .../NotificationCenterController.cs | 30 ++++++++++++++++--- src/Notifications/View/NotificationUI.xaml.cs | 10 +++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/Notifications/NotificationCenterController.cs b/src/Notifications/NotificationCenterController.cs index 2364395c4f8..c3d75669263 100644 --- a/src/Notifications/NotificationCenterController.cs +++ b/src/Notifications/NotificationCenterController.cs @@ -16,6 +16,7 @@ using Dynamo.Wpf.ViewModels.Core; using Newtonsoft.Json; using Microsoft.Web.WebView2.Wpf; +using Dynamo.Utilities; namespace Dynamo.Notifications { @@ -24,16 +25,26 @@ namespace Dynamo.Notifications public class ScriptObject { Action onMarkAllAsRead; + Action onNotificationPopupUpdated; - internal ScriptObject(Action onMarkAllAsRead) + internal ScriptObject(Action onMarkAllAsRead, Action onNotificationPopupUpdated) { this.onMarkAllAsRead = onMarkAllAsRead; + this.onNotificationPopupUpdated = onNotificationPopupUpdated; } public void SetNoficationsAsRead(object[] ids) { onMarkAllAsRead(ids); } + /// + /// This function will be triggered in NotificationCenter side passing the current height it has so we can update popup height in Dynamo + /// + /// + public void UpdateNotificationWindowSize(int height) + { + onNotificationPopupUpdated(height); + } } public class NotificationCenterController @@ -55,6 +66,7 @@ public class NotificationCenterController private readonly DynamoLogger logger; private string jsonStringFile; private NotificationsModel notificationsModel; + private const int PopupMaxHeigth = 598; internal NotificationCenterController(DynamoView view, DynamoLogger dynLogger) { @@ -125,7 +137,7 @@ private void InitializeBrowserAsync() }; } notificationUIPopup.webView.CoreWebView2InitializationCompleted += WebView_CoreWebView2InitializationCompleted; - notificationUIPopup.webView.EnsureCoreWebView2Async(); + notificationUIPopup.webView.EnsureCoreWebView2Async(); } private void WebView_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e) @@ -194,6 +206,16 @@ internal void OnMarkAllAsRead(object[] ids) shortcutToolbarViewModel.NotificationsNumber = 0; } + internal void OnNotificationPopupUpdated(int height) + { + var notificationsViewModel = notificationUIPopup.DataContext as NotificationsUIViewModel; + if(notificationsViewModel != null && height > 0 && height < PopupMaxHeigth) + { + notificationsViewModel.PopupRectangleHeight = height; + } + notificationUIPopup.UpdatePopupSize(); + } + // Handler for new Webview2 tab window request private void WebView_NewWindowRequested(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NewWindowRequestedEventArgs e) { @@ -223,13 +245,13 @@ private void WebView_CoreWebView2InitializationCompleted(object sender, Microsof { // More initialization options // Context menu disabled - notificationUIPopup.webView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false; + notificationUIPopup.webView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = true; // Opening hyper-links using default system browser instead of WebView2 tab window notificationUIPopup.webView.CoreWebView2.NewWindowRequested += WebView_NewWindowRequested; notificationUIPopup.webView.CoreWebView2.NavigateToString(htmlString); // Hosts an object that will expose the properties and methods to be called from the javascript side notificationUIPopup.webView.CoreWebView2.AddHostObjectToScript("scriptObject", - new ScriptObject(OnMarkAllAsRead)); + new ScriptObject(OnMarkAllAsRead, OnNotificationPopupUpdated)); notificationUIPopup.webView.CoreWebView2.Settings.IsZoomControlEnabled = false; } diff --git a/src/Notifications/View/NotificationUI.xaml.cs b/src/Notifications/View/NotificationUI.xaml.cs index ef1a0f411cc..eb7b8c4092a 100644 --- a/src/Notifications/View/NotificationUI.xaml.cs +++ b/src/Notifications/View/NotificationUI.xaml.cs @@ -50,5 +50,15 @@ internal void UpdatePopupLocation() positionMethod.Invoke(this, null); } } + + internal void UpdatePopupSize() + { + BackgroundRectangle.Rect = new Rect(notificationsUIViewModel.PopupBordersOffSet, + notificationsUIViewModel.PopupBordersOffSet, + notificationsUIViewModel.PopupRectangleWidth, + notificationsUIViewModel.PopupRectangleHeight); + + this.Height = notificationsUIViewModel.PopupRectangleHeight + notificationsUIViewModel.PopupBordersOffSet + 10; + } } }