diff --git a/src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.Android.cs index a16a541f54ff..e087b12bb3fc 100644 --- a/src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.Android.cs +++ b/src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.Android.cs @@ -10,5 +10,14 @@ public partial class BoxViewTests { MauiShapeView GetNativeBoxView(ShapeViewHandler boxViewViewHandler) => boxViewViewHandler.PlatformView; + + Task GetPlatformOpacity(ShapeViewHandler handler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetNativeBoxView(handler); + return nativeView.Alpha; + }); + } } } \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.Windows.cs index 526aed50725a..994e01829fd3 100644 --- a/src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.Windows.cs +++ b/src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.Windows.cs @@ -10,5 +10,14 @@ public partial class BoxViewTests { W2DGraphicsView GetNativeBoxView(ShapeViewHandler boxViewHandler) => boxViewHandler.PlatformView; + + Task GetPlatformOpacity(ShapeViewHandler handler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetNativeBoxView(handler); + return (float)nativeView.Opacity; + }); + } } } \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.cs b/src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.cs index 5703a964359f..e6a20ffb1bcb 100644 --- a/src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.Diagnostics; using System.Threading.Tasks; using Microsoft.Maui.Controls; using Microsoft.Maui.Graphics; @@ -45,5 +46,23 @@ public async Task BoxViewBackgroundColorConsistent() await ValidateHasColor(boxView, expected, typeof(ShapeViewHandler)); } + + [Fact] + [Description("The Opacity property of a BoxView should match with native Opacity")] + public async Task VerifyBoxViewOpacityProperty() + { + var boxView = new BoxView + { + Opacity = 0.35f + }; + var expectedValue = boxView.Opacity; + + var handler = await CreateHandlerAsync(boxView); + await InvokeOnMainThreadAsync(async () => + { + var nativeOpacityValue = await GetPlatformOpacity(handler); + Assert.Equal(expectedValue, nativeOpacityValue); + }); + } } } \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.iOS.cs index 4146023aab2c..67c5fbc701a5 100644 --- a/src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.iOS.cs @@ -15,6 +15,15 @@ public partial class BoxViewTests MauiShapeView GetNativeBoxView(ShapeViewHandler boxViewHandler) => boxViewHandler.PlatformView; + Task GetPlatformOpacity(ShapeViewHandler handler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetNativeBoxView(handler); + return (float)nativeView.Alpha; + }); + } + [Fact(DisplayName = "ShapeView Parts Keep Around")] public async Task ShapeViewPartsKeepAround() { diff --git a/src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.Android.cs index 954910381092..b8b71fead772 100644 --- a/src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.Android.cs +++ b/src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.Android.cs @@ -1,5 +1,6 @@ #nullable enable using System; +using System.ComponentModel; using System.Threading.Tasks; using AndroidX.AppCompat.Widget; using AndroidX.Core.Widget; @@ -24,6 +25,14 @@ AppCompatButton GetPlatformButton(ButtonHandler buttonHandler) => Android.Text.TextUtils.TruncateAt? GetPlatformLineBreakMode(ButtonHandler buttonHandler) => GetPlatformButton(buttonHandler).Ellipsize; + Task GetPlatformOpacity(ButtonHandler buttonHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformButton(buttonHandler); + return nativeView.Alpha; + }); + } [Theory(DisplayName = "Button Icon has Correct Position"), Category(TestCategory.Layout)] [InlineData(Button.ButtonContentLayout.ImagePosition.Left)] @@ -81,5 +90,22 @@ await CreateHandlerAndAddToWindow(page, () => }); } + [Fact] + [Description("The Opacity property of a Button should match with native Opacity")] + public async Task VerifyButtonOpacityProperty() + { + var button = new Button + { + Opacity = 0.35f + }; + var expectedValue = button.Opacity; + + var handler = await CreateHandlerAsync(button); + await InvokeOnMainThreadAsync(async () => + { + var nativeOpacityValue = await GetPlatformOpacity(handler); + Assert.Equal(expectedValue, nativeOpacityValue); + }); + } } } diff --git a/src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.Windows.cs index 072fdb916260..e3029fe05cd2 100644 --- a/src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.Windows.cs +++ b/src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.Windows.cs @@ -4,6 +4,8 @@ using Microsoft.Maui.Platform; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using System.ComponentModel; +using Xunit; namespace Microsoft.Maui.DeviceTests { @@ -19,5 +21,32 @@ Button GetPlatformButton(ButtonHandler buttonHandler) => TextTrimming GetPlatformLineBreakMode(ButtonHandler buttonHandler) => (GetPlatformButton(buttonHandler).Content as FrameworkElement)!.GetFirstDescendant()!.TextTrimming; + + Task GetPlatformOpacity(ButtonHandler buttonHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformButton(buttonHandler); + return (float)nativeView.Opacity; + }); + } + + [Fact] + [Description("The Opacity property of a Button should match with native Opacity")] + public async Task VerifyButtonOpacityProperty() + { + var button = new Microsoft.Maui.Controls.Button + { + Opacity = 0.35f + }; + var expectedValue = button.Opacity; + + var handler = await CreateHandlerAsync(button); + await InvokeOnMainThreadAsync(async () => + { + var nativeOpacityValue = await GetPlatformOpacity(handler); + Assert.Equal(expectedValue, nativeOpacityValue); + }); + } } } diff --git a/src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.cs b/src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.cs index e5c287b24353..d0ca13d84f3d 100644 --- a/src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.cs @@ -70,6 +70,5 @@ public async Task ButtonBackgroundColorConsistent() await ValidateHasColor(button, expected, typeof(ButtonHandler)); } - } } \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.Android.cs index 900c1889399c..dd8faaa342a8 100644 --- a/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.Android.cs +++ b/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.Android.cs @@ -13,5 +13,14 @@ public partial class CheckBoxTests { AppCompatCheckBox GetNativeCheckBox(CheckBoxHandler checkBoxHandler) => checkBoxHandler.PlatformView; + + Task GetPlatformOpacity(CheckBoxHandler CheckBoxHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetNativeCheckBox(CheckBoxHandler); + return nativeView.Alpha; + }); + } } } \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.Windows.cs index 2a038c567052..e291d1855621 100644 --- a/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.Windows.cs +++ b/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.Windows.cs @@ -10,5 +10,14 @@ public partial class CheckBoxTests { CheckBox GetNativeCheckBox(CheckBoxHandler checkBoxHandler) => checkBoxHandler.PlatformView; + + Task GetPlatformOpacity(CheckBoxHandler checkBoxHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetNativeCheckBox(checkBoxHandler); + return (float)nativeView.Opacity; + }); + } } } diff --git a/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.cs b/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.cs index 816ee52b0317..be8021a5bc6c 100644 --- a/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.cs @@ -5,6 +5,7 @@ using Microsoft.Maui.Handlers; using Microsoft.Maui.Hosting; using Xunit; +using System.ComponentModel; namespace Microsoft.Maui.DeviceTests { @@ -43,5 +44,23 @@ public async Task UpdatingCheckBoxBackgroundColorUpdatesBackground(string colorS await ValidateHasColor(checkBox, color); } + + [Fact] + [Description("The Opacity property of a CheckBox should match with native Opacity")] + public async Task VerifyCheckBoxOpacityProperty() + { + var checkBox = new CheckBox + { + Opacity = 0.35f + }; + var expectedValue = checkBox.Opacity; + + var handler = await CreateHandlerAsync(checkBox); + await InvokeOnMainThreadAsync(async () => + { + var nativeOpacityValue = await GetPlatformOpacity(handler); + Assert.Equal(expectedValue, nativeOpacityValue); + }); + } } } \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.iOS.cs index 112ca8b29faa..879dcfbab6e8 100644 --- a/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.iOS.cs @@ -12,5 +12,14 @@ public partial class CheckBoxTests { MauiCheckBox GetNativeCheckBox(CheckBoxHandler checkBoxHandler) => checkBoxHandler.PlatformView; + + Task GetPlatformOpacity(CheckBoxHandler checkBoxHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetNativeCheckBox(checkBoxHandler); + return (float)nativeView.Alpha; + }); + } } } \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Android.cs index 0be22351a23d..b4fe33fd2a21 100644 --- a/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Android.cs +++ b/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Android.cs @@ -40,6 +40,15 @@ static int GetPlatformSelectionLength(EditorHandler editorHandler) return -1; } + Task GetPlatformOpacity(EditorHandler editorHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformControl(editorHandler); + return nativeView.Alpha; + }); + } + [Fact] public async Task CursorPositionPreservedWhenTextTransformPresent() { diff --git a/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Windows.cs index 6d0340628605..13608fe74373 100644 --- a/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Windows.cs +++ b/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Windows.cs @@ -15,6 +15,15 @@ static Task GetPlatformText(EditorHandler handler) return InvokeOnMainThreadAsync(() => GetPlatformControl(handler).Text); } + Task GetPlatformOpacity(EditorHandler editorHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformControl(editorHandler); + return (float)nativeView.Opacity; + }); + } + static void SetPlatformText(EditorHandler editorHandler, string text) => GetPlatformControl(editorHandler).Text = text; diff --git a/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.cs b/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.cs index 70d9cc9d1af9..8860d5b8f41b 100644 --- a/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.cs @@ -291,6 +291,24 @@ await InvokeOnMainThreadAsync(() => } #endif + [Fact] + [Description("The Opacity property of a Editor should match with native Opacity")] + public async Task VerifyEditorOpacityProperty() + { + var editor = new Editor + { + Opacity = 0.35f + }; + var expectedValue = editor.Opacity; + + var handler = await CreateHandlerAsync(editor); + await InvokeOnMainThreadAsync(async () => + { + var nativeOpacityValue = await GetPlatformOpacity(handler); + Assert.Equal(expectedValue, nativeOpacityValue); + }); + } + [Category(TestCategory.Editor)] [Category(TestCategory.TextInput)] [Collection(RunInNewWindowCollection)] diff --git a/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.iOS.cs index 4a71b39e43e1..46de2e3bcbb9 100644 --- a/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.iOS.cs @@ -43,6 +43,15 @@ static int GetPlatformSelectionLength(EditorHandler editorHandler) return -1; } + Task GetPlatformOpacity(EditorHandler editorHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformControl(editorHandler); + return (float)nativeView.Alpha; + }); + } + [Category(TestCategory.Editor)] public class PlaceholderTests : ControlsHandlerTestBase { diff --git a/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.Android.cs index fb042691e062..bac4eaa334fe 100644 --- a/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.Android.cs +++ b/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.Android.cs @@ -39,6 +39,15 @@ static int GetPlatformSelectionLength(EntryHandler entryHandler) return -1; } + Task GetPlatformOpacity(EntryHandler entryHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformControl(entryHandler); + return nativeView.Alpha; + }); + } + [Fact] public async Task CursorPositionPreservedWhenTextTransformPresent() { diff --git a/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.Windows.cs index 341b96eb0ae5..6beb820d3d19 100644 --- a/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.Windows.cs +++ b/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.Windows.cs @@ -15,6 +15,15 @@ static Task GetPlatformText(EntryHandler handler) return InvokeOnMainThreadAsync(() => GetPlatformControl(handler).Text); } + Task GetPlatformOpacity(EntryHandler entryHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformControl(entryHandler); + return (float)nativeView.Opacity; + }); + } + static void SetPlatformText(EntryHandler entryHandler, string text) => GetPlatformControl(entryHandler).Text = text; diff --git a/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.cs b/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.cs index 0ce43610089d..8e62d81c37ed 100644 --- a/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.cs @@ -204,6 +204,24 @@ public async Task EntryBackgroundColorConsistent() await ValidateHasColor(entry, expected, typeof(EntryHandler)); } + [Fact] + [Description("The Opacity property of an Entry should match with native Opacity")] + public async Task VerifyEntryOpacityProperty() + { + var entry = new Entry + { + Opacity = 0.35f + }; + var expectedValue = entry.Opacity; + + var handler = await CreateHandlerAsync(entry); + await InvokeOnMainThreadAsync(async () => + { + var nativeOpacityValue = await GetPlatformOpacity(handler); + Assert.Equal(expectedValue, nativeOpacityValue); + }); + } + [Category(TestCategory.Entry)] [Category(TestCategory.TextInput)] [Collection(RunInNewWindowCollection)] diff --git a/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.iOS.cs index ca80bbf47394..a4ce142a1145 100644 --- a/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.iOS.cs @@ -44,6 +44,15 @@ static int GetPlatformSelectionLength(EntryHandler entryHandler) return -1; } + + Task GetPlatformOpacity(EntryHandler entryHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformControl(entryHandler); + return (float)nativeView.Alpha; + }); + } [Collection(ControlsHandlerTestBase.RunInNewWindowCollection)] public class ScrollTests : ControlsHandlerTestBase diff --git a/src/Controls/tests/DeviceTests/Elements/Image/ImageTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/Image/ImageTests.Android.cs index cc40a90c2b56..2a5f40c37ba2 100644 --- a/src/Controls/tests/DeviceTests/Elements/Image/ImageTests.Android.cs +++ b/src/Controls/tests/DeviceTests/Elements/Image/ImageTests.Android.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Android.Graphics.Drawables; +using Android.Widget; using Microsoft.Maui.Controls; using Microsoft.Maui.Graphics; using Microsoft.Maui.Handlers; @@ -68,6 +70,35 @@ await rootView.AttachAndRun(async () => }); }); } + + [Fact] + [Description("The Opacity property of a image should match with native Opacity")] + public async Task VerifyImageOpacityProperty() + { + var image = new Image + { + Opacity = 0.35f + }; + var expectedValue = image.Opacity; + + var handler = await CreateHandlerAsync(image); + await InvokeOnMainThreadAsync(async () => + { + var nativeOpacityValue = await GetPlatformOpacity(handler); + Assert.Equal(expectedValue, nativeOpacityValue); + }); + } + ImageView GetPlatformImage(ImageHandler imageHandler) => + imageHandler.PlatformView; + + Task GetPlatformOpacity(ImageHandler imageHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformImage(imageHandler); + return (float)nativeView.Alpha; + }); + } } // This subclass of memory stream is deliberately set up to trick Glide into using the cached image diff --git a/src/Controls/tests/DeviceTests/Elements/Image/ImageTests.cs b/src/Controls/tests/DeviceTests/Elements/Image/ImageTests.cs index 9cf3d160b828..0213cb9d8bc6 100644 --- a/src/Controls/tests/DeviceTests/Elements/Image/ImageTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/Image/ImageTests.cs @@ -90,8 +90,6 @@ public async Task ImageBackgroundColorConsistent() }; await ValidateHasColor(image, expected, typeof(ImageHandler)); - } - - + } } } \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/Image/ImageTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Image/ImageTests.iOS.cs index a916ff51e0a0..f06117dcfc02 100644 --- a/src/Controls/tests/DeviceTests/Elements/Image/ImageTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Image/ImageTests.iOS.cs @@ -1,9 +1,11 @@ using System; +using System.ComponentModel; using System.IO; using System.Threading.Tasks; using Microsoft.Maui.Controls; using Microsoft.Maui.Graphics; using Microsoft.Maui.Handlers; +using UIKit; using Xunit; namespace Microsoft.Maui.DeviceTests @@ -151,5 +153,35 @@ await InvokeOnMainThreadAsync(async () => Assert.Equal(100, image.Height); Assert.Equal(200, image.Width); } + + [Fact] + [Description("The Opacity property of a image should match with native Opacity")] + public async Task VerifyImageOpacityProperty() + { + var image = new Image + { + Opacity = 0.35f + }; + var expectedValue = image.Opacity; + + var handler = await CreateHandlerAsync(image); + await InvokeOnMainThreadAsync(async () => + { + var nativeOpacityValue = await GetPlatformOpacity(handler); + Assert.Equal(expectedValue, nativeOpacityValue); + }); + } + UIImageView GetPlatformImage(ImageHandler imageHandler) => + imageHandler.PlatformView; + + Task GetPlatformOpacity(ImageHandler imageHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformImage(imageHandler); + return (float)nativeView.Alpha; + }); + } + } } \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.Android.cs index 22bced4d0afb..d750c7e21143 100644 --- a/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.Android.cs +++ b/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.Android.cs @@ -96,5 +96,14 @@ TextUtils.TruncateAt GetPlatformLineBreakMode(LabelHandler labelHandler) => int GetPlatformMaxLines(LabelHandler labelHandler) => GetPlatformLabel(labelHandler).MaxLines; + + Task GetPlatformOpacity(LabelHandler labelHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformLabel(labelHandler); + return (float)nativeView.Alpha; + }); + } } } \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.Windows.cs index 48b203701698..cc68b57e8a74 100644 --- a/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.Windows.cs +++ b/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.Windows.cs @@ -1,4 +1,5 @@ -using Microsoft.Maui.Handlers; +using System.Threading.Tasks; +using Microsoft.Maui.Handlers; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; @@ -19,5 +20,14 @@ TextTrimming GetPlatformLineBreakMode(LabelHandler labelHandler) => int GetPlatformMaxLines(LabelHandler labelHandler) => GetPlatformLabel(labelHandler).MaxLines; + + Task GetPlatformOpacity(LabelHandler labelHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformLabel(labelHandler); + return (float)nativeView.Opacity; + }); + } } } diff --git a/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.cs b/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.cs index 1bac973e0546..659c3dc00c13 100644 --- a/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.cs @@ -742,6 +742,24 @@ public async Task LabelBackgroundColorConsistent() await ValidateHasColor(label, expected, typeof(LabelHandler)); } + [Fact] + [Description("The Opacity property of a Label should match with native Opacity")] + public async Task VerifyLabelOpacityProperty() + { + var label = new Label + { + Opacity = 0.35f + }; + var expectedValue = label.Opacity; + + var handler = await CreateHandlerAsync(label); + await InvokeOnMainThreadAsync(async () => + { + var nativeOpacityValue = await GetPlatformOpacity(handler); + Assert.Equal(expectedValue, nativeOpacityValue); + }); + } + Color TextColor(LabelHandler handler) { #if __IOS__ diff --git a/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.iOS.cs index 971e6e1717a1..733be10164a3 100644 --- a/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.iOS.cs @@ -60,6 +60,14 @@ TextDecorations GetPlatformTextDecorations(LabelHandler labelHandler) return textDecorations; } + Task GetPlatformOpacity(LabelHandler labelHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformLabel(labelHandler); + return (float)nativeView.Alpha; + }); + } public static IEnumerable GetCharacterSpacingWithLineHeightWithTextDecorationsWorksTestData() { var label1 = new Label() diff --git a/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.Android.cs index d7a24e0fe2f1..7633630ad563 100644 --- a/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.Android.cs +++ b/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.Android.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Android.Widget; using Microsoft.Maui.Controls; using Microsoft.Maui.Graphics; using Microsoft.Maui.Handlers; @@ -16,5 +17,17 @@ protected Task GetPlatformControlText(MauiPicker platformView) { return InvokeOnMainThreadAsync(() => platformView.Text); } + + MauiPicker GetPlatformPicker(PickerHandler pickerHandler) => + pickerHandler.PlatformView; + + Task GetPlatformOpacity(PickerHandler pickerHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformPicker(pickerHandler); + return (float)nativeView.Alpha; + }); + } } } \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.Windows.cs index 0f5d9dc64066..08f118082b28 100644 --- a/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.Windows.cs +++ b/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.Windows.cs @@ -82,5 +82,17 @@ UI.Xaml.VerticalAlignment GetPlatformVerticalOptions(ComboBox platformView) { return platformView.VerticalAlignment; } + + ComboBox GetPlatformPicker(PickerHandler pickerHandler) => + pickerHandler.PlatformView; + + Task GetPlatformOpacity(PickerHandler pickerHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformPicker(pickerHandler); + return (float)nativeView.Opacity; + }); + } } } \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.cs b/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.cs index 40c2f92f7672..073518ec2c5d 100644 --- a/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.cs @@ -70,5 +70,23 @@ public async Task PickerBackgroundColorConsistent() await ValidateHasColor(picker, expected, typeof(PickerHandler)); } + + [Fact] + [Description("The Opacity property of a Picker should match with native Opacity")] + public async Task VerifyPickerOpacityProperty() + { + var picker = new Picker + { + Opacity = 0.35f + }; + var expectedValue = picker.Opacity; + + var handler = await CreateHandlerAsync(picker); + await InvokeOnMainThreadAsync(async () => + { + var nativeOpacityValue = await GetPlatformOpacity(handler); + Assert.Equal(expectedValue, nativeOpacityValue); + }); + } } } \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.iOS.cs index 4be49a2c3ffa..7ca87c59224d 100644 --- a/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.iOS.cs @@ -9,11 +9,24 @@ namespace Microsoft.Maui.DeviceTests { - public partial class PickerTests : ControlsHandlerTestBase - { - protected Task GetPlatformControlText(MauiPicker platformView) - { - return InvokeOnMainThreadAsync(() => platformView.Text); - } - } + public partial class PickerTests : ControlsHandlerTestBase + { + protected Task GetPlatformControlText(MauiPicker platformView) + { + return InvokeOnMainThreadAsync(() => platformView.Text); + } + + MauiPicker GetPlatformPicker(PickerHandler pickerHandler) => + pickerHandler.PlatformView; + + Task GetPlatformOpacity(PickerHandler pickerHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformPicker(pickerHandler); + return (float)nativeView.Alpha; + }); + } + + } } \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/RadioButton/RadioButtonTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/RadioButton/RadioButtonTests.Windows.cs index a60e116f9a98..3cc783bb4286 100644 --- a/src/Controls/tests/DeviceTests/Elements/RadioButton/RadioButtonTests.Windows.cs +++ b/src/Controls/tests/DeviceTests/Elements/RadioButton/RadioButtonTests.Windows.cs @@ -1,4 +1,8 @@ using Microsoft.Maui.Handlers; +using Xunit; +using System.ComponentModel; +using System.Threading.Tasks; +using Microsoft.Maui.Controls; namespace Microsoft.Maui.DeviceTests { @@ -9,5 +13,24 @@ UI.Xaml.Controls.RadioButton GetNativeRadioButton(RadioButtonHandler radioButton bool GetNativeIsChecked(RadioButtonHandler radioButtonHandler) => GetNativeRadioButton(radioButtonHandler).IsChecked ?? false; + + [Fact] + [Description("The Opacity property of a RadioButton should match with native Opacity")] + public async Task VerifyRadioButtonOpacityProperty() + { + var radioButton = new RadioButton + { + Opacity = 0.35f + }; + var expectedValue = radioButton.Opacity; + + var handler = await CreateHandlerAsync(radioButton); + var nativeView = GetNativeRadioButton(handler); + await InvokeOnMainThreadAsync(() => + { + var nativeOpacityValue = (float)nativeView.Opacity; + Assert.Equal(expectedValue, nativeOpacityValue); + }); + } } } diff --git a/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.Android.cs index b60d23b13962..63fe3c327277 100644 --- a/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.Android.cs +++ b/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.Android.cs @@ -30,5 +30,14 @@ static int GetPlatformCursorPosition(SearchBarHandler searchBarHandler) var editText = control.GetChildrenOfType().FirstOrDefault(); return editText.SelectionStart; } + + Task GetPlatformOpacity(SearchBarHandler searchBarHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformControl(searchBarHandler); + return nativeView.Alpha; + }); + } } } diff --git a/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.Windows.cs index 1dc922d50c61..7542558cf8bd 100644 --- a/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.Windows.cs +++ b/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.Windows.cs @@ -43,5 +43,14 @@ static int GetPlatformCursorPosition(SearchBarHandler searchBarHandler) return -1; } + + Task GetPlatformOpacity(SearchBarHandler searchBarHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformControl(searchBarHandler); + return (float)nativeView.Opacity; + }); + } } } diff --git a/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.cs b/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.cs index e846c3fb79f5..35f0e55182e6 100644 --- a/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.cs @@ -4,6 +4,7 @@ using Microsoft.Maui.Handlers; using Microsoft.Maui.Platform; using Xunit; +using System.ComponentModel; namespace Microsoft.Maui.DeviceTests { @@ -76,6 +77,24 @@ await InvokeOnMainThreadAsync(() => } #endif + [Fact] + [Description("The Opacity property of a SearchBar should match with native Opacity")] + public async Task VerifySearchBarOpacityProperty() + { + var searchBar = new SearchBar + { + Opacity = 0.35f + }; + var expectedValue = searchBar.Opacity; + + var handler = await CreateHandlerAsync(searchBar); + await InvokeOnMainThreadAsync(async () => + { + var nativeOpacityValue = await GetPlatformOpacity(handler); + Assert.Equal(expectedValue, nativeOpacityValue); + }); + } + #if false // TODO: The search bar controls are composite controls and need to be attached to the UI to run [Category(TestCategory.SearchBar)] diff --git a/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.iOS.cs index 05b337cb41c6..3aa0a46345b6 100644 --- a/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.iOS.cs @@ -34,5 +34,15 @@ static int GetPlatformCursorPosition(SearchBarHandler searchBarHandler) var control = searchBarHandler.QueryEditor; return control.GetCursorPosition(); } + + Task GetPlatformOpacity(SearchBarHandler searchBarHandler) + { + return InvokeOnMainThreadAsync(() => + { + var nativeView = GetPlatformControl(searchBarHandler); + return (float)nativeView.Alpha; + }); + } + } } diff --git a/src/Controls/tests/DeviceTests/Elements/SwipeView/SwipeViewTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/SwipeView/SwipeViewTests.Android.cs index 773e158080b9..de8afa21e8ec 100644 --- a/src/Controls/tests/DeviceTests/Elements/SwipeView/SwipeViewTests.Android.cs +++ b/src/Controls/tests/DeviceTests/Elements/SwipeView/SwipeViewTests.Android.cs @@ -6,6 +6,7 @@ using Microsoft.Maui.Platform; using Xunit; using static Microsoft.Maui.DeviceTests.AssertHelpers; +using System.ComponentModel; namespace Microsoft.Maui.DeviceTests { @@ -78,5 +79,24 @@ Task HasChildren(SwipeViewHandler handler) return InvokeOnMainThreadAsync(() => GetPlatformControl(handler).ChildCount != 0); } + + [Fact] + [Description("The Opacity property of a SwipeView should match with native Opacity")] + public async Task VerifySwipeViewOpacityProperty() + { + var swipeView = new SwipeView + { + Opacity = 0.35f + }; + var expectedValue = swipeView.Opacity; + + var handler = await CreateHandlerAsync(swipeView); + var nativeView = GetPlatformControl(handler); + await InvokeOnMainThreadAsync(() => + { + var nativeOpacityValue = (float)nativeView.Alpha; + Assert.Equal(expectedValue, nativeOpacityValue); + }); + } } } \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/SwipeView/SwipeViewTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/SwipeView/SwipeViewTests.iOS.cs index e6dba6c2cbf0..e763f6a70312 100644 --- a/src/Controls/tests/DeviceTests/Elements/SwipeView/SwipeViewTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/SwipeView/SwipeViewTests.iOS.cs @@ -5,6 +5,7 @@ using Microsoft.Maui.Handlers; using Microsoft.Maui.Platform; using Xunit; +using System.ComponentModel; namespace Microsoft.Maui.DeviceTests { @@ -19,6 +20,25 @@ Task HasChildren(SwipeViewHandler handler) return InvokeOnMainThreadAsync(() => GetPlatformControl(handler).Subviews.Length != 0); } + + [Fact] + [Description("The Opacity property of a SwipeView should match with native Opacity")] + public async Task VerifySwipeViewOpacityProperty() + { + var swipeView = new SwipeView + { + Opacity = 0.35f + }; + var expectedValue = swipeView.Opacity; + + var handler = await CreateHandlerAsync(swipeView); + var nativeView = GetPlatformControl(handler); + await InvokeOnMainThreadAsync(() => + { + var nativeOpacityValue = (float)nativeView.Alpha; + Assert.Equal(expectedValue, nativeOpacityValue); + }); + } } }