Skip to content

Commit 9a762e9

Browse files
Merge branch 'internal_public' of https://github.com/syncfusion/maui-toolkit into internal_public
2 parents f183070 + 870bc3e commit 9a762e9

File tree

9 files changed

+98
-40
lines changed

9 files changed

+98
-40
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/src/SegmentedControl/Helper/SegmentViewHelper.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,20 @@ internal static Color GetSelectedSegmentForeground(ISegmentItemInfo? itemInfo, S
280280
{
281281
return segmentItem.SelectedSegmentTextColor ?? itemInfo?.SelectionIndicatorSettings?.TextColor ?? Colors.White;
282282
}
283+
else
284+
{
285+
Color textColor;
286+
if (itemInfo != null && itemInfo.SelectionIndicatorSettings != null && !itemInfo.SelectedSegmentTextColor.Equals(itemInfo.SelectionIndicatorSettings.TextColor))
287+
{
288+
textColor = itemInfo.SelectionIndicatorSettings.TextColor;
289+
}
290+
else
291+
{
292+
textColor = BrushToColorConverter(GetSelectedSegmentStroke(itemInfo, segmentItem));
293+
}
283294

284-
// If the selection indicator is not filled, get the text color from the selected segment background.
285-
Brush textColor = GetSelectedSegmentStroke(itemInfo, segmentItem);
286-
return BrushToColorConverter(textColor);
295+
return segmentItem.SelectedSegmentTextColor ?? textColor;
296+
}
287297
}
288298

289299
/// <summary>

maui/src/SegmentedControl/Interface/ISegmentInfo.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ internal interface ISegmentInfo
8787
/// </summary>
8888
Brush KeyboardFocusStroke { get; }
8989

90+
/// <summary>
91+
/// Gets the selected text color for the segment.
92+
/// </summary>
93+
Color SelectedSegmentTextColor { get; }
94+
9095
/// <summary>
9196
/// Gets the background brush for the segment when it is disabled.
9297
/// </summary>

maui/src/SegmentedControl/Model/SfSegmentedControl.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,19 @@ public partial class SfSegmentedControl
290290
typeof(SfSegmentedControl),
291291
defaultValueCreator: bindable => null);
292292

293+
/// <summary>
294+
/// Identifies the <see cref="SelectedSegmentTextColor"/> dependency property.
295+
/// </summary>
296+
/// <value>
297+
/// Identifies the <see cref="SelectedSegmentTextColor"/> bindable property.
298+
/// </value>
299+
internal static readonly BindableProperty SelectedSegmentTextColorProperty =
300+
BindableProperty.Create(
301+
nameof(SelectedSegmentTextColor),
302+
typeof(Color), typeof(SfSegmentedControl),
303+
defaultValueCreator: bindable => Color.FromArgb("#FFFFFF"),
304+
propertyChanged: OnSelectedSegmentTextColorChanged);
305+
293306
/// <summary>
294307
/// Identifies the <see cref="KeyboardFocusStroke"/> dependency property.
295308
/// </summary>
@@ -993,6 +1006,15 @@ internal Brush HoveredBackground
9931006
set { SetValue(HoveredBackgroundProperty, value); }
9941007
}
9951008

1009+
/// <summary>
1010+
/// Gets or sets the selected text color brush for the segment.
1011+
/// </summary>
1012+
internal Color SelectedSegmentTextColor
1013+
{
1014+
get { return (Color)this.GetValue(SelectedSegmentTextColorProperty); }
1015+
set { this.SetValue(SelectedSegmentTextColorProperty, value); }
1016+
}
1017+
9961018
/// <summary>
9971019
/// Gets or sets the focused keyboard stroke for the segment.
9981020
/// </summary>
@@ -1280,6 +1302,23 @@ static void OnKeyboardFocusStrokeChanged(BindableObject bindable, object oldValu
12801302
segmentedControl._keyNavigationView?.InvalidateDrawable();
12811303
}
12821304

1305+
/// <summary>
1306+
/// Occurs when <see cref="SelectedSegmentTextColor"/> property changed.
1307+
/// </summary>
1308+
/// <param name="bindable">The bindable object.</param>
1309+
/// <param name="oldValue">The old value.</param>
1310+
/// <param name="newValue">The new value.</param>
1311+
static void OnSelectedSegmentTextColorChanged(BindableObject bindable, object oldValue, object newValue)
1312+
{
1313+
SfSegmentedControl segmentedControl = (SfSegmentedControl)bindable;
1314+
if (segmentedControl == null || segmentedControl._segmentLayout == null || !segmentedControl.IsLoaded)
1315+
{
1316+
return;
1317+
}
1318+
1319+
segmentedControl._segmentLayout?.UpdateSelectedSegmentItemStyle();
1320+
}
1321+
12831322
/// <summary>
12841323
/// Occurs when <see cref="DisabledSegmentBackground"/> property changed.
12851324
/// </summary>

maui/src/SegmentedControl/SfSegmentedControl.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public SfSegmentedControl()
8888
ThemeElement.InitializeThemeResources(this, "SfSegmentedControlTheme");
8989
SetDynamicResource(HoveredBackgroundProperty, "SfSegmentedControlHoveredBackground");
9090
SetDynamicResource(KeyboardFocusStrokeProperty, "SfSegmentedControlKeyboardFocusStroke");
91+
SetDynamicResource(SelectedSegmentTextColorProperty, "SfSegmentedControlSelectionTextColor");
9192
MinimumWidthRequest = 180;
9293
MinimumHeightRequest = 40;
9394
SelectionIndicatorSettings.Parent = this;
@@ -130,6 +131,11 @@ public SfSegmentedControl()
130131
/// </summary>
131132
Brush ISegmentInfo.KeyboardFocusStroke => KeyboardFocusStroke;
132133

134+
/// <summary>
135+
/// Gets the selected text color for the segment.
136+
/// </summary>
137+
Color ISegmentInfo.SelectedSegmentTextColor => this.SelectedSegmentTextColor;
138+
133139
#endregion
134140

135141
#region Public methods

maui/tests/Syncfusion.Maui.Toolkit.UnitTest/Buttons/SfSegmentedControlUnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ public void GetSelectedSegmentForeground_ReturnsColorFromSelectedSegmentbackgrou
12221222
var itemInfo = new SfSegmentedControl { SelectionIndicatorSettings = new SelectionIndicatorSettings { SelectionIndicatorPlacement = SelectionIndicatorPlacement.Border } };
12231223
var segmentItem = new SfSegmentItem { SelectedSegmentTextColor = Colors.Yellow };
12241224
var resultColor = SegmentViewHelper.GetSelectedSegmentForeground(itemInfo, segmentItem);
1225-
var expected = Color.FromRgba(0.40392157, 0.3137255, 0.6431373, 1);
1225+
var expected = Color.FromRgba(255, 255, 0, 255);
12261226
Assert.Equal(expected, resultColor);
12271227
}
12281228

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)