From 1d89461e8ff08f4b1aabef421b38a0a2428542ea Mon Sep 17 00:00:00 2001 From: Jens-Christian Skibakk Date: Thu, 19 Dec 2024 19:12:50 +0100 Subject: [PATCH 01/39] Fix bug: Support for arrays in IsListNotNullOrEmptyConverter/IsListNotNullOrEmptyConverter (#2396) * Update IsListNotNullOrEmptyConverter tests and method Modified IsListNotNullOrEmptyConverterTests: - Empty List now returns true. - Added empty array (Array.Empty()) returning true. - List with "TestValue" now returns false. - Null value now returns true. - Enumerable.Range(1, 3) now returns false. Added new test cases: - Empty array (Array.Empty()) returning true. - Array with "TestValue" returning false. Updated IsListNullOrEmpty method: - Check if enumerator is IDisposable before disposing. * Fix tests --------- Co-authored-by: Jens-Christian Skibakk --- .../Converters/IsListNotNullOrEmptyConverterTests.cs | 12 +++++++++++- .../Converters/IsListNullOrEmptyConverterTests.cs | 12 +++++++++++- .../Converters/IsListNullOrEmptyConverter.shared.cs | 6 +++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/CommunityToolkit.Maui.UnitTests/Converters/IsListNotNullOrEmptyConverterTests.cs b/src/CommunityToolkit.Maui.UnitTests/Converters/IsListNotNullOrEmptyConverterTests.cs index 546bd8c519..5099196573 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Converters/IsListNotNullOrEmptyConverterTests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Converters/IsListNotNullOrEmptyConverterTests.cs @@ -12,6 +12,9 @@ public class IsListNotNullOrEmptyConverterTests : BaseOneWayConverterTest(), false }, + { + Array.Empty(), false + }, { new List { @@ -19,12 +22,19 @@ public class IsListNotNullOrEmptyConverterTests : BaseOneWayConverterTest(), true }, + { + Array.Empty(), true + }, { new List { @@ -19,12 +22,19 @@ public class IsListNullOrEmptyConverterTests : BaseOneWayConverterTest Date: Thu, 19 Dec 2024 13:26:47 -0800 Subject: [PATCH 02/39] Fix ObservableProperties error: mvvmtk0045 (#2399) * Fix ObservableProperties * Resolve null dereference * Bump `CommunityToolkitSampleApp_Xcode_Version` to 16.2 --------- Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com> --- azure-pipelines.yml | 2 +- .../Views/CameraView/CameraViewViewModel.cs | 14 +++++++++++++- .../Views/Popup/MauiPopup.macios.cs | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7e30ed19e3..d0b7e1583a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -28,7 +28,7 @@ variables: PathToCommunityToolkitAnalyzersUnitTestCsproj: 'src/CommunityToolkit.Maui.Analyzers.UnitTests/CommunityToolkit.Maui.Analyzers.UnitTests.csproj' PathToCommunityToolkitAnalyzersBenchmarkCsproj: 'src/CommunityToolkit.Maui.Analyzers.Benchmarks/CommunityToolkit.Maui.Analyzers.Benchmarks.csproj' DotNetMauiRollbackFile: 'https://maui.blob.core.windows.net/metadata/rollbacks/8.0.6.json' - CommunityToolkitSampleApp_Xcode_Version: '16.1' + CommunityToolkitSampleApp_Xcode_Version: '16.2' CommunityToolkitLibrary_Xcode_Version: '16.1' trigger: diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/CameraView/CameraViewViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/CameraView/CameraViewViewModel.cs index d3e9c3a432..1520ed8017 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/CameraView/CameraViewViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/CameraView/CameraViewViewModel.cs @@ -20,7 +20,19 @@ public partial class CameraViewViewModel(ICameraProvider cameraProvider) : BaseV public partial float CurrentZoom { get; set; } [ObservableProperty] - string cameraNameText = "", zoomRangeText = "", currentZoomText = "", flashModeText = "", resolutionText = ""; + public partial string CameraNameText { get; set; } = string.Empty; + + [ObservableProperty] + public partial string ZoomRangeText { get; set; } = string.Empty; + + [ObservableProperty] + public partial string CurrentZoomText { get; set; } = string.Empty; + + [ObservableProperty] + public partial string FlashModeText { get; set; } = string.Empty; + + [ObservableProperty] + public partial string ResolutionText { get; set; } = string.Empty; public IReadOnlyList Cameras => cameraProvider?.AvailableCameras ?? []; diff --git a/src/CommunityToolkit.Maui.Core/Views/Popup/MauiPopup.macios.cs b/src/CommunityToolkit.Maui.Core/Views/Popup/MauiPopup.macios.cs index c6061660a0..b93f426cbe 100644 --- a/src/CommunityToolkit.Maui.Core/Views/Popup/MauiPopup.macios.cs +++ b/src/CommunityToolkit.Maui.Core/Views/Popup/MauiPopup.macios.cs @@ -42,6 +42,7 @@ public override void ViewDidLayoutSubviews() base.ViewDidLayoutSubviews(); _ = View ?? throw new InvalidOperationException($"{nameof(View)} cannot be null."); + _ = View.Superview ?? throw new InvalidOperationException($"{nameof(View.Superview)} cannot be null."); View.Superview.Layer.CornerRadius = 0.0f; View.Superview.Layer.MasksToBounds = false; @@ -115,7 +116,7 @@ public void SetElement(IPopup element) } /// - /// Method to CleanUp the resources of the . + /// Method to clean up the resources of the . /// public void CleanUp() { From be16c67978f277e25041e8e755108421e14bea00 Mon Sep 17 00:00:00 2001 From: James Crutchley Date: Thu, 19 Dec 2024 13:46:43 -0800 Subject: [PATCH 03/39] Fix mvvmtk0045 warnings for `SpeechToTextViewModel` (#2402) Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com> --- .../ViewModels/Essentials/SpeechToTextViewModel.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/SpeechToTextViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/SpeechToTextViewModel.cs index 8e30cf1cd9..6ae0f3b8a4 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/SpeechToTextViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/SpeechToTextViewModel.cs @@ -24,13 +24,13 @@ public partial class SpeechToTextViewModel : BaseViewModel public partial string? RecognitionText { get; set; } = "Welcome to .NET MAUI Community Toolkit!"; [ObservableProperty, NotifyCanExecuteChangedFor(nameof(ListenCommand))] - bool canListenExecute = true; + public partial bool CanListenExecute { get; set; } = true; [ObservableProperty, NotifyCanExecuteChangedFor(nameof(StartListenCommand))] - bool canStartListenExecute = true; + public partial bool CanStartListenExecute { get; set; } = true; [ObservableProperty, NotifyCanExecuteChangedFor(nameof(StopListenCommand))] - bool canStopListenExecute = false; + public partial bool CanStopListenExecute { get; set; } = false; public SpeechToTextViewModel(ITextToSpeech textToSpeech, ISpeechToText speechToText) { From 1bcee8c054a09c79cc7b8fef36b0df08d50e5425 Mon Sep 17 00:00:00 2001 From: James Crutchley Date: Thu, 19 Dec 2024 14:04:04 -0800 Subject: [PATCH 04/39] Fix mvvmtk0045 warnings for `VariableMultiValueConverterViewModel` (#2401) Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com> --- .../VariableMultiValueConverterViewModel.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/VariableMultiValueConverterViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/VariableMultiValueConverterViewModel.cs index ec84d4ffd6..a9ee805be6 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/VariableMultiValueConverterViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/VariableMultiValueConverterViewModel.cs @@ -5,6 +5,26 @@ namespace CommunityToolkit.Maui.Sample.ViewModels.Converters; public partial class VariableMultiValueConverterViewModel : BaseViewModel { [ObservableProperty] - bool isAllGroupSwitch1On, isAllGroupSwitch2On, isAnyGroupSwitch1On, isAnyGroupSwitch2On, - isGreaterThanGroupSwitch1On, isGreaterThanGroupSwitch2On, isGreaterThanGroupSwitch3On, isGreaterThanGroupSwitch4On; + public partial bool IsAllGroupSwitch1On { get; set; } + + [ObservableProperty] + public partial bool IsAllGroupSwitch2On { get; set; } + + [ObservableProperty] + public partial bool IsAnyGroupSwitch1On { get; set; } + + [ObservableProperty] + public partial bool IsAnyGroupSwitch2On { get; set; } + + [ObservableProperty] + public partial bool IsGreaterThanGroupSwitch1On { get; set; } + + [ObservableProperty] + public partial bool IsGreaterThanGroupSwitch2On { get; set; } + + [ObservableProperty] + public partial bool IsGreaterThanGroupSwitch3On { get; set; } + + [ObservableProperty] + public partial bool IsGreaterThanGroupSwitch4On { get; set; } } \ No newline at end of file From b01a18dcef03f955523b8ec71a3f02ec98c96824 Mon Sep 17 00:00:00 2001 From: James Crutchley Date: Thu, 19 Dec 2024 14:20:40 -0800 Subject: [PATCH 05/39] Fix mvvmtk0045 warning for `StateContainerViewModel` (#2400) Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com> --- .../Layouts/StateContainerViewModel.cs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Layouts/StateContainerViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Layouts/StateContainerViewModel.cs index 6253d3faf6..dd083184ea 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Layouts/StateContainerViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Layouts/StateContainerViewModel.cs @@ -6,16 +6,28 @@ namespace CommunityToolkit.Maui.Sample.ViewModels.Layouts; public partial class StateContainerViewModel : BaseViewModel { [ObservableProperty] - string? currentState, gridState, noAnimateState, notFoundState, fullPageState; + public partial string? CurrentState { get; set; } + + [ObservableProperty] + public partial string? GridState { get; set; } + + [ObservableProperty] + public partial string? NoAnimateState { get; set; } + + [ObservableProperty] + public partial string? NotFoundState { get; set; } + + [ObservableProperty] + public partial string? FullPageState { get; set; } [ObservableProperty, NotifyCanExecuteChangedFor(nameof(ToggleGridStateCommand))] - bool canGridStateChange = true; + public partial bool CanGridStateChange { get; set; } = true; [ObservableProperty, NotifyCanExecuteChangedFor(nameof(CycleStatesCommand))] - bool canCycleStateChange = true; + public partial bool CanCycleStateChange { get; set; } = true; [ObservableProperty, NotifyCanExecuteChangedFor(nameof(ToggleFullPageStateCommand))] - bool canFullPageStateChange = true; + public partial bool CanFullPageStateChange { get; set; } = true; [ObservableProperty] public partial bool CanAnimationStateChange { get; set; } = true; From 4766a1492fba0519bb101f961aa9c98fb8e40447 Mon Sep 17 00:00:00 2001 From: matt-bartholomew <148586208+matt-bartholomew@users.noreply.github.com> Date: Tue, 24 Dec 2024 15:16:55 -0500 Subject: [PATCH 06/39] change to ResetValidationTokenSource to guard against a disposed validationTokenSource (#2344) * change to ResetValidationTokenSource to guard against a disposed validationTokenSource * add .Dispose() after cancel() --------- Co-authored-by: Pedro Jesus Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com> --- .../Validators/ValidationBehavior.shared.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs b/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs index 4b5f6a000a..797ccdd884 100644 --- a/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs +++ b/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs @@ -419,8 +419,16 @@ void UpdateStyle(in VisualElement view, bool isValid) void ResetValidationTokenSource(CancellationTokenSource? newTokenSource) { - validationTokenSource?.Cancel(); - validationTokenSource = newTokenSource; + try + { + validationTokenSource?.Cancel(); + validationTokenSource?.Dispose(); + } + catch (ObjectDisposedException) { } + finally + { + validationTokenSource = newTokenSource; + } } } From e97b4a631ff9e3fc592bf1e3858beb3e32bc7938 Mon Sep 17 00:00:00 2001 From: James Crutchley Date: Tue, 24 Dec 2024 12:40:58 -0800 Subject: [PATCH 07/39] Fix mvvmtk0045 and XC0045 warnings (#2403) * Fix mvvmtk0045 warnings Fix XamlC warning XC0045 Value not found * Fix incorrect initial bool values * Update formatting * Update Formatting * Update CustomSizeAndPositionPopupViewModel.cs --------- Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com> --- .../IndexToArrayItemConverterPage.xaml | 4 +-- .../Essentials/SpeechToTextViewModel.cs | 24 +++++++------- .../Views/CameraView/CameraViewViewModel.cs | 14 ++++---- .../CustomSizeAndPositionPopupViewModel.cs | 33 ++++++++++++++++--- 4 files changed, 50 insertions(+), 25 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Converters/IndexToArrayItemConverterPage.xaml b/samples/CommunityToolkit.Maui.Sample/Pages/Converters/IndexToArrayItemConverterPage.xaml index 19f3d0ca65..af9c14dcf1 100644 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Converters/IndexToArrayItemConverterPage.xaml +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Converters/IndexToArrayItemConverterPage.xaml @@ -45,8 +45,8 @@ Grid.Column="0" Grid.Row="2"/> -