Skip to content
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

Merged
merged 24 commits into from
Nov 7, 2017
Merged

feat(InAppNotifications): improve control #1441

merged 24 commits into from
Nov 7, 2017

Conversation

Odonno
Copy link
Contributor

@Odonno Odonno commented Aug 26, 2017

Linked to #1430

@nmetulev nmetulev added this to the v2.1 milestone Aug 26, 2017
/// <summary>
/// When user explicitly dismissed the notification.
/// </summary>
User = 1,
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Member

@michael-hawker michael-hawker left a 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]"
Copy link
Member

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]"
Copy link
Member

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]"
Copy link
Member

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);
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

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

@@ -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.
Copy link
Member

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);
Copy link
Member

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;
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

```xml
* `AnimationDuration` - duration of the popup animation (in milliseconds)
* `VerticalOffset` - vertical offset of the popup animation
* `HorizontalOffset` - horizontal offset of the popup animation
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

```
### Using styles

The In App Notification control is designed to support multiple styles.
Copy link
Contributor

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"?

Copy link
Contributor Author

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.

### Using styles

The In App Notification control is designed to support multiple styles.
The default style applied is the Microsoft Edge-like notification. ??
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "??" on purpose?

Copy link
Contributor Author

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.

@Odonno
Copy link
Contributor Author

Odonno commented Aug 30, 2017

I still need to make a fix because the animation properties are not set during initialization.

@Vijay-Nirmal
Copy link
Contributor

Set default value for VerticalOffset and HorizontalOffset otherwise the app will crash.

@Odonno
Copy link
Contributor Author

Odonno commented Aug 31, 2017

@Vijay-Nirmal There is already a default value. VerticalOffset=100 and HorizontalOffset=0.

@Vijay-Nirmal
Copy link
Contributor

@Odonno If I didn't set VerticalOffset and HorizontalOffset then I am getting exceptions.

devenv_2017-08-31_18-01-12

Setting default value for VerticalOffset and HorizontalOffset in InAppNotification.xaml solves my problem

<Setter Property="VerticalOffset" Value="100"/>
<Setter Property="HorizontalOffset" Value="0"/>

@Odonno
Copy link
Contributor Author

Odonno commented Aug 31, 2017

@Vijay-Nirmal I thought I added them in the default template. Sorry for this mistake. Currently fixing it.

@nmetulev nmetulev changed the base branch from dev to master September 1, 2017 04:03
/// <summary>
/// Event raised when the notification is dismissing
/// </summary>
public event InAppNotificationDismissingEventHandler Dismissing;
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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)
{
Copy link
Contributor

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?

@nmetulev
Copy link
Contributor

ping @Odonno

@Odonno
Copy link
Contributor Author

Odonno commented Oct 24, 2017

@nmetulev Sorry. Not enough time right now. Will work on it as soon as I can.

@Vijay-Nirmal
Copy link
Contributor

Use > [!NOTE] in InAppNotification.md/#24 as per #issuecomment-341176267

Copy link
Contributor

@nmetulev nmetulev left a 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]
Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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;
Copy link
Contributor

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 @@
// ******************************************************************
Copy link
Contributor

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.

@Odonno
Copy link
Contributor Author

Odonno commented Nov 7, 2017

@nmetulev Should be good.

@nmetulev
Copy link
Contributor

nmetulev commented Nov 7, 2017

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]
Copy link
Member

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.

Copy link
Contributor

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

Copy link
Member

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!

Copy link
Member

@michael-hawker michael-hawker left a 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!

@nmetulev nmetulev merged commit 0b06b20 into CommunityToolkit:master Nov 7, 2017
@Odonno Odonno deleted the inAppNotificationImprovements branch November 8, 2017 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants