From e65200b792e46976440068b3a6dd16c02c2e43c2 Mon Sep 17 00:00:00 2001 From: Kym Phillpotts Date: Mon, 4 Sep 2023 21:09:36 +0200 Subject: [PATCH] Bringing touch-effect up to date with main (#1383) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Popup v6 windows (#1086) Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Co-authored-by: Pedro Jesus Co-authored-by: Shaun Lawrence * ♻️ [Housekeeping] Fixed GravatarImageSourceTests.TestDefaultStream (#1335) * [housekeeping] Automated PR to fix formatting errors (#1327) * Fix popup margin on iOS (#1329) * Bump NuGet.Protocol from 6.6.1 to 6.7.0 in /samples (#1330) * Use fully qualified namespace for Color reference in TextToColorGenerator (#1332) * Use fully qualified namespace for Color reference in TextToColorGenerator to prevent collisions This change should prevent "ambiguous reference" error to occur when other packages are included in a MAUI project that provide their own Color objects * added global prefix to be safer --------- Co-authored-by: Pedro Jesus Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com> * Code cleanup and preparation for the next release (breaking changes) (#1324) * Code cleanup and preparation for .net 8 * Update CompareConverter.shared.cs * Revert global.json * More CleanUps * Remove redundant TrySetCanceled and rely on speech recognition result * Update Formatting --------- Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com> * Fix Gestures on Popup on ios (#1342) * Fix Gestures on Popup on ios * don't query type cast directly * Code for AddLogicalChild (.NET 8) * reduce changes * setting the parent fixes the BindingContext of the view * Revert "setting the parent fixes the BindingContext of the view" This reverts commit 0a64b56ca51948bd0596408a14cfadf60c3dde41. * reduce changes * simplify code * fixing build * assigned Element to contentPage.Parent --------- Co-authored-by: pedrojesus * `global.json`: Change `"rollForward": "latestMajor",` -> `"rollForward": "latestFeature"`. (#1338) Update global.json * Bump Microsoft.NET.Test.Sdk from 17.7.0 to 17.7.1 in /samples (#1348) Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.7.0 to 17.7.1. - [Release notes](https://github.com/microsoft/vstest/releases) - [Changelog](https://github.com/microsoft/vstest/blob/main/docs/releases.md) - [Commits](https://github.com/microsoft/vstest/compare/v17.7.0...v17.7.1) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * 632 bug avatar view clipping on windows (#1344) * Resolves issue on Windows where the splash screen icon is not found. * Resolves an issue with the 'Ratings' sample for AvatarView. * Spaces and not tabs * Spaces and not tabs * Changed MauiImage to point to Images folder. * Changed splash for Windows to be Resize=False * Typo in name of MauiImage * Try to prevent locking. * Bump Microsoft.CodeAnalysis from 4.6.0 to 4.7.0 in /samples (#1355) * Bump Microsoft.CodeAnalysis.CSharp.Workspaces from 4.6.0 to 4.7.0 in /samples (#1357) * Bump FluentAssertions from 6.11.0 to 6.12.0 in /samples (#1365) * fix IconTintColorBehavior for Windows (#1370) fix IconTintColorBehavior for windows Co-authored-by: Oleksii * Add `MemoryAnalyzer` roslyn analyzer (#1371) * Add NuGet Package + Update `WarningsAsErrors` * Fix MA0002 * Fix `MauiDrawingView` * Fix `MauiPopup` * Fix Naming * return `null` for nullable references * Use Ternary Operator * `dotnet format` * iOS popup fix with Shell or TabbedPage (#1343) * Fix Issue #1256 Better fix * Fixed Popup on Multiple Level Pages (#822) --------- Co-authored-by: Vladislav Antonyuk <33021114+VladislavAntonyuk@users.noreply.github.com> Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com> * [housekeeping] Automated PR to fix formatting errors (#1373) * Bump Microsoft.NET.Test.Sdk from 17.7.1 to 17.7.2 in /samples (#1378) --------- Signed-off-by: dependabot[bot] Co-authored-by: Vladislav Antonyuk <33021114+VladislavAntonyuk@users.noreply.github.com> Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Co-authored-by: Pedro Jesus Co-authored-by: Shaun Lawrence Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: cat0363 <125236133+cat0363@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wolf <132034537+wolfgang-ironsoftware@users.noreply.github.com> Co-authored-by: Thomas Stocker Co-authored-by: George Leithead Co-authored-by: Sokol2001 <53799292+Sokol2001@users.noreply.github.com> Co-authored-by: Oleksii Co-authored-by: Andrey Onishchenko <100789522+cucumber-sp@users.noreply.github.com> --- .../Pages/Essentials/SpeechToTextPage.xaml | 2 +- .../Pages/Views/Popup/PopupPositionPage.xaml | 2 +- .../Popup/ShowPopupInOnAppearingPage.xaml.cs | 2 +- .../Resources/Images/splash.svg | 8 +++++ .../Views/Popups/XamlBindingPopup.xaml | 2 +- .../Handlers/Popup/PopUpHandler.windows.cs | 2 +- .../Views/Alert/AlertView.macios.cs | 20 +++++++++---- .../PlatformView/MauiDrawingView.android.cs | 7 ++--- .../PlatformView/MauiDrawingView.macios.cs | 3 +- .../PlatformView/MauiDrawingView.shared.cs | 12 ++++++-- .../PlatformView/MauiDrawingView.tizen.cs | 3 +- .../PlatformView/MauiDrawingView.windows.cs | 3 +- .../Views/Popup/MauiPopup.macios.cs | 29 ++++++++++++------- .../Views/Popup/PopupExtensions.windows.cs | 2 +- .../CommunityToolkit.Maui.MediaElement.csproj | 7 +++++ .../Views/MauiMediaElement.windows.cs | 2 +- .../Generators/TextColorToGenerator.cs | 2 +- .../GravatarImageSourceTests.cs | 2 +- .../SelectAllTextBehavior.macios.cs | 2 +- .../Converters/CompareConverter.shared.cs | 2 +- .../Views/Popup/Popup.shared.cs | 2 +- .../Views/Popup/PopupExtensions.shared.cs | 2 +- 22 files changed, 78 insertions(+), 40 deletions(-) create mode 100644 samples/CommunityToolkit.Maui.Sample/Resources/Images/splash.svg diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Essentials/SpeechToTextPage.xaml b/samples/CommunityToolkit.Maui.Sample/Pages/Essentials/SpeechToTextPage.xaml index 58d5726d9c..f1e425a533 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 d19a4a687a..fe522769cb 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 1371cd936d..564c581707 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 6c1bbd5c93..12c3dc4f25 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 da5c1c2afe..bc3940573b 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 772c45099b..61d407e058 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 f2ad8e0717..41445eabcd 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 df46825863..1a6805e47e 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 eb4b9f0964..c4e9da01fb 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 3377b662c1..370e3aa905 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 6ee0b1c47e..ddbb3e5cea 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 6ce96bf88a..7377cd4a9f 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 8b4896ef8f..9f5210e36a 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 292ed7d5f3..f2b695f4d8 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 1cdddac76e..d15d7b32a6 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 79ca8b987b..0514cdf6a2 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 25586365c8..0d7879d673 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;