Skip to content

Commit e418928

Browse files
Clean-up Shadow internal part usage based on @Sergio0694 PR comments
1 parent 2404be9 commit e418928

File tree

8 files changed

+24
-21
lines changed

8 files changed

+24
-21
lines changed

Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/ShadowAnimation{TValue,TKeyFrame}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static AnimationBuilder ThrowArgumentNullException()
6464
if (Target is IAttachedShadow allShadows)
6565
{
6666
// in this case we'll animate all the shadows being used.
67-
foreach (var context in allShadows.GetElementContextEnumerable()) //// TODO: Find better way!!!
67+
foreach (var context in allShadows.EnumerateElementContexts()) //// TODO: Find better way!!!
6868
{
6969
NormalizedKeyFrameAnimationBuilder<TKeyFrame>.Composition keyFrameBuilder = new(
7070
explicitTarget,

Microsoft.Toolkit.Uwp.UI.Media/Shadows/AttachedCardShadow.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Media
1717
/// <remarks>
1818
/// This shadow will not work on <see cref="FrameworkElement"/> which is directly clipping to its bounds (e.g. a <see cref="Windows.UI.Xaml.Controls.Border"/> using a <see cref="Windows.UI.Xaml.Controls.Control.CornerRadius"/>). An extra <see cref="Windows.UI.Xaml.Controls.Border"/> can instead be applied around the clipped border with the Shadow to create the desired effect. Most existing controls due to how they're templated will not encounter this behavior or require this workaround.
1919
/// </remarks>
20-
public class AttachedCardShadow : AttachedShadowBase
20+
public sealed class AttachedCardShadow : AttachedShadowBase
2121
{
2222
private const float MaxBlurRadius = 72;
2323
private static readonly TypedResourceKey<CompositionGeometricClip> ClipResourceKey = "Clip";
@@ -52,7 +52,7 @@ public double CornerRadius
5252
public override bool IsSupported => SupportsCompositionVisualSurface;
5353

5454
/// <inheritdoc/>
55-
protected override bool SupportsOnSizeChangedEvent => true;
55+
protected internal override bool SupportsOnSizeChangedEvent => true;
5656

5757
/// <inheritdoc/>
5858
protected override void OnPropertyChanged(AttachedShadowElementContext context, DependencyProperty property, object oldValue, object newValue)
@@ -145,7 +145,7 @@ protected override CompositionClip GetShadowClip(AttachedShadowElementContext co
145145
}
146146

147147
/// <inheritdoc/>
148-
protected override void OnSizeChanged(AttachedShadowElementContext context, Size newSize, Size previousSize)
148+
protected internal override void OnSizeChanged(AttachedShadowElementContext context, Size newSize, Size previousSize)
149149
{
150150
var sizeAsVec2 = newSize.ToVector2();
151151

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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.Runtime.CompilerServices;
6+
7+
[assembly: InternalsVisibleTo("Microsoft.Toolkit.Uwp.UI.Media")]

Microsoft.Toolkit.Uwp.UI/Shadows/AttachedDropShadow.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System;
6-
using System.Collections.Generic;
75
using System.Linq;
86
using System.Numerics;
9-
using System.Text;
10-
using System.Threading.Tasks;
117
using Windows.Foundation;
128
using Windows.UI;
139
using Windows.UI.Composition;
@@ -21,7 +17,7 @@ namespace Microsoft.Toolkit.Uwp.UI
2117
/// <summary>
2218
/// A helper to add a composition based drop shadow to a <see cref="FrameworkElement"/>.
2319
/// </summary>
24-
public class AttachedDropShadow : AttachedShadowBase
20+
public sealed class AttachedDropShadow : AttachedShadowBase
2521
{
2622
private const float MaxBlurRadius = 72;
2723

@@ -121,7 +117,7 @@ private static void OnCastToPropertyChanged(DependencyObject d, DependencyProper
121117
// Need to remove all old children from previous container if it's changed
122118
if (prevContainer != null && prevContainer != shadow._container)
123119
{
124-
foreach (var context in shadow.GetElementContextEnumerable())
120+
foreach (var context in shadow.EnumerateElementContexts())
125121
{
126122
if (context.IsInitialized &&
127123
prevContainer.Children.Contains(context.SpriteVisual))
@@ -132,7 +128,7 @@ private static void OnCastToPropertyChanged(DependencyObject d, DependencyProper
132128
}
133129

134130
// Make sure all child shadows are hooked into container
135-
foreach (var context in shadow.GetElementContextEnumerable())
131+
foreach (var context in shadow.EnumerateElementContexts())
136132
{
137133
if (context.IsInitialized)
138134
{
@@ -152,7 +148,7 @@ private void CastToElement_SizeChanged(object sender, SizeChangedEventArgs e)
152148
{
153149
// Don't use sender or 'e' here as related to container element not
154150
// element for shadow, grab values off context. (Also may be null from internal call.)
155-
foreach (var context in GetElementContextEnumerable())
151+
foreach (var context in EnumerateElementContexts())
156152
{
157153
if (context.IsInitialized)
158154
{

Microsoft.Toolkit.Uwp.UI/Shadows/AttachedShadowBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public AttachedShadowElementContext GetElementContext(FrameworkElement element)
172172
}
173173

174174
/// <inheritdoc/>
175-
public IEnumerable<AttachedShadowElementContext> GetElementContextEnumerable()
175+
public IEnumerable<AttachedShadowElementContext> EnumerateElementContexts()
176176
{
177177
foreach (var kvp in ShadowElementContextTable)
178178
{

Microsoft.Toolkit.Uwp.UI/Shadows/AttachedShadowElementContext.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,35 +268,35 @@ public T RemoveAndDisposeResource<T>(string key)
268268
/// </summary>
269269
/// <typeparam name="T">The type of the resource being added.</typeparam>
270270
/// <returns>The resource that was added</returns>
271-
public T AddResource<T>(TypedResourceKey<T> key, T resource) => AddResource(key.Key, resource);
271+
internal T AddResource<T>(TypedResourceKey<T> key, T resource) => AddResource(key.Key, resource);
272272

273273
/// <summary>
274274
/// Retrieves a resource with the specified key and type if it exists
275275
/// </summary>
276276
/// <typeparam name="T">The type of the resource being retrieved.</typeparam>
277277
/// <returns>True if the resource exists, false otherwise</returns>
278-
public bool TryGetResource<T>(TypedResourceKey<T> key, out T resource) => TryGetResource(key.Key, out resource);
278+
internal bool TryGetResource<T>(TypedResourceKey<T> key, out T resource) => TryGetResource(key.Key, out resource);
279279

280280
/// <summary>
281281
/// Retries a resource with the specified key and type
282282
/// </summary>
283283
/// <typeparam name="T">The type of the resource being retrieved.</typeparam>
284284
/// <returns>The resource if it exists or a default value.</returns>
285-
public T GetResource<T>(TypedResourceKey<T> key) => GetResource<T>(key.Key);
285+
internal T GetResource<T>(TypedResourceKey<T> key) => GetResource<T>(key.Key);
286286

287287
/// <summary>
288288
/// Removes an existing resource with the specified key and type
289289
/// </summary>
290290
/// <typeparam name="T">The type of the resource being removed.</typeparam>
291291
/// <returns>The resource that was removed, if any</returns>
292-
public T RemoveResource<T>(TypedResourceKey<T> key) => RemoveResource<T>(key.Key);
292+
internal T RemoveResource<T>(TypedResourceKey<T> key) => RemoveResource<T>(key.Key);
293293

294294
/// <summary>
295295
/// Removes an existing resource with the specified key and type, and <see cref="IDisposable.Dispose">disposes</see> it
296296
/// </summary>
297297
/// <typeparam name="T">The type of the resource being removed.</typeparam>
298298
/// <returns>The resource that was removed, if any</returns>
299-
public T RemoveAndDisposeResource<T>(TypedResourceKey<T> key)
299+
internal T RemoveAndDisposeResource<T>(TypedResourceKey<T> key)
300300
where T : IDisposable => RemoveAndDisposeResource<T>(key.Key);
301301

302302
/// <summary>

Microsoft.Toolkit.Uwp.UI/Shadows/IAttachedShadow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ public interface IAttachedShadow
4545
/// Gets an enumeration over the current list of <see cref="AttachedShadowElementContext"/> of elements using this shared shadow definition.
4646
/// </summary>
4747
/// <returns>Enumeration of <see cref="AttachedShadowElementContext"/> objects.</returns>
48-
IEnumerable<AttachedShadowElementContext> GetElementContextEnumerable();
48+
IEnumerable<AttachedShadowElementContext> EnumerateElementContexts();
4949
}
5050
}

Microsoft.Toolkit/TypedResourceKey.cs renamed to Microsoft.Toolkit.Uwp.UI/Shadows/TypedResourceKey.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
using System;
66

7-
namespace Microsoft.Toolkit
7+
namespace Microsoft.Toolkit.Uwp.UI
88
{
99
/// <summary>
1010
/// A generic class that can be used to retrieve keyed resources of the specified type.
1111
/// </summary>
1212
/// <typeparam name="TValue">The <see cref="Type"/> of resource the <see cref="TypedResourceKey{TValue}"/> will retrieve.</typeparam>
13-
public class TypedResourceKey<TValue>
13+
internal sealed class TypedResourceKey<TValue>
1414
{
1515
/// <summary>
1616
/// Initializes a new instance of the <see cref="TypedResourceKey{TValue}"/> class with the specified key.

0 commit comments

Comments
 (0)