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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
844a176
feat(InAppNotifications): add events Opening, Opened and Dismissing
Odonno Aug 26, 2017
4af5fb8
docs(InAppNotifications): add docs on new events
Odonno Aug 26, 2017
348ab1c
feat(InAppNotifications): add details on Dismissing event args
Odonno Aug 26, 2017
4514004
feat(InAppNotifications): improve animations
Odonno Aug 27, 2017
13dbd44
refactor(InAppNotifications): split styles into separate files
Odonno Aug 28, 2017
8b2722a
refactor(InAppNotifications): improve docs and code
Odonno Aug 28, 2017
a8965f6
feat(InAppNotifications): add ability to cancel the opening/closing
Odonno Aug 28, 2017
27539f5
docs(InAppNotifications): update animation part
Odonno Aug 29, 2017
562ac87
docs(InAppNotifications): add styling part
Odonno Aug 29, 2017
9676d3b
docs(InAppNotifications): fix typos and improve animation property de…
Odonno Aug 29, 2017
fb86ea9
merge
Odonno Aug 30, 2017
ad14b9b
fix(InAppNotifications): update animation properties on the control w…
Odonno Aug 30, 2017
227619a
fix(InAppNotifications): add default values for animation in default …
Odonno Aug 31, 2017
828c517
feat(InAppNotification): mark Dimiss events as obsolete and replace t…
Odonno Sep 30, 2017
99ccc76
Moved animation properties to template
nmetulev Oct 9, 2017
31d2568
merge
Odonno Nov 4, 2017
0b0dfb2
Merge branch 'nmetulev/InAppNotifications' of https://github.com/Micr…
Odonno Nov 4, 2017
1178f6b
docs(InAppNotification): update code blocks
Odonno Nov 4, 2017
f5e38ef
docs(InAppNotification): change type of AnimationDuration property
Odonno Nov 4, 2017
fb5282f
docs(InAppNotification): use Note block
Odonno Nov 5, 2017
2093c1a
docs(SampleApp): fix docs on TimeSpan
Odonno Nov 7, 2017
b8c5e5f
refactor(InAppNotification): remove Dismissing event
Odonno Nov 7, 2017
33a1c3e
docs(InAppNotification): add missing header
Odonno Nov 7, 2017
f9ec93a
feat(InAppNotification): add dismiss kind info on closed event
Odonno Nov 7, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Microsoft.Toolkit.Uwp.SampleApp/Common/TimeSpanConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************

using System;
using Windows.UI.Xaml.Data;

namespace Microsoft.Toolkit.Uwp.SampleApp.Common
{
public class TimeSpanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is TimeSpan tSpan)
{
return tSpan.TotalMilliseconds;
}

return value;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
if (value is double milliseconds)
{
return TimeSpan.FromMilliseconds(milliseconds);
}

return TimeSpan.MinValue;
}
}
}
20 changes: 20 additions & 0 deletions Microsoft.Toolkit.Uwp.SampleApp/Controls/PropertyControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,26 @@ private void PropertyControl_OnDataContextChanged(FrameworkElement sender, DataC

controlToAdd = colorComboBox;
dependencyProperty = Selector.SelectedItemProperty;
break;
case PropertyKind.TimeSpan:
var timeSlider = new Slider();
var timeSliderOption = option as SliderPropertyOptions;
if (timeSliderOption != null)
{
timeSlider.Minimum = timeSliderOption.MinValue;
timeSlider.Maximum = timeSliderOption.MaxValue;
timeSlider.StepFrequency = timeSliderOption.Step;
}

if ((propertyDict[option.Name] as ValueHolder).Value is double timeValue)
{
timeSlider.Value = timeValue;
}

controlToAdd = timeSlider;
dependencyProperty = RangeBase.ValueProperty;
converter = new TimeSpanConverter();

break;
default:
var textBox = new TextBox { Text = (propertyDict[option.Name] as ValueHolder).Value.ToString() };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@
<Compile Include="Common\BoolStringConverter.cs" />
<Compile Include="Common\Constants.cs" />
<Compile Include="Common\DelegateCommand{T}.cs" />
<Compile Include="Common\TimeSpanConverter.cs" />
<Compile Include="Common\EnumConverter.cs" />
<Compile Include="Common\ListViewHoverScroll.cs" />
<Compile Include="Common\SampleCommand.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum PropertyKind
String,
Enum,
Bool,
Brush
Brush,
TimeSpan
}
}
31 changes: 31 additions & 0 deletions Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,37 @@ public async Task PreparePropertyDescriptorAsync()
continue;
}

