Skip to content

Commit

Permalink
Enhanced Stepper to Support Dynamic Increment Mapping (dotnet#24396)
Browse files Browse the repository at this point in the history
* Fix Stepper doesn't change increment value when being bound to a double in MVVM context (Windows)

* shipped file changes updated

* shipped file changes included

* changes added in unshipped file

* platform condition removed

* platform condition added in script file

* shipped file extra changes removed

* extra changes removed in unshipped.txt

* empty lines removed

* tizen shipped file changes reverted

* new test case and snapshot added for android & iOS

* WinUI snap added

* old changes reverted new changes added

* snap added for all platform

* Added AppendToMapping pattern

* Removed wrong namespace

* Renamed class name

* Updated testcase screenshot forMac

* Update StepperUITests.cs

* Revert "Update StepperUITests.cs"

This reverts commit 70ff4bc.

* Revert "Updated testcase screenshot forMac"

This reverts commit 0aadff6.

* Updated alignment in test case

* Updated MapInterval

* Updated test sample

* Reverted test images

* Revert "Reverted test images"

This reverts commit 0ecfc54.

* Removed test images

* Added test_fails_on_catalyst tag in test sample

---------

Co-authored-by: Dhivya-SF4094 <[email protected]>
  • Loading branch information
devanathan-vaithiyanathan and Dhivya-SF4094 authored Jan 24, 2025
1 parent 92f25df commit a200973
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ internal static MauiAppBuilder RemapForControls(this MauiAppBuilder builder)
SwipeView.RemapForControls();
Picker.RemapForControls();
SearchBar.RemapForControls();
Stepper.RemapForControls();
TabbedPage.RemapForControls();
TimePicker.RemapForControls();
Layout.RemapForControls();
Expand Down
15 changes: 15 additions & 0 deletions src/Controls/src/Core/Stepper/Stepper.Mapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace Microsoft.Maui.Controls;
public partial class Stepper
{
internal static new void RemapForControls()
{
StepperHandler.Mapper.AppendToMapping(nameof(Stepper.Increment), MapInterval);
}

internal static void MapInterval(IStepperHandler handler, IStepper stepper)
{
handler.UpdateValue(nameof(IStepper.Interval));
}
}
23 changes: 23 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue20706.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue20706"
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues">
<ContentPage.BindingContext>
<local:ViewModelClass/>
</ContentPage.BindingContext>
<ContentPage.Content>
<VerticalStackLayout>
<Stepper AutomationId="myStepper"
x:Name="stepperValue"
Maximum="1000"
Increment="{Binding Increment}"/>
<Entry AutomationId="entry"
Text="{Binding Value,Source={x:Reference stepperValue}} "/>
<Button AutomationId="incrementButton"
Text="Change Increment Value"
x:Name="button"
Clicked="button_Clicked"/>
</VerticalStackLayout>
</ContentPage.Content>
</ContentPage>
51 changes: 51 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue20706.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.ComponentModel;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 20706, "Stepper doesn't change increment value when being bound to a double in MVVM context (Windows)", PlatformAffected.UWP)]
public partial class Issue20706 : ContentPage
{
public Issue20706()
{
InitializeComponent();
}

private void button_Clicked(object sender, EventArgs e)
{
stepperValue.Increment = 10;
}
}

internal class ViewModelClass : INotifyPropertyChanged
{
private double _increment;

public double Increment
{
get
{
return _increment;
}

set
{
_increment = value;
OnPropertyChanged("Increment");
}
}

public ViewModelClass()
{
Increment = 2;
}
private void OnPropertyChanged(string v)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(v));
}
}

public event PropertyChangedEventHandler PropertyChanged;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#if TEST_FAILS_ON_CATALYST // Stepper interaction is not implemented for catalyst
using NUnit.Framework;
using NUnit.Framework.Legacy;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue20706 : _IssuesUITest
{
public override string Issue => "Stepper doesn't change increment value when being bound to a double in MVVM context (Windows)";
public Issue20706(TestDevice device) : base(device)
{
}

[Test]
[Category(UITestCategories.Stepper)]
public void ChangeIncrementValue()
{
App.WaitForElement("entry");
// check the current value.
var initialValue = App.FindElement("entry").GetText();
Assert.That("0", Is.EqualTo(initialValue));

// Increase the value.
App.IncreaseStepper("myStepper");

// Verify that the value has been increased.
var step1Value = App.FindElement("entry").GetText();
Assert.That("2", Is.EqualTo(step1Value));

// Change the Stepper increment value.
App.Click("incrementButton");

// Increase the value.
App.IncreaseStepper("myStepper");
var step2Value = App.FindElement("entry").GetText();
Assert.That("12", Is.EqualTo(step2Value));

// Decrease the value.
App.DecreaseStepper("myStepper");

// Verify that the value has decreased.
var step3Value = App.FindElement("entry").GetText();
Assert.That("2", Is.EqualTo(step3Value));
}
}
}
#endif

0 comments on commit a200973

Please sign in to comment.