Skip to content

Commit

Permalink
DYN-5296 setting dynamic height for notification center popup (#14014)
Browse files Browse the repository at this point in the history
* feat:dynamic height for notification center popup

* docs(NotificationCenterController): add summary for UpdateNotificationWindowSize()
  • Loading branch information
Enzo707 authored Jun 6, 2023
1 parent af4c57c commit 214d392
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/Notifications/NotificationCenterController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Dynamo.Wpf.ViewModels.Core;
using Newtonsoft.Json;
using Microsoft.Web.WebView2.Wpf;
using Dynamo.Utilities;

namespace Dynamo.Notifications
{
Expand All @@ -24,16 +25,26 @@ namespace Dynamo.Notifications
public class ScriptObject
{
Action<object[]> onMarkAllAsRead;
Action<int> onNotificationPopupUpdated;

internal ScriptObject(Action<object []> onMarkAllAsRead)
internal ScriptObject(Action<object []> onMarkAllAsRead, Action<int> onNotificationPopupUpdated)
{
this.onMarkAllAsRead = onMarkAllAsRead;
this.onNotificationPopupUpdated = onNotificationPopupUpdated;
}

public void SetNoficationsAsRead(object[] ids)
{
onMarkAllAsRead(ids);
}
/// <summary>
/// This function will be triggered in NotificationCenter side passing the current height it has so we can update popup height in Dynamo
/// </summary>
/// <param name="height"></param>
public void UpdateNotificationWindowSize(int height)
{
onNotificationPopupUpdated(height);
}
}

public class NotificationCenterController
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions src/Notifications/View/NotificationUI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit 214d392

Please sign in to comment.