Skip to content

Commit add7f5e

Browse files
committed
Ported notifications component from 7.x
1 parent 7312fc3 commit add7f5e

File tree

149 files changed

+19146
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+19146
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@ECHO OFF
2+
3+
powershell ..\..\tooling\ProjectHeads\GenerateSingleSampleHeads.ps1 -componentPath %CD% %*
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using CommunityToolkit.Notifications.Adaptive.Elements;
8+
9+
namespace CommunityToolkit.Notifications
10+
{
11+
/// <summary>
12+
/// Groups semantically identify that the content in the group must either be displayed as a whole, or not displayed if it cannot fit. Groups also allow creating multiple columns. Supported on Tiles since RTM. Supported on Toasts since Anniversary Update.
13+
/// </summary>
14+
public sealed class AdaptiveGroup : ITileBindingContentAdaptiveChild, IAdaptiveChild, IToastBindingGenericChild
15+
{
16+
/// <summary>
17+
/// Gets the only valid children of groups are <see cref="AdaptiveSubgroup"/>.
18+
/// Each subgroup is displayed as a separate vertical column. Note that you must
19+
/// include at least one subgroup in your group, otherwise an <see cref="InvalidOperationException"/>
20+
/// will be thrown when you try to retrieve the XML for the notification.
21+
/// </summary>
22+
public IList<AdaptiveSubgroup> Children { get; private set; } = new List<AdaptiveSubgroup>();
23+
24+
internal Element_AdaptiveGroup ConvertToElement()
25+
{
26+
if (Children.Count == 0)
27+
{
28+
throw new InvalidOperationException("Groups must have at least one child subgroup. The Children property had zero items in it.");
29+
}
30+
31+
Element_AdaptiveGroup group = new Element_AdaptiveGroup();
32+
33+
foreach (var subgroup in Children)
34+
{
35+
group.Children.Add(subgroup.ConvertToElement());
36+
}
37+
38+
return group;
39+
}
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
7+
namespace CommunityToolkit.Notifications.Adaptive
8+
{
9+
internal static class AdaptiveHelper
10+
{
11+
internal static object ConvertToElement(object obj)
12+
{
13+
if (obj is AdaptiveText)
14+
{
15+
return (obj as AdaptiveText).ConvertToElement();
16+
}
17+
18+
if (obj is AdaptiveImage)
19+
{
20+
return (obj as AdaptiveImage).ConvertToElement();
21+
}
22+
23+
if (obj is AdaptiveGroup)
24+
{
25+
return (obj as AdaptiveGroup).ConvertToElement();
26+
}
27+
28+
if (obj is AdaptiveSubgroup)
29+
{
30+
return (obj as AdaptiveSubgroup).ConvertToElement();
31+
}
32+
33+
if (obj is AdaptiveProgressBar)
34+
{
35+
return (obj as AdaptiveProgressBar).ConvertToElement();
36+
}
37+
38+
throw new NotImplementedException("Unknown object: " + obj.GetType());
39+
}
40+
}
41+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using CommunityToolkit.Notifications.Adaptive.Elements;
6+
7+
namespace CommunityToolkit.Notifications
8+
{
9+
/// <summary>
10+
/// An inline image.
11+
/// </summary>
12+
public sealed class AdaptiveImage
13+
: IBaseImage,
14+
IToastBindingGenericChild,
15+
ITileBindingContentAdaptiveChild,
16+
IAdaptiveChild,
17+
IAdaptiveSubgroupChild
18+
{
19+
/// <summary>
20+
/// Gets or sets the desired cropping of the image.
21+
/// Supported on Tiles since RTM. Supported on Toast since Anniversary Update.
22+
/// </summary>
23+
public AdaptiveImageCrop HintCrop { get; set; }
24+
25+
/// <summary>
26+
/// Gets or sets a value whether a margin is removed. images have an 8px margin around them.
27+
/// You can remove this margin by setting this property to true.
28+
/// Supported on Tiles since RTM. Supported on Toast since Anniversary Update.
29+
/// </summary>
30+
public bool? HintRemoveMargin { get; set; }
31+
32+
/// <summary>
33+
/// Gets or sets the horizontal alignment of the image.
34+
/// For Toast, this is only supported when inside an <see cref="AdaptiveSubgroup"/>.
35+
/// </summary>
36+
public AdaptiveImageAlign HintAlign { get; set; }
37+
38+
private string _source;
39+
40+
/// <summary>
41+
/// Gets or sets the URI of the image (Required).
42+
/// Can be from your application package, application data, or the internet.
43+
/// Internet images must be less than 200 KB in size.
44+
/// </summary>
45+
public string Source
46+
{
47+
get { return _source; }
48+
set { BaseImageHelper.SetSource(ref _source, value); }
49+
}
50+
51+
/// <summary>
52+
/// Gets or sets a description of the image, for users of assistive technologies.
53+
/// </summary>
54+
public string AlternateText { get; set; }
55+
56+
/// <summary>
57+
/// Gets or sets set to true to allow Windows to append a query string to the image URI
58+
/// supplied in the Tile notification. Use this attribute if your server hosts
59+
/// images and can handle query strings, either by retrieving an image variant based
60+
/// on the query strings or by ignoring the query string and returning the image
61+
/// as specified without the query string. This query string specifies scale,
62+
/// contrast setting, and language.
63+
/// </summary>
64+
public bool? AddImageQuery { get; set; }
65+
66+
/// <summary>
67+
/// Returns the image's source string.
68+
/// </summary>
69+
/// <returns>The image's source string.</returns>
70+
public override string ToString()
71+
{
72+
if (Source == null)
73+
{
74+
return "Source is null";
75+
}
76+
77+
return Source;
78+
}
79+
80+
internal Element_AdaptiveImage ConvertToElement()
81+
{
82+
Element_AdaptiveImage image = BaseImageHelper.CreateBaseElement(this);
83+
84+
image.Crop = HintCrop;
85+
image.RemoveMargin = HintRemoveMargin;
86+
image.Align = HintAlign;
87+
image.Placement = AdaptiveImagePlacement.Inline;
88+
89+
return image;
90+
}
91+
}
92+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace CommunityToolkit.Notifications
6+
{
7+
/// <summary>
8+
/// Specifies the horizontal alignment for an image.
9+
/// </summary>
10+
public enum AdaptiveImageAlign
11+
{
12+
/// <summary>
13+
/// Default value, alignment behavior determined by renderer.
14+
/// </summary>
15+
Default,
16+
17+
/// <summary>
18+
/// Image stretches to fill available width (and potentially available height too, depending on where the image is).
19+
/// </summary>
20+
Stretch,
21+
22+
/// <summary>
23+
/// Align the image to the left, displaying the image at its native resolution.
24+
/// </summary>
25+
Left,
26+
27+
/// <summary>
28+
/// Align the image in the center horizontally, displaying the image at its native resolution.
29+
/// </summary>
30+
Center,
31+
32+
/// <summary>
33+
/// Align the image to the right, displaying the image at its native resolution.
34+
/// </summary>
35+
Right
36+
}
37+
38+
/// <summary>
39+
/// Specify the desired cropping of the image.
40+
/// </summary>
41+
public enum AdaptiveImageCrop
42+
{
43+
/// <summary>
44+
/// Default value, cropping behavior determined by renderer.
45+
/// </summary>
46+
Default,
47+
48+
/// <summary>
49+
/// Image is not cropped.
50+
/// </summary>
51+
None,
52+
53+
/// <summary>
54+
/// Image is cropped to a circle shape.
55+
/// </summary>
56+
Circle
57+
}
58+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#pragma warning disable SA1121 // UseBuiltInTypeAlias
6+
7+
using System;
8+
using CommunityToolkit.Notifications.Adaptive.Elements;
9+
10+
#if WINRT
11+
using System.Collections.Generic;
12+
using BindableProgressBarValue = CommunityToolkit.Notifications.AdaptiveProgressBarValue;
13+
using BindableString = System.String;
14+
#else
15+
using BindableProgressBarValue = CommunityToolkit.Notifications.BindableProgressBarValue;
16+
using BindableString = CommunityToolkit.Notifications.BindableString;
17+
#endif
18+
19+
namespace CommunityToolkit.Notifications
20+
{
21+
/// <summary>
22+
/// New in Creators Update: A progress bar. Only supported on toasts on Desktop, build 15007 or newer.
23+
/// </summary>
24+
public sealed class AdaptiveProgressBar : IToastBindingGenericChild
25+
{
26+
#if WINRT
27+
/// <summary>
28+
/// Gets a dictionary of the current data bindings, where you can assign new bindings.
29+
/// </summary>
30+
public IDictionary<AdaptiveProgressBarBindableProperty, string> Bindings { get; private set; } = new Dictionary<AdaptiveProgressBarBindableProperty, string>();
31+
#endif
32+
33+
/// <summary>
34+
/// Gets or sets an optional title string. Supports data binding.
35+
/// </summary>
36+
public BindableString Title { get; set; }
37+
38+
/// <summary>
39+
/// Gets or sets the value of the progress bar. Supports data binding. Defaults to 0.
40+
/// </summary>
41+
public BindableProgressBarValue Value { get; set; } = AdaptiveProgressBarValue.FromValue(0);
42+
43+
/// <summary>
44+
/// Gets or sets an optional string to be displayed instead of the default percentage string. If this isn't provided, something like "70%" will be displayed.
45+
/// </summary>
46+
public BindableString ValueStringOverride { get; set; }
47+
48+
/// <summary>
49+
/// Gets or sets a status string (Required), which is displayed underneath the progress bar. This string should reflect the status of the operation, like "Downloading..." or "Installing..."
50+
/// </summary>
51+
public BindableString Status { get; set; }
52+
53+
internal Element_AdaptiveProgressBar ConvertToElement()
54+
{
55+
// If Value not provided, we use 0
56+
var val = Value;
57+
if (val == null)
58+
{
59+
val = AdaptiveProgressBarValue.FromValue(0);
60+
}
61+
62+
var answer = new Element_AdaptiveProgressBar();
63+
64+
#if WINRT
65+
answer.Title = XmlWriterHelper.GetBindingOrAbsoluteXmlValue(Bindings, AdaptiveProgressBarBindableProperty.Title, Title);
66+
answer.Value = XmlWriterHelper.GetBindingOrAbsoluteXmlValue(Bindings, AdaptiveProgressBarBindableProperty.Value, val.ToXmlString());
67+
answer.ValueStringOverride = XmlWriterHelper.GetBindingOrAbsoluteXmlValue(Bindings, AdaptiveProgressBarBindableProperty.ValueStringOverride, ValueStringOverride);
68+
answer.Status = XmlWriterHelper.GetBindingOrAbsoluteXmlValue(Bindings, AdaptiveProgressBarBindableProperty.Status, Status);
69+
#else
70+
answer.Title = Title?.ToXmlString();
71+
answer.Value = val.ToXmlString();
72+
answer.ValueStringOverride = ValueStringOverride?.ToXmlString();
73+
answer.Status = Status?.ToXmlString();
74+
#endif
75+
76+
if (answer.Status == null)
77+
{
78+
throw new NullReferenceException("Status property is required.");
79+
}
80+
81+
return answer;
82+
}
83+
}
84+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace CommunityToolkit.Notifications
6+
{
7+
// Note that this code is only compiled for WinRT. It is not compiled in any of the other projects.
8+
#if WINRT
9+
/// <summary>
10+
/// An enumeration of the properties that support data binding on <see cref="AdaptiveProgressBar"/> .
11+
/// </summary>
12+
public enum AdaptiveProgressBarBindableProperty
13+
{
14+
/// <summary>
15+
/// An optional title string
16+
/// </summary>
17+
Title,
18+
19+
/// <summary>
20+
/// The value of the progress bar.
21+
/// </summary>
22+
Value,
23+
24+
/// <summary>
25+
/// An optional string to be displayed instead of the default percentage string. If this isn't provided, something like "70%" will be displayed.
26+
/// </summary>
27+
ValueStringOverride,
28+
29+
/// <summary>
30+
/// An optional status string, which is displayed underneath the progress bar. If provided, this string should reflect the status of the download, like "Downloading..." or "Installing...".
31+
/// </summary>
32+
Status
33+
}
34+
#endif
35+
}

0 commit comments

Comments
 (0)