Skip to content

Commit 171777e

Browse files
Merge pull request #58 from surya3655/NumericUpDown-Improvements
Enhancements and Bug Fixes: Long Press, AutoReverse, Toolbar Item, and Accessibility Improvements
2 parents 5be3ed7 + a8862ac commit 171777e

File tree

7 files changed

+482
-123
lines changed

7 files changed

+482
-123
lines changed

maui/src/NumericEntry/Event/ValueChangedEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// <summary>
44
/// Provides event data for the <see cref="SfNumericEntry.ValueChanged"/> event.
55
/// </summary>
6-
public class NumericEntryValueChangedEventArgs
6+
public class NumericEntryValueChangedEventArgs : EventArgs
77
{
88
/// <summary>
99
/// Initializes a new instance of the <see cref="NumericEntryValueChangedEventArgs"/> class.

maui/src/NumericEntry/SfNumericEntry.Methods.cs

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,13 @@ void SetBinding()
344344
_textBox.SetBinding(SfEntryView.IsVisibleProperty, "IsVisible");
345345
_textBox.SetBinding(SfEntryView.CursorPositionProperty, "CursorPosition", BindingMode.TwoWay);
346346
_textBox.SetBinding(SfEntryView.SelectionLengthProperty, "SelectionLength", BindingMode.TwoWay);
347+
348+
#if WINDOWS
349+
if(_textBox.Text != null)
350+
{
351+
_textBox.CursorPosition = _textBox.Text.Length;
352+
}
353+
#endif
347354
}
348355
}
349356

@@ -700,12 +707,12 @@ void AndroidEntry_AfterTextChanged(object? sender, Android.Text.AfterTextChanged
700707
string decimalSeparator = GetNumberDecimalSeparator(GetNumberFormat());
701708
if (entry != null && (entry.Text == "-" || entry.Text == decimalSeparator))
702709
{
703-
if (!IsSamsungDevice() && _textBox != null)
710+
if (!_isSamsungWithSamsungKeyboard && _textBox != null)
704711
{
705712
_textBox.Text = AllowNull ? string.Empty : "0";
706713
}
707714
}
708-
if (IsSamsungDevice() && _textBox != null && _textBox.Text.Length > 1)
715+
if (_isSamsungWithSamsungKeyboard && _textBox != null && _textBox.Text.Length > 1)
709716
{
710717
if (_textBox.Text[0] == decimalSeparator[0] && _textBox.Text.LastIndexOf(decimalSeparator) == 0)
711718
{
@@ -725,13 +732,21 @@ void AndroidEntry_AfterTextChanged(object? sender, Android.Text.AfterTextChanged
725732
}
726733

727734
/// <summary>
728-
/// Validate the device is Samsung.
735+
/// Validate the device is Samsung and which keyboard is used.
729736
/// </summary>
730-
/// <returns>It returns <c>True</c> if the device is Samsung</returns>
731-
bool IsSamsungDevice()
732-
{
733-
return string.Equals(global::Android.OS.Build.Manufacturer, "samsung", StringComparison.OrdinalIgnoreCase);
734-
}
737+
void CheckDeviceAndKeyboard()
738+
{
739+
if (string.Equals(global::Android.OS.Build.Manufacturer, "samsung", StringComparison.OrdinalIgnoreCase))
740+
{
741+
var context = Android.App.Application.Context;
742+
string currentKeyboard = KeyboardChecker.GetCurrentKeyboard(context);
743+
_isSamsungWithSamsungKeyboard = currentKeyboard == "Samsung Keyboard";
744+
}
745+
else
746+
{
747+
_isSamsungWithSamsungKeyboard = false;
748+
}
749+
}
735750

736751
#endif
737752

@@ -1590,6 +1605,9 @@ void OnLoaded(object? sender, EventArgs e)
15901605
{
15911606
SetFlowDirection();
15921607
}
1608+
1609+
#elif ANDROID
1610+
CheckDeviceAndKeyboard();
15931611
#endif
15941612

15951613
}
@@ -1872,7 +1890,7 @@ void ProcessDisplayTextForPlatform(ref string displayText)
18721890

18731891
#if ANDROID
18741892
// Prefix zero if needed, except on Samsung devices
1875-
if (!IsSamsungDevice())
1893+
if (!_isSamsungWithSamsungKeyboard)
18761894
{
18771895
PrefixZeroIfNeeded(ref displayText, IsNegative(displayText, GetNumberFormat()), GetNumberFormat());
18781896
}
@@ -1985,7 +2003,7 @@ void UpdateCursorPosition(int decimalIndex, int caretPosition, string displayTex
19852003
return;
19862004
}
19872005
#if ANDROID
1988-
if (!IsSamsungDevice())
2006+
if (!_isSamsungWithSamsungKeyboard)
19892007
{
19902008
_cursorPosition = decimalIndex + 1;
19912009
}
@@ -2074,7 +2092,7 @@ void HandleNegativeKey(bool isNegative, int caretPosition)
20742092
#endif
20752093
}
20762094
#if ANDROID
2077-
else if (displayText.StartsWith('.') && IsSamsungDevice())
2095+
else if (displayText.StartsWith('.') && _isSamsungWithSamsungKeyboard)
20782096
{
20792097
string decimalSeparator = GetNumberDecimalSeparator(GetNumberFormat());
20802098
displayText = string.Concat("", displayText.AsSpan(1));
@@ -2360,6 +2378,13 @@ private void UpdateTextBoxCursorPosition(string displayText, int caretPosition)
23602378
}
23612379

23622380
_textBox.Text = displayText;
2381+
if (ValueChangeMode == ValueChangeMode.OnKeyFocus && _textBox.Text != null && _textBox.Text != displayText)
2382+
{
2383+
if (Parse(_textBox.Text) == Maximum)
2384+
{
2385+
caretPosition = _textBox.Text.Length;
2386+
}
2387+
}
23632388
if (_textBox.Text != null)
23642389
{
23652390
_textBox.CursorPosition = caretPosition >= 0 ? (caretPosition <= _textBox.Text.Length) ? caretPosition : _textBox.Text.Length : 0;
@@ -2379,6 +2404,9 @@ private void UpdateTextBoxCursorPosition(string displayText, int caretPosition)
23792404
/// <param name="caretPosition">The position of the caret where input should be inserted.</param>
23802405
void InsertNumbers(string displayText, string selectedText, string input, int caretPosition)
23812406
{
2407+
#if WINDOWS
2408+
displayText ??= "";
2409+
#endif
23822410
displayText = displayText.Remove(caretPosition, Math.Min(selectedText.Length, displayText.Length - caretPosition));
23832411
string negativeSign = GetNegativeSign(GetNumberFormat());
23842412
bool isNegative = IsNegative(displayText, GetNumberFormat());
@@ -2541,7 +2569,11 @@ internal void UpdateDisplayText(double? value, bool resetCursor = true)
25412569
}
25422570
}
25432571

2572+
#if WINDOWS
2573+
if ((resetCursor || _isFirst) && _textBox.Text != null)
2574+
#else
25442575
if (resetCursor && _textBox.Text != null)
2576+
#endif
25452577
{
25462578
_textBox.CursorPosition = _textBox.Text.Length;
25472579
}

0 commit comments

Comments
 (0)