-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(InAppNotifications): improve control #1441
feat(InAppNotifications): improve control #1441
Conversation
/// <summary> | ||
/// When user explicitly dismissed the notification. | ||
/// </summary> | ||
User = 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why this is 1,2 rather than 0,1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied the behavior of ActivationKind which is a Flag that start from 1. I can revert to the default enum values if necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like some nice additions. Few minor comments.
@@ -278,7 +278,10 @@ | |||
|
|||
<controls:InAppNotification x:Name="ExampleInAppNotification" | |||
Content="This is a test message." | |||
ShowDismissButton="@[ShowDismissButton:Bool:True]" /> | |||
ShowDismissButton="@[ShowDismissButton:Bool:True]" | |||
AnimationDuration="@[AnimationDuration:String:100]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually use the Slider type for these sorts of values.
ShowDismissButton="@[ShowDismissButton:Bool:True]" /> | ||
ShowDismissButton="@[ShowDismissButton:Bool:True]" | ||
AnimationDuration="@[AnimationDuration:String:100]" | ||
VerticalOffset="@[VerticalOffset:String:100]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the DoubleSlider for these.
@@ -289,7 +292,10 @@ | |||
BorderThickness="0" | |||
ShowDismissButton="False" | |||
VerticalAlignment="Top" | |||
RenderTransformOrigin="0.5,0"> | |||
RenderTransformOrigin="0.5,0" | |||
AnimationDuration="@[AnimationDuration:String:100]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you reuse the same property in the file later you can just use its name @[AnimationDuration]
it'll grab the settings from the first one.
|
||
Visibility = Visibility.Visible; | ||
VisualStateManager.GoToState(this, StateContentVisible, true); | ||
Opening?.Invoke(this, EventArgs.Empty); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put this before the visibility change and check the eventargs.handled? This way if they register to the event they could prevent the popup from displaying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-hawker I am not sure how to check the Handled property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to create your own EventArgs class which has a 'Handled' property on it. Then, construct it and pass its reference into the invoke to Opening. Then you can see if the property was set to true afterwards and escape.
Though if we're going to align more with FlyoutBase in the future, we may want to use 'Cancel' as they do here for Closing
: https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.primitives.flyoutbaseclosingeventargs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can directly start with Cancel
right now, don't you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sorry, that's kinda what I meant. :P
docs/controls/InAppNotification.md
Outdated
@@ -88,9 +88,50 @@ To hide it, simply set the property to `ShowDismissButton="False"`. | |||
|
|||
## Events | |||
|
|||
### Opening | |||
|
|||
This event is raised when the system or your user started to open of the notification. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user would never be directly triggering the notification. Maybe:
This event is raised just before the notification starts to open.
@@ -127,10 +133,25 @@ public void Show(DataTemplate dataTemplate, int duration = 0) | |||
/// </summary> | |||
public void Dismiss() | |||
{ | |||
Dismiss(InAppNotificationDismissKind.User); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want a third Programmatic one on the enum? As this is the function the developer would call from their code, eh?
/// <summary> | ||
/// Event raised when the notification is dismissing | ||
/// </summary> | ||
public event InAppNotificationDismissingEventHandler Dismissing; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Later we may want to discuss if these should be Closing/Closed to align with FlyoutBase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course. I did not wanted to make a breaking change because the Dismissed event was already available in 2.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, makes sense. Just wanted to make sure we have something tracking it for a later release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to decide on this. @nmetulev may have an opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closed/Closing does fit in better with the Opened/Opening events. If you do want to change it, I recommend marking Dismissed deprecated and adding the new events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
docs/controls/InAppNotification.md
Outdated
```xml | ||
* `AnimationDuration` - duration of the popup animation (in milliseconds) | ||
* `VerticalOffset` - vertical offset of the popup animation | ||
* `HorizontalOffset` - horizontal offset of the popup animation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A table would be nice to explain properties. Something like this
Animation properties | Type | Description |
---|---|---|
AnimationDuration |
double | Duration of the popup animation in milliseconds |
VerticalOffset |
double | Vertical offset of the popup animation |
HorizontalOffset |
double | Horizontal offset of the popup animation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
docs/controls/InAppNotification.md
Outdated
``` | ||
### Using styles | ||
|
||
The In App Notification control is designed to support multiple styles. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be "InAppNotification control"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"in-app notification" is better.
docs/controls/InAppNotification.md
Outdated
### Using styles | ||
|
||
The In App Notification control is designed to support multiple styles. | ||
The default style applied is the Microsoft Edge-like notification. ?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "??" on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it's a mistake.
I still need to make a fix because the animation properties are not set during initialization. |
…hen first initialized
Set default value for |
@Vijay-Nirmal There is already a default value. VerticalOffset=100 and HorizontalOffset=0. |
@Odonno If I didn't set Setting default value for <Setter Property="VerticalOffset" Value="100"/>
<Setter Property="HorizontalOffset" Value="0"/> |
@Vijay-Nirmal I thought I added them in the default template. Sorry for this mistake. Currently fixing it. |
/// <summary> | ||
/// Event raised when the notification is dismissing | ||
/// </summary> | ||
public event InAppNotificationDismissingEventHandler Dismissing; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closed/Closing does fit in better with the Opened/Opening events. If you do want to change it, I recommend marking Dismissed deprecated and adding the new events.
} | ||
} | ||
|
||
private void UpdateAnimationDuration(int duration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if I've already re-templated the control and added custom duration? Or what if I want to have multiple DoubleAnimationUsingKeyFrames with different durations. Seems like this will break re-templated controls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It's possible. I don't know what is the best strategy to have default animations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd try to see if you can use TemplateBinding in the storyboard in the template itself. That should allow you to remove all of this code and have everything in the template.
} | ||
|
||
private void UpdateVerticalOffset(double verticalOffset) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also seems like it will be messing with my custom animations? Instead of doing the Update(Animation/Offset) through code, is it possible to instead do this through TemplateBinding in the template itself?
ping @Odonno |
@nmetulev Sorry. Not enough time right now. Will work on it as soon as I can. |
Use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This a great addition to the control. With the exception of minor changes, looks good to me.
@@ -38,6 +38,7 @@ You can define "interactive" values in this file. The value types can be: | |||
* String: You want the user to provide a text. The string is built like this @[Name:**String**:Default value] | |||
* Slider: You want the user to provide a double value. The string is built like this @[Name:**Slider**:Default value:min-max] | |||
* DoubleSlider: Same as slider but with double values (0.01 precision) | |||
* TimeSpan: You want the user to a duration. The string is built like this (all values in miliseconds) @[Name:**TimeSpan**:DefaultValue:min-max] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a word, should be You want the user to provide a duration
/// <summary> | ||
/// Event raised when the notification is closed | ||
/// </summary> | ||
public event EventHandler Closed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the Closed EventHandler also provide the details on how it was closed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nmetulev Well, it can a little bit harder for this part. I used a Timer for both Opened and Closed events, started after the Opening and Closing events respectively. I am not sure if it's possible but I can eventually store the InAppNotificationDismissKind
before Tick event. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that makes sense to me, you can store the last dismisskind in a variable
/// Event raised when the notification is dismissing | ||
/// </summary> | ||
[Obsolete("Use Closing event instead.")] | ||
public event InAppNotificationDismissingEventHandler Dismissing; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to add this event if it wasn't there before
@@ -0,0 +1,48 @@ | |||
// ****************************************************************** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this class can be removed with the event.
@nmetulev Should be good. |
Now we just need @michael-hawker seal of approval :) |
@@ -21,27 +21,28 @@ The control should be placed where you want your notification to be displayed in | |||
|
|||
``` | |||
|
|||
**Note:** Since the control is part of the page visual tree, it will render in the order it was added in the parent control, and might be hidden by other elements. For the control to render on top of other elements, add it as the last child of the parent control or set the Canvas.ZIndex to a high number. | |||
> [!NOTE] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do we do for other notes? We should be consistent still.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are moving to use this for all the docs per #1569
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, missed that note :), all good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks! Small question about the doc formatting, otherwise can't wait to try out the improvements!
Linked to #1430