Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Fix Stepper IsEnabled property changes #11053

Merged
merged 3 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
Text="Disabled"
Style="{StaticResource Headline}"/>
<Stepper
x:Name="EnableStepper"
IsEnabled="False"/>
<Button
x:Name="EnableButton"
Text="Enable Stepper"
Clicked="OnEnableButtonClicked"/>
<Label
Text="BackgroundColor"
Style="{StaticResource Headline}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,19 @@ void OnValueChanged(object sender, ValueChangedEventArgs args)
{
Debug.WriteLine($"Stepper Value: {args.NewValue}");
}

void OnEnableButtonClicked(object sender, System.EventArgs e)
{
if (EnableStepper.IsEnabled)
{
EnableStepper.IsEnabled = false;
EnableButton.Text = "Enable Stepper";
}
else
{
EnableStepper.IsEnabled = true;
EnableButton.Text = "Disable Stepper";
}
}
}
}
5 changes: 5 additions & 0 deletions src/Core/src/Handlers/Stepper/StepperHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ protected override MauiStepper CreatePlatformView()
return stepperLayout;
}

public static void MapIsEnabled(IStepperHandler handler, IStepper stepper)
{
handler.PlatformView?.UpdateIsEnabled(stepper);
}

public static void MapMinimum(IStepperHandler handler, IStepper stepper)
{
handler.PlatformView?.UpdateMinimum(stepper);
Expand Down
4 changes: 3 additions & 1 deletion src/Core/src/Handlers/Stepper/StepperHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public partial class StepperHandler : IStepperHandler
[nameof(IStepper.Maximum)] = MapMaximum,
[nameof(IStepper.Minimum)] = MapMinimum,
[nameof(IStepper.Value)] = MapValue,
#if WINDOWS
#if ANDROID
[nameof(IStepper.IsEnabled)] = MapIsEnabled,
#elif WINDOWS
[nameof(IStepper.Background)] = MapBackground,
#endif
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ static Microsoft.Maui.Handlers.MenuFlyoutHandler.Mapper -> Microsoft.Maui.IPrope
static Microsoft.Maui.Handlers.MenuFlyoutHandler.MapRemove(Microsoft.Maui.Handlers.IMenuFlyoutHandler! handler, Microsoft.Maui.IMenuFlyout! menuElement, object? arg) -> void
static Microsoft.Maui.Handlers.MenuFlyoutSeparatorHandler.CommandMapper -> Microsoft.Maui.CommandMapper<Microsoft.Maui.IMenuFlyoutSeparator!, Microsoft.Maui.Handlers.IMenuFlyoutSeparatorHandler!>!
static Microsoft.Maui.Handlers.MenuFlyoutSeparatorHandler.Mapper -> Microsoft.Maui.IPropertyMapper<Microsoft.Maui.IMenuFlyoutSeparator!, Microsoft.Maui.Handlers.IMenuFlyoutSeparatorHandler!>!
static Microsoft.Maui.Handlers.StepperHandler.MapIsEnabled(Microsoft.Maui.Handlers.IStepperHandler! handler, Microsoft.Maui.IStepper! stepper) -> void
static Microsoft.Maui.Handlers.ViewHandler.MapToolTip(Microsoft.Maui.IViewHandler! handler, Microsoft.Maui.IView! view) -> void
static Microsoft.Maui.Handlers.ViewHandler.MapContextFlyout(Microsoft.Maui.IViewHandler! handler, Microsoft.Maui.IView! view) -> void
static Microsoft.Maui.Handlers.WindowHandler.MapHeight(Microsoft.Maui.Handlers.IWindowHandler! handler, Microsoft.Maui.IWindow! view) -> void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
using System;
using System.Threading.Tasks;
using Android.Widget;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.DeviceTests.Stubs;

namespace Microsoft.Maui.DeviceTests
{
public partial class StepperHandlerTests
{
[Fact(DisplayName = "IsEnabled Initializes Correctly")]
public async Task IsEnabledInitializesCorrectly()
{
var stepper = new StepperStub()
{
Minimum = 0,
Maximum = 50,
IsEnabled = false
};

await ValidatePropertyInitValue(stepper, () => stepper.IsEnabled, GetNativeIsEnabled, stepper.IsEnabled);
}

LinearLayout GetNativeStepper(StepperHandler stepperHandler) =>
stepperHandler.PlatformView;

Expand Down Expand Up @@ -44,6 +56,16 @@ public partial class StepperHandlerTests
return 0;
}

bool GetNativeIsEnabled(StepperHandler stepperHandler)
{
var platformView = GetNativeStepper(stepperHandler);

var minimumButton = platformView.GetChildAt(0);
var maximumButton = platformView.GetChildAt(1);

return minimumButton.Enabled && maximumButton.Enabled;
}

Task ValidateHasColor(IStepper stepper, Color color, Action action = null)
{
return InvokeOnMainThreadAsync(() =>
Expand Down