Skip to content

Commit cdf0d09

Browse files
committed
remove locks
1 parent 76032fe commit cdf0d09

File tree

6 files changed

+396
-312
lines changed

6 files changed

+396
-312
lines changed

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationXaml.bind

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@
153153
<ColumnDefinition Width="Auto" />
154154
</Grid.ColumnDefinitions>
155155

156-
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
156+
<ContentPresenter x:Name="PART_Presenter"
157+
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
157158
HorizontalContentAlignment="Stretch"
158159
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
159160
VerticalContentAlignment="Center"
@@ -333,7 +334,8 @@
333334
<ColumnDefinition Width="Auto" />
334335
</Grid.ColumnDefinitions>
335336

336-
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
337+
<ContentPresenter x:Name="PART_Presenter"
338+
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
337339
HorizontalContentAlignment="Stretch"
338340
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
339341
VerticalContentAlignment="Center"

Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.Constants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,10 @@ public partial class InAppNotification
2828
/// Key of the UI Element that dismiss the control
2929
/// </summary>
3030
private const string DismissButtonPart = "PART_DismissButton";
31+
32+
/// <summary>
33+
/// Key of the UI Element that will display the notification content.
34+
/// </summary>
35+
private const string ContentPresenterPart = "PART_Presenter";
3136
}
3237
}

Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.Events.cs

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ public partial class InAppNotification
3535
/// </summary>
3636
public event InAppNotificationClosedEventHandler Closed;
3737

38+
private static void AutomateTextNotification(AutomationPeer peer, string message)
39+
{
40+
if (peer != null)
41+
{
42+
peer.SetFocus();
43+
peer.RaiseNotificationEvent(
44+
AutomationNotificationKind.Other,
45+
AutomationNotificationProcessing.ImportantMostRecent,
46+
StringExtensions.GetLocalized("WindowsCommunityToolkit_InAppNotification_Events_NewNotificationMessage", "/Microsoft.Toolkit.Uwp.UI.Controls/Resources") + message,
47+
Guid.NewGuid().ToString());
48+
}
49+
}
50+
3851
private void DismissButton_Click(object sender, RoutedEventArgs e)
3952
{
4053
Dismiss(InAppNotificationDismissKind.User);
@@ -45,44 +58,37 @@ private void DismissTimer_Tick(object sender, object e)
4558
Dismiss(InAppNotificationDismissKind.Timeout);
4659
}
4760

48-
private void OpenAnimationTimer_Tick(object sender, object e)
61+
private void OnCurrentStateChanged(object sender, VisualStateChangedEventArgs e)
4962
{
50-
lock (_openAnimationTimer)
63+
switch (e.NewState.Name)
5164
{
52-
_openAnimationTimer.Stop();
53-
Opened?.Invoke(this, EventArgs.Empty);
54-
SetValue(AutomationProperties.NameProperty, StringExtensions.GetLocalized("WindowsCommunityToolkit_InAppNotification_NameProperty", "/Microsoft.Toolkit.Uwp.UI.Controls/Resources"));
55-
if (ContentTemplateRoot != null)
56-
{
57-
var peer = FrameworkElementAutomationPeer.CreatePeerForElement(ContentTemplateRoot);
58-
if (Content?.GetType() == typeof(string))
59-
{
60-
AutomateTextNotification(peer, Content.ToString());
61-
}
62-
}
65+
case StateContentVisible:
66+
OnNotificationVisible();
67+
break;
68+
case StateContentCollapsed:
69+
OnNotificationCollapsed();
70+
break;
6371
}
6472
}
6573

66-
private void AutomateTextNotification(AutomationPeer peer, string message)
74+
private void OnNotificationVisible()
6775
{
68-
if (peer != null)
76+
Opened?.Invoke(this, EventArgs.Empty);
77+
SetValue(AutomationProperties.NameProperty, StringExtensions.GetLocalized("WindowsCommunityToolkit_InAppNotification_NameProperty", "/Microsoft.Toolkit.Uwp.UI.Controls/Resources"));
78+
if (ContentTemplateRoot != null)
6979
{
70-
peer.SetFocus();
71-
peer.RaiseNotificationEvent(
72-
AutomationNotificationKind.Other,
73-
AutomationNotificationProcessing.ImportantMostRecent,
74-
StringExtensions.GetLocalized("WindowsCommunityToolkit_InAppNotification_Events_NewNotificationMessage", "/Microsoft.Toolkit.Uwp.UI.Controls/Resources") + message,
75-
Guid.NewGuid().ToString());
80+
var peer = FrameworkElementAutomationPeer.CreatePeerForElement(ContentTemplateRoot);
81+
if (Content?.GetType() == typeof(string))
82+
{
83+
AutomateTextNotification(peer, Content.ToString());
84+
}
7685
}
7786
}
7887

79-
private void ClosingAnimationTimer_Tick(object sender, object e)
88+
private void OnNotificationCollapsed()
8089
{
81-
lock (_closingAnimationTimer)
82-
{
83-
_closingAnimationTimer.Stop();
84-
Closed?.Invoke(this, new InAppNotificationClosedEventArgs(_lastDismissKind));
85-
}
90+
Closed?.Invoke(this, new InAppNotificationClosedEventArgs(_lastDismissKind));
91+
Visibility = Visibility.Collapsed;
8692
}
8793
}
8894
}

0 commit comments

Comments
 (0)