break;
case PropertyKind.TimeSpan:
try
{
var sliderOptions = new SliderPropertyOptions { DefaultValue = TimeSpan.FromMilliseconds(double.Parse(value)) };
var parameters = match.Groups["parameters"].Value;
var split = parameters.Split('-');
int minIndex = 0;
int minMultiplier = 1;
if (string.IsNullOrEmpty(split[0]))
{
minIndex = 1;
minMultiplier = -1;
}

sliderOptions.MinValue = minMultiplier * double.Parse(split[minIndex]);
sliderOptions.MaxValue = double.Parse(split[minIndex + 1]);
if (split.Length > 2 + minIndex)
{
sliderOptions.Step = double.Parse(split[split.Length - 1]);
}

options = sliderOptions;
}
catch (Exception ex)
{
Debug.WriteLine($"Unable to extract slider info from {value}({ex.Message})");
TrackingManager.TrackException(ex);
continue;
}

break;
case PropertyKind.Enum:
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/Styles/MSEdgeNotificationStyle.xaml" />
<ResourceDictionary Source="ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/Styles/VSCodeNotificationStyle.xaml" />
</ResourceDictionary.MergedDictionaries>

<local:DismissCommand x:Key="DismissCommand" />

<Style x:Key="DismissTextBlockButtonStyle" TargetType="ButtonBase">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/Styles/VSCodeNotificationStyle.xaml" />
</ResourceDictionary.MergedDictionaries>

<local:DismissCommand x:Key="DismissCommand" />

<Style x:Key="DismissTextBlockButtonStyle" TargetType="ButtonBase">
Expand Down Expand Up @@ -278,41 +282,29 @@

<controls:InAppNotification x:Name="ExampleInAppNotification"
Content="This is a test message."
ShowDismissButton="@[ShowDismissButton:Bool:True]" />
ShowDismissButton="@[ShowDismissButton:Bool:True]"
AnimationDuration="@[AnimationDuration:TimeSpan:100:0-5000]"
VerticalOffset="@[VerticalOffset:DoubleSlider:100.0:-200.0-200.0]"
HorizontalOffset="@[HorizontalOffset:DoubleSlider:0.0:-200.0-200.0]" />

<controls:InAppNotification x:Name="ExampleVSCodeInAppNotification"
MinHeight="35"
Background="#333333"
Foreground="White"
FontSize="14"
Padding="0"
BorderThickness="0"
ShowDismissButton="False"
VerticalAlignment="Top"
RenderTransformOrigin="0.5,0">
Style="{StaticResource VSCodeNotificationStyle}"
AnimationDuration="@[AnimationDuration]"
VerticalOffset="@[VerticalOffset]"
HorizontalOffset="@[HorizontalOffset]">
<controls:InAppNotification.ContentTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Grid Margin="10 5" Height="20" Background="#007ACC">
<TextBlock Text="info"
Padding="5 0"
FontWeight="Bold"
VerticalAlignment="Center"
Foreground="White" />
</Grid>

<TextBlock Grid.Column="1"
VerticalAlignment="Center"
<TextBlock VerticalAlignment="Center"
Text="This a test message."
TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" />

