Skip to content

Commit 082ad8a

Browse files
Added Numeric Entry Changes
1 parent fce44dc commit 082ad8a

File tree

4 files changed

+34
-36
lines changed

4 files changed

+34
-36
lines changed

maui/src/NumericEntry/SfNumericEntry.Methods.cs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,8 @@ void SetTextBoxMargin()
166166
if (_textBox != null)
167167
{
168168
_textBox.ButtonSize = ButtonSize + 4;
169-
int defaultMargin = IsTextInputLayout ? 0 : 10;
170169
double rightMargin = _buttonSpace;
171-
172-
#if ANDROID || IOS || MACCATALYST
173-
_textBox.Margin = new Thickness(defaultMargin, 0, rightMargin, 0);
174-
#else
175-
_textBox.Margin = new Thickness(0, 0, rightMargin, 0);
176-
#endif
170+
_textBox.Margin = GetMarginBasedOnTextAlignment(0, 0, rightMargin, 0);
177171
}
178172
}
179173

@@ -947,9 +941,11 @@ async void OnTextBoxPaste(object? sender, int caretPosition)
947941
/// <param name="numberBox">The SfNumericEntry control.</param>
948942
/// <param name="oldValue">The previous value.</param>
949943
/// <param name="newValue">The new value.</param>
950-
static void RaiseValueChangedEvent(SfNumericEntry numberBox, double? oldValue, double? newValue)
944+
static async void RaiseValueChangedEvent(SfNumericEntry numberBox, double? oldValue, double? newValue)
951945
{
952946
var valueChangedEventArgs = new NumericEntryValueChangedEventArgs(newValue, oldValue);
947+
//Fix included for Value loop issue.
948+
await Task.Yield();
953949
numberBox.ValueChanged?.Invoke(numberBox, valueChangedEventArgs);
954950
}
955951

@@ -2275,6 +2271,30 @@ void UpdateMaximumFractionDigit()
22752271
}
22762272
}
22772273

2274+
/// <summary>
2275+
/// On iOS and MacCatalyst, it ensures a minimum left or right margin value when the
2276+
/// text alignment is Start or End respectively.
2277+
/// On other platforms, it returns the provided thickness without modification.
2278+
/// <param name="left">The original left margin.</param>
2279+
/// <param name="top">The original top margin.</param>
2280+
/// <param name="right">The original right margin.</param>
2281+
/// <param name="bottom">The original bottom margin.</param>
2282+
/// <returns>Returns a <see cref="Thickness"/> value adjusted based on the specified text alignment.</returns>
2283+
/// </summary>
2284+
internal Thickness GetMarginBasedOnTextAlignment(double left, double top, double right, double bottom)
2285+
{
2286+
#if MACCATALYST || IOS
2287+
return HorizontalTextAlignment switch
2288+
{
2289+
TextAlignment.Start => new Thickness(left > 0 ? left : MinimumMargin, top, right, bottom),
2290+
TextAlignment.End => new Thickness(left, top, right > 0 ? right : MinimumMargin, bottom),
2291+
_ => new Thickness(left, top, right, bottom)
2292+
};
2293+
#else
2294+
return new Thickness(left, top, right, bottom);
2295+
#endif
2296+
}
2297+
22782298
/// <summary>
22792299
/// Restricts digits in the fractional part of the number in the <see cref="SfNumericEntry"/>.
22802300
/// </summary>

maui/src/NumericEntry/SfNumericEntry.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ public partial class SfNumericEntry : SfView, ITextElement, ITouchListener, IKey
308308
/// </summary>
309309
string _previousText = string.Empty;
310310
#endif
311+
312+
#if MACCATALYST || IOS
313+
const double MinimumMargin = 7;
314+
#endif
315+
311316
#endregion
312317

313318
#region Constructor

maui/src/NumericEntry/SfNumericUpDown.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -921,13 +921,7 @@ void SetTextBoxMargin()
921921
if (_textBox != null)
922922
{
923923
_textBox.ButtonSize = ButtonSize + 4;
924-
int defaultMargin = IsTextInputLayout ? 0 : 10;
925-
926-
#if ANDROID || IOS || MACCATALYST
927-
_textBox.Margin = new Thickness(_leftMargin + defaultMargin, 0, _rightMargin, 0);
928-
#else
929-
_textBox.Margin = new Thickness(_leftMargin, 0, _rightMargin, 0);
930-
#endif
924+
_textBox.Margin = GetMarginBasedOnTextAlignment(_leftMargin, 0, _rightMargin, 0);
931925
}
932926
}
933927

maui/tests/Syncfusion.Maui.Toolkit.UnitTest/Editors/SfNumericEntryUnitTests.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -519,27 +519,6 @@ public void UpdateEffectsRendererBounds_ShouldReturn_EffectsRenderer()
519519
Assert.NotNull(GetPrivateField(numericEntry, "_effectsRenderer"));
520520
}
521521

522-
[Fact]
523-
public void RaiseValueChangedEvent_ShouldTrigger_ValueChangedEvent()
524-
{
525-
var numericEntry = new SfNumericEntry();
526-
double? oldValue = 50;
527-
double? newValue = 60;
528-
bool eventTriggered = false;
529-
530-
numericEntry.ValueChanged += (sender, e) =>
531-
{
532-
eventTriggered = true;
533-
Assert.Equal(oldValue, e.OldValue);
534-
Assert.Equal(newValue, e.NewValue);
535-
};
536-
537-
InvokeStaticPrivateMethod(numericEntry, "RaiseValueChangedEvent", new object[] { numericEntry, oldValue, newValue });
538-
539-
Assert.True(eventTriggered);
540-
}
541-
542-
543522
[Theory]
544523
[InlineData("42.5", 0)]
545524
[InlineData("invalid", 42.5)]

0 commit comments

Comments
 (0)