Skip to content

Commit 73ab7ad

Browse files
authored
fix: update notification card widgets (#294)
1 parent 57c7184 commit 73ab7ad

File tree

4 files changed

+14
-37
lines changed

4 files changed

+14
-37
lines changed

samples/Gallery/Pages/NotificationsPage.fs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ module NotificationsPage =
136136

137137
| ShowAsyncCompletedNotification -> model, notifyOneAsync()
138138
| ShowAsyncStatusNotifications -> model, notifyAsyncStatusUpdates()
139-
140139
| ToggleInlinedNotification ->
141140
{ model with
142141
ShowInlined = not model.ShowInlined },
@@ -150,7 +149,7 @@ module NotificationsPage =
150149
(* WindowNotificationManager can't be used immediately after creating it,
151150
so we need to wait for it to be attached to the visual tree.
152151
See https://github.com/AvaloniaUI/Avalonia/issues/5442 *)
153-
| AttachedToVisualTreeChanged args ->
152+
| AttachedToVisualTreeChanged _ ->
154153
{ model with
155154
NotificationManager = FabApplication.Current.WindowNotificationManager },
156155
Cmd.none
@@ -238,24 +237,21 @@ module NotificationsPage =
238237
.isVisible(model.ShowInlined)
239238
.dock(Dock.Top)
240239

241-
//TODO this is always shown - indepedendent of model.ShowInlined. I.e, NotificationCard isClosed flag is not working!
242-
// Demonstrate NotificationCard controlled solely via its IsClosed flag. Avoid .isVisible, which masks the effect.
243-
NotificationCard(not model.ShowInlined, "I was here all along, just hidden!")
244-
//.isVisible(model.ShowInlined) // but if you uncomment this, toggling works!
245-
.size(300., 70.)
246-
.dock(Dock.Top)
247-
.padding(10)
248-
.borderBrush(SolidColorBrush(Colors.Blue))
240+
if model.ShowInlined then
241+
NotificationCard("I was here all along, just hidden!")
242+
.size(300., 70.)
243+
.dock(Dock.Top)
244+
.padding(10)
245+
.borderBrush(SolidColorBrush(Colors.Blue))
249246
}
250247

251248
(* Use the WindowNotificationManager widget to create a NotificationManager
252249
separate from the FabApplication.Current.WindowNotificationManager
253-
allowing you to control e.g. the Position of specific notifications. *)
250+
allowing you to control e.g., the Position of specific notifications. *)
254251
WindowNotificationManager(controlNotificationsRef)
255252
.position(model.NotificationPosition)
256253
.dock(Dock.Top)
257254
.maxItems(3)
258-
259255
})
260256
.onAttachedToVisualTree(AttachedToVisualTreeChanged)
261257
}

src/Fabulous.Avalonia/Views/Controls/Notifications/NotificationCard.Components.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ open Fabulous.Avalonia
88

99
module ComponentNotificationCard =
1010
let NotificationClosed =
11-
Attributes.Component.defineEvent "NotificationCard_NotificationClosed" (fun target -> (target :?> NotificationCard).NotificationClosed)
11+
Attributes.Component.defineRoutedEvent "NotificationCard_NotificationClosed" NotificationCard.NotificationClosedEvent
1212

1313
type ComponentNotificationCardModifiers =
1414
/// <summary>Listens to the NotificationCard NotificationClosed event.</summary>

src/Fabulous.Avalonia/Views/Controls/Notifications/NotificationCard.Mvu.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ open Fabulous.Avalonia
88

99
module MvuNotificationCard =
1010
let NotificationClosed =
11-
Attributes.Mvu.defineEvent "NotificationCard_NotificationClosed" (fun target -> (target :?> NotificationCard).NotificationClosed)
11+
Attributes.Mvu.defineRoutedEvent "NotificationCard_NotificationClosed" NotificationCard.NotificationClosedEvent
1212

1313
type MvuNotificationCardModifiers =
1414
/// <summary>Listens to the NotificationCard NotificationClosed event.</summary>

src/Fabulous.Avalonia/Views/Controls/Notifications/NotificationCard.fs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ namespace Fabulous.Avalonia
33
open System.Runtime.CompilerServices
44
open Avalonia.Controls.Notifications
55
open Fabulous
6-
open Fabulous.StackAllocatedCollections.StackList
76

87
type IFabNotificationCard =
98
inherit IFabContentControl
@@ -14,40 +13,22 @@ module NotificationCard =
1413
let NotificationType =
1514
Attributes.defineAvaloniaPropertyWithEquality NotificationCard.NotificationTypeProperty
1615

17-
let IsClosed =
18-
Attributes.defineAvaloniaPropertyWithEquality NotificationCard.IsClosedProperty
19-
2016
let CloseOnClick =
2117
Attributes.defineAvaloniaPropertyWithEquality NotificationCard.CloseOnClickProperty
2218

23-
2419
[<AutoOpen>]
2520
module NotificationCardBuilders =
2621
type Fabulous.Avalonia.View with
2722

2823
/// <summary>Creates a NotificationCard widget.</summary>
29-
/// <param name="isClosed">Whether the NotificationCard is closed.</param>
3024
/// <param name="content">The content of the NotificationCard.</param>
31-
static member NotificationCard(isClosed: bool, content: WidgetBuilder<'msg, #IFabControl>) =
32-
WidgetBuilder<'msg, IFabNotificationCard>(
33-
NotificationCard.WidgetKey,
34-
AttributesBundle(
35-
StackList.one(NotificationCard.IsClosed.WithValue(isClosed)),
36-
[| ContentControl.ContentWidget.WithValue(content.Compile()) |],
37-
[||],
38-
[||]
39-
)
40-
)
25+
static member NotificationCard(content: WidgetBuilder<'msg, #IFabControl>) =
26+
WidgetBuilder<'msg, IFabNotificationCard>(NotificationCard.WidgetKey, ContentControl.ContentWidget.WithValue(content.Compile()))
4127

4228
/// <summary>Creates a NotificationCard widget.</summary>
43-
/// <param name="isClosed">Whether the NotificationCard is closed.</param>
4429
/// <param name="content">The content of the NotificationCard.</param>
45-
static member NotificationCard(isClosed: bool, content: string) =
46-
WidgetBuilder<'msg, IFabNotificationCard>(
47-
NotificationCard.WidgetKey,
48-
NotificationCard.IsClosed.WithValue(isClosed),
49-
ContentControl.ContentString.WithValue(content)
50-
)
30+
static member NotificationCard(content: string) =
31+
WidgetBuilder<'msg, IFabNotificationCard>(NotificationCard.WidgetKey, ContentControl.ContentString.WithValue(content))
5132

5233
type NotificationCardModifiers =
5334

0 commit comments

Comments
 (0)