<StackPanel Grid.Column="2" Orientation="Horizontal">
<StackPanel Grid.Column="1" Orientation="Horizontal">
<Button Content="Action 1"
Command="{StaticResource DismissCommand}"
CommandParameter="{Binding ElementName=ExampleVSCodeInAppNotification}"
Expand Down
1 change: 1 addition & 0 deletions Microsoft.Toolkit.Uwp.SampleApp/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 provide a duration. The string is built like this (all values in miliseconds) @[Name:**TimeSpan**:DefaultValue:min-max]
* Enum: You want the user to provide a enum value. The string is built like this @[Name:**Enum**:EnumType.DefaultValue]
* Brush: You want the user to select a color from a list. The string is built like this @[Name:**Brush**:Black]
* Bool: You want the user to enable or disable a property. The string is built like this @[Name:**Bool**:True]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************

using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media.Animation;

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
/// <summary>
/// In App Notification defines a control to show local notification in the app.
/// </summary>
public partial class InAppNotification
{
/// <summary>
/// Gets the value of the KeyFrameDuration attached Property
/// </summary>
/// <param name="obj">the KeyFrame where the duration is set</param>
/// <returns>Value of KeyFrameDuration</returns>
public static TimeSpan GetKeyFrameDuration(DependencyObject obj)
{
return (TimeSpan)obj.GetValue(KeyFrameDurationProperty);
}

/// <summary>
/// Sets the value of the KeyFrameDuration attached property
/// </summary>
/// <param name="obj">The KeyFrame object where the property is attached</param>
/// <param name="value">The TimeSpan value to be set as duration</param>
public static void SetKeyFrameDuration(DependencyObject obj, TimeSpan value)
{
obj.SetValue(KeyFrameDurationProperty, value);
}

/// <summary>
/// Using a DependencyProperty as the backing store for KeyFrameDuration. This enables animation, styling, binding, etc
/// </summary>
public static readonly DependencyProperty KeyFrameDurationProperty =
DependencyProperty.RegisterAttached("KeyFrameDuration", typeof(TimeSpan), typeof(InAppNotification), new PropertyMetadata(0, OnKeyFrameAnimationChanged));

private static void OnKeyFrameAnimationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue is TimeSpan ts)
{
var keyTimeFromAnimationDuration = KeyTime.FromTimeSpan(ts);
if (d is DoubleKeyFrame dkf)
{
dkf.KeyTime = KeyTime.FromTimeSpan(ts);
}
else if (d is ObjectKeyFrame okf)
{
okf.KeyTime = KeyTime.FromTimeSpan(ts);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,56 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
/// </summary>
public partial class InAppNotification
{
/// <summary>
/// Event raised when the notification is opening
/// </summary>
public event InAppNotificationOpeningEventHandler Opening;

/// <summary>
/// Event raised when the notification is opened
/// </summary>
public event EventHandler Opened;

/// <summary>
/// Event raised when the notification is dismissed
/// </summary>
[Obsolete("Use Closed event instead.")]
public event EventHandler Dismissed;

/// <summary>
/// Event raised when the notification is closing
/// </summary>
public event InAppNotificationClosingEventHandler Closing;

/// <summary>
/// Event raised when the notification is closed
/// </summary>
public event InAppNotificationClosedEventHandler Closed;

private void DismissButton_Click(object sender, RoutedEventArgs e)
{
Dismiss();
Dismiss(InAppNotificationDismissKind.User);
}

private void DismissTimer_Tick(object sender, object e)
{
Dismiss(InAppNotificationDismissKind.Timeout);
_dismissTimer.Stop();
}

private void OpenAnimationTimer_Tick(object sender, object e)
{
_animationTimer.Stop();
Opened?.Invoke(this, EventArgs.Empty);
_animationTimer.Tick -= OpenAnimationTimer_Tick;
}

private void DismissAnimationTimer_Tick(object sender, object e)
{
_animationTimer.Stop();
Dismissed?.Invoke(this, EventArgs.Empty);
Closed?.Invoke(this, new InAppNotificationClosedEventArgs(_lastDismissKind));
_animationTimer.Tick -= DismissAnimationTimer_Tick;
}
}
}
Loading