Skip to content
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 @@ -167,7 +167,6 @@ public void Stepper_SetVisibilityToFalse_VerifyVisualState()
App.WaitForNoElement("StepperControl");
}

#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST //Related Issue Link : https://github.com/dotnet/maui/issues/29704
[Test]
public void Stepper_ChangeFlowDirection_RTL_VerifyVisualState()
{
Expand All @@ -180,7 +179,7 @@ public void Stepper_ChangeFlowDirection_RTL_VerifyVisualState()
App.WaitForElement("Options");
VerifyScreenshot(tolerance: 0.5, retryTimeout: TimeSpan.FromSeconds(2));
Comment thread
SubhikshaSf4851 marked this conversation as resolved.
Resolved
}
#endif

[Test]
public void Stepper_AtMinimumValue_DecrementButtonDisabled()
{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/Core/src/Handlers/Stepper/StepperHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public partial class StepperHandler : IStepperHandler
[nameof(IStepper.IsEnabled)] = MapIsEnabled,
#elif WINDOWS
[nameof(IStepper.Background)] = MapBackground,
#elif __IOS__ || MACCATALYST
[nameof(IStepper.FlowDirection)] = MapFlowDirection,
#endif
};

Expand Down
6 changes: 6 additions & 0 deletions src/Core/src/Handlers/Stepper/StepperHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public static void MapValue(IStepperHandler handler, IStepper stepper)
handler.PlatformView?.UpdateValue(stepper);
}

// TODO: Make public for .NET 11.
internal static void MapFlowDirection(IStepperHandler handler, IStepper stepper)
{
handler.PlatformView?.UpdateFlowDirection(stepper);
}

class StepperProxy
{
WeakReference<IStepper>? _virtualView;
Expand Down
86 changes: 84 additions & 2 deletions src/Core/src/Platform/iOS/StepperExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using ObjCRuntime;
using System;
using ObjCRuntime;
using UIKit;
using CoreGraphics;

namespace Microsoft.Maui.Platform
{
Expand Down Expand Up @@ -38,5 +40,85 @@ public static void UpdateValue(this UIStepper platformStepper, IStepper stepper)
}

}

// Applies the semantic content attribute and visual transform
// to the UIStepper and its subviews based on the Stepper's FlowDirection
// and its parent's layout direction.
internal static void UpdateFlowDirection(this UIStepper platformStepper, IStepper stepper)
{
UISemanticContentAttribute contentAttribute = GetSemanticContentAttribute(stepper);
// iOS 26 changed UIStepper internal rendering so that SemanticContentAttribute alone
// is no longer sufficient to mirror the control for RTL. A horizontal transform is required.
bool isIOS26 = OperatingSystem.IsIOSVersionAtLeast(26) || OperatingSystem.IsMacCatalystVersionAtLeast(26);
platformStepper.SemanticContentAttribute = contentAttribute;

// Apply transform to stepper subviews on iOS 26+.
if (isIOS26)
{
CGAffineTransform transform = GetCGAffineTransform(stepper);
platformStepper.Transform = transform;

foreach (var subview in platformStepper.Subviews)
{
subview.SemanticContentAttribute = contentAttribute;
subview.Transform = transform;
}
}
else
{
foreach (var subview in platformStepper.Subviews)
{
subview.SemanticContentAttribute = contentAttribute;
}
}
}

static UISemanticContentAttribute GetSemanticContentAttribute(IStepper stepper)
{
return stepper.FlowDirection switch
{
FlowDirection.LeftToRight => UISemanticContentAttribute.ForceLeftToRight,
FlowDirection.RightToLeft => UISemanticContentAttribute.ForceRightToLeft,
_ => GetParentSemanticContentAttribute(stepper),
};
}

static UISemanticContentAttribute GetParentSemanticContentAttribute(IStepper stepper)
{
var parentView = (stepper as IView)?.Parent as IView;
if (parentView is null)
{
return UISemanticContentAttribute.Unspecified;
}

return parentView.FlowDirection switch
{
FlowDirection.LeftToRight => UISemanticContentAttribute.ForceLeftToRight,
FlowDirection.RightToLeft => UISemanticContentAttribute.ForceRightToLeft,
_ => UISemanticContentAttribute.Unspecified,
};
}

static CGAffineTransform GetCGAffineTransform(IStepper stepper)
{
return stepper.FlowDirection switch
{
FlowDirection.LeftToRight => CGAffineTransform.MakeIdentity(),
FlowDirection.RightToLeft => CGAffineTransform.MakeScale(-1, 1),
_ => GetParentTransform(stepper), // Default to parent's direction if MatchParent
};
}

static CGAffineTransform GetParentTransform(IStepper stepper)
{
var parentSemanticAttribute = GetParentSemanticContentAttribute(stepper);
if (parentSemanticAttribute == UISemanticContentAttribute.ForceRightToLeft)
{
// Flip horizontally for RTL
return CGAffineTransform.MakeScale(-1, 1);
}
// Identity transform for LTR
return CGAffineTransform.MakeIdentity();
}
}
}
}
Loading