diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Essentials/SpeechToTextPage.xaml b/samples/CommunityToolkit.Maui.Sample/Pages/Essentials/SpeechToTextPage.xaml index 58d5726d9..f1e425a53 100644 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Essentials/SpeechToTextPage.xaml +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Essentials/SpeechToTextPage.xaml @@ -1,4 +1,4 @@ - + + + + + + + + + \ No newline at end of file diff --git a/samples/CommunityToolkit.Maui.Sample/Views/Popups/XamlBindingPopup.xaml b/samples/CommunityToolkit.Maui.Sample/Views/Popups/XamlBindingPopup.xaml index d19a4a687..fe522769c 100644 --- a/samples/CommunityToolkit.Maui.Sample/Views/Popups/XamlBindingPopup.xaml +++ b/samples/CommunityToolkit.Maui.Sample/Views/Popups/XamlBindingPopup.xaml @@ -1,4 +1,4 @@ - + children = Enumerable.Empty().ToList(); + readonly WeakReference anchorViewReference = new(null); + readonly WeakReference containerReference = new(null); /// /// Parent UIView @@ -22,19 +24,27 @@ public class AlertView : UIView public FrozenSet Children => children.ToFrozenSet(); /// - /// on which Alert will appear. When null, will appear at bottom of screen. + /// /// - public UIView? AnchorView { get; set; } + public AlertViewVisualOptions VisualOptions { get; } = new(); /// - /// + /// on which Alert will appear. When null, will appear at bottom of screen. /// - public AlertViewVisualOptions VisualOptions { get; } = new(); + public UIView? AnchorView + { + get => anchorViewReference.TryGetTarget(out var anchorView) ? anchorView : null; + set => anchorViewReference.SetTarget(value); + } /// /// Container of /// - protected UIStackView? Container { get; set; } + protected UIStackView? Container + { + get => containerReference.TryGetTarget(out var container) ? container : null; + set => containerReference.SetTarget(value); + } /// /// Dismisses the Popup from the screen diff --git a/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.android.cs b/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.android.cs index 1371cd936..564c58170 100644 --- a/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.android.cs +++ b/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.android.cs @@ -3,10 +3,6 @@ using Android.Views; using CommunityToolkit.Maui.Core.Extensions; using Microsoft.Maui.Platform; -using AColor = Android.Graphics.Color; -using APaint = Android.Graphics.Paint; -using APath = Android.Graphics.Path; -using AView = Android.Views.View; namespace CommunityToolkit.Maui.Core.Views; @@ -26,6 +22,7 @@ protected override void Dispose(bool disposing) if (disposing) { currentPath.Dispose(); + proxy?.Dispose(); } base.Dispose(disposing); @@ -80,7 +77,7 @@ public override bool OnTouchEvent(MotionEvent? e) public void Initialize() { Drawable = new DrawingViewDrawable(this); - Lines.CollectionChanged += OnLinesCollectionChanged; + proxy = new(this); } void Redraw() diff --git a/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.macios.cs b/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.macios.cs index 6c1bbd5c9..12c3dc4f2 100644 --- a/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.macios.cs +++ b/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.macios.cs @@ -49,7 +49,7 @@ public override void TouchesCancelled(NSSet touches, UIEvent? evt) public void Initialize() { Drawable = new DrawingViewDrawable(this); - Lines.CollectionChanged += OnLinesCollectionChanged; + proxy = new(this); } /// @@ -58,6 +58,7 @@ protected override void Dispose(bool disposing) if (disposing) { currentPath.Dispose(); + proxy?.Dispose(); } base.Dispose(disposing); diff --git a/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.shared.cs b/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.shared.cs index da5c1c2af..bc3940573 100644 --- a/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.shared.cs +++ b/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.shared.cs @@ -1,4 +1,4 @@ -using System.Collections.ObjectModel; +using System.Collections.ObjectModel; using CommunityToolkit.Maui.Core.Extensions; namespace CommunityToolkit.Maui.Core.Views; @@ -9,11 +9,13 @@ namespace CommunityToolkit.Maui.Core.Views; public partial class MauiDrawingView { readonly WeakEventManager weakEventManager = new(); + readonly WeakReference?> drawActionReference = new(null); bool isDrawing; PointF previousPoint; PathF currentPath = new(); MauiDrawingLine? currentLine; + MauiDrawingViewProxy? proxy; Paint paint = new SolidPaint(DrawingViewDefaults.BackgroundColor); /// @@ -80,7 +82,11 @@ public event EventHandler Drawing /// /// Used to draw any shape on the canvas /// - public Action? DrawAction { get; set; } + public Action? DrawAction + { + get => drawActionReference.TryGetTarget(out var drawAction) ? drawAction : null; + set => drawActionReference.SetTarget(value); + } /// /// Drawable background @@ -204,7 +210,7 @@ void ClearPath() currentPath = new PathF(); } - class DrawingViewDrawable : IDrawable + sealed class DrawingViewDrawable : IDrawable { readonly MauiDrawingView drawingView; diff --git a/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.tizen.cs b/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.tizen.cs index 772c45099..61d407e05 100644 --- a/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.tizen.cs +++ b/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.tizen.cs @@ -20,7 +20,7 @@ public MauiDrawingView() : base(null) public void Initialize() { Drawable = new DrawingViewDrawable(this); - Lines.CollectionChanged += OnLinesCollectionChanged; + proxy = new(this); } /// @@ -29,6 +29,7 @@ protected override void Dispose(bool disposing) if (disposing) { currentPath.Dispose(); + proxy?.Dispose(); TouchEvent -= OnTouch; } diff --git a/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.windows.cs b/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.windows.cs index f2ad8e071..41445eabc 100644 --- a/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.windows.cs +++ b/src/CommunityToolkit.Maui.Core/Views/DrawingView/PlatformView/MauiDrawingView.windows.cs @@ -30,7 +30,7 @@ public void Initialize() System.Diagnostics.Trace.WriteLine("DrawingView requires Windows 10.0.18362 or higher."); } - Lines.CollectionChanged += OnLinesCollectionChanged; + proxy = new(this); } /// @@ -49,6 +49,7 @@ protected virtual void Dispose(bool disposing) if (disposing) { currentPath.Dispose(); + proxy?.Dispose(); } isDisposed = true; diff --git a/src/CommunityToolkit.Maui.Core/Views/Popup/MauiPopup.macios.cs b/src/CommunityToolkit.Maui.Core/Views/Popup/MauiPopup.macios.cs index df4682586..1a6805e47 100644 --- a/src/CommunityToolkit.Maui.Core/Views/Popup/MauiPopup.macios.cs +++ b/src/CommunityToolkit.Maui.Core/Views/Popup/MauiPopup.macios.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; using Microsoft.Maui.ApplicationModel; using Microsoft.Maui.Handlers; @@ -10,6 +10,7 @@ namespace CommunityToolkit.Maui.Core.Views; public class MauiPopup : UIViewController { readonly IMauiContext mauiContext; + readonly WeakReference viewControllerReference = new(null); /// /// Constructor of . @@ -31,7 +32,11 @@ public MauiPopup(IMauiContext mauiContext) /// public IPopup? VirtualView { get; private set; } - internal UIViewController? ViewController { get; private set; } + internal UIViewController? ViewController + { + get => viewControllerReference.TryGetTarget(out var viewController) ? viewController : null; + set => viewControllerReference.SetTarget(value); + } /// /// Method to update the Popup's size. @@ -207,8 +212,7 @@ void SetView(UIView view, PageHandler control) void SetPresentationController() { - var popOverDelegate = new PopoverDelegate(); - popOverDelegate.PopoverDismissedEvent += HandlePopoverDelegateDismissed; + var popOverDelegate = new PopoverDelegate(this); UIPopoverPresentationController presentationController = (UIPopoverPresentationController)(PresentationController ?? throw new InvalidOperationException($"{nameof(PresentationController)} cannot be null.")); presentationController.SourceView = ViewController?.View ?? throw new InvalidOperationException($"{nameof(ViewController.View)} cannot be null."); @@ -216,13 +220,6 @@ void SetPresentationController() presentationController.Delegate = popOverDelegate; } - [MemberNotNull(nameof(VirtualView))] - void HandlePopoverDelegateDismissed(object? sender, UIPresentationController e) - { - _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} cannot be null."); - VirtualView.Handler?.Invoke(nameof(IPopup.OnDismissedByTappingOutsideOfPopup)); - } - void AddToCurrentPageViewController(UIViewController viewController) { viewController.PresentViewController(this, true, null); @@ -232,12 +229,22 @@ sealed class PopoverDelegate : UIPopoverPresentationControllerDelegate { readonly WeakEventManager popoverDismissedEventManager = new(); + public PopoverDelegate(MauiPopup mauiPopup) + { + this.mauiPopup = new(mauiPopup); + PopoverDismissedEvent += HandlePopoverDelegateDismissed; + } + public event EventHandler PopoverDismissedEvent { add => popoverDismissedEventManager.AddEventHandler(value); remove => popoverDismissedEventManager.RemoveEventHandler(value); } + MauiPopup MauiPopup => mauiPopup.TryGetTarget(out var virtualView) + ? virtualView + : throw new ObjectDisposedException(nameof(MauiPopup)); + public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController) => UIModalPresentationStyle.None; diff --git a/src/CommunityToolkit.Maui.Core/Views/Popup/PopupExtensions.windows.cs b/src/CommunityToolkit.Maui.Core/Views/Popup/PopupExtensions.windows.cs index eb4b9f096..c4e9da01f 100644 --- a/src/CommunityToolkit.Maui.Core/Views/Popup/PopupExtensions.windows.cs +++ b/src/CommunityToolkit.Maui.Core/Views/Popup/PopupExtensions.windows.cs @@ -1,4 +1,4 @@ -using CommunityToolkit.Maui.Core.Handlers; +using CommunityToolkit.Maui.Core.Handlers; using Microsoft.Maui.Platform; using Microsoft.Maui.Primitives; using Microsoft.UI.Xaml; diff --git a/src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj b/src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj index 3377b662c..370e3aa90 100644 --- a/src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj +++ b/src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj @@ -58,6 +58,13 @@ + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + diff --git a/src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.windows.cs b/src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.windows.cs index 6ee0b1c47..ddbb3e5ce 100644 --- a/src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.windows.cs +++ b/src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.windows.cs @@ -1,4 +1,4 @@ -using CommunityToolkit.Maui.Extensions; +using CommunityToolkit.Maui.Extensions; using CommunityToolkit.Maui.Views; using Microsoft.UI; using Microsoft.UI.Windowing; diff --git a/src/CommunityToolkit.Maui.SourceGenerators/Generators/TextColorToGenerator.cs b/src/CommunityToolkit.Maui.SourceGenerators/Generators/TextColorToGenerator.cs index 6ce96bf88..7377cd4a9 100644 --- a/src/CommunityToolkit.Maui.SourceGenerators/Generators/TextColorToGenerator.cs +++ b/src/CommunityToolkit.Maui.SourceGenerators/Generators/TextColorToGenerator.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using System.Text; diff --git a/src/CommunityToolkit.Maui.UnitTests/ImageSources/GravatarImageSource/GravatarImageSourceTests.cs b/src/CommunityToolkit.Maui.UnitTests/ImageSources/GravatarImageSource/GravatarImageSourceTests.cs index 8b4896ef8..9f5210e36 100644 --- a/src/CommunityToolkit.Maui.UnitTests/ImageSources/GravatarImageSource/GravatarImageSourceTests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/ImageSources/GravatarImageSource/GravatarImageSourceTests.cs @@ -1,4 +1,4 @@ -using CommunityToolkit.Maui.ImageSources; +using CommunityToolkit.Maui.ImageSources; using FluentAssertions; using Xunit; diff --git a/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/SelectAllText/SelectAllTextBehavior.macios.cs b/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/SelectAllText/SelectAllTextBehavior.macios.cs index 292ed7d5f..f2b695f4d 100644 --- a/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/SelectAllText/SelectAllTextBehavior.macios.cs +++ b/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/SelectAllText/SelectAllTextBehavior.macios.cs @@ -1,4 +1,4 @@ -using System.Diagnostics; +using System.Diagnostics; using ObjCRuntime; using UIKit; diff --git a/src/CommunityToolkit.Maui/Converters/CompareConverter.shared.cs b/src/CommunityToolkit.Maui/Converters/CompareConverter.shared.cs index 1cdddac76..d15d7b32a 100644 --- a/src/CommunityToolkit.Maui/Converters/CompareConverter.shared.cs +++ b/src/CommunityToolkit.Maui/Converters/CompareConverter.shared.cs @@ -1,4 +1,4 @@ -using System.ComponentModel; +using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Globalization; diff --git a/src/CommunityToolkit.Maui/Views/Popup/Popup.shared.cs b/src/CommunityToolkit.Maui/Views/Popup/Popup.shared.cs index 79ca8b987..0514cdf6a 100644 --- a/src/CommunityToolkit.Maui/Views/Popup/Popup.shared.cs +++ b/src/CommunityToolkit.Maui/Views/Popup/Popup.shared.cs @@ -1,4 +1,4 @@ -using CommunityToolkit.Maui.Core; +using CommunityToolkit.Maui.Core; using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Controls.StyleSheets; using LayoutAlignment = Microsoft.Maui.Primitives.LayoutAlignment; diff --git a/src/CommunityToolkit.Maui/Views/Popup/PopupExtensions.shared.cs b/src/CommunityToolkit.Maui/Views/Popup/PopupExtensions.shared.cs index 25586365c..0d7879d67 100644 --- a/src/CommunityToolkit.Maui/Views/Popup/PopupExtensions.shared.cs +++ b/src/CommunityToolkit.Maui/Views/Popup/PopupExtensions.shared.cs @@ -1,4 +1,4 @@ -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; using CommunityToolkit.Maui.Core; using Microsoft.Maui.Controls.Platform; using Microsoft.Maui.Platform;