Skip to content

Commit 92eec56

Browse files
committed
Update SfOtpInput class and .gitignore settings
- Added .vs/ directory to .gitignore for Visual Studio files. - Modified _entryWidth and _entryHeight to be uninitialized. - Introduced BoxWidthProperty and BoxHeightProperty for dynamic sizing. - Updated constructor to initialize dimensions from new properties. - Added public properties BoxWidth and BoxHeight for access. - Implemented OnBoxSizePropertyChanged to handle property changes. - Corrected parameter type declarations in event handler methods.
1 parent da41cba commit 92eec56

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
bin
33
obj
4+
.vs/

maui/src/OtpInput/SfOtpInput.cs

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ public class SfOtpInput : SfView, IKeyboardListener, IParentThemeElement
5757
/// <summary>
5858
/// Width of each OTP input field.
5959
/// </summary>
60-
float _entryWidth = 40;
60+
float _entryWidth;
6161

6262
/// <summary>
6363
/// Height of each OTP input field.
6464
/// </summary>
65-
float _entryHeight = 40;
65+
float _entryHeight;
6666

6767
/// <summary>
6868
/// Corner radius for the rounded edges of OTP input fields.
@@ -155,6 +155,18 @@ public class SfOtpInput : SfView, IKeyboardListener, IParentThemeElement
155155
/// </summary>
156156
bool _isPasteHandled = false;
157157
#endif
158+
159+
/// <summary>
160+
/// Identifies the BoxWidth bindable property.
161+
/// </summary>
162+
public static readonly BindableProperty BoxWidthProperty =
163+
BindableProperty.Create(nameof(BoxWidth), typeof(double), typeof(SfOtpInput), 40.0, BindingMode.TwoWay, propertyChanged: OnBoxSizePropertyChanged);
164+
165+
/// <summary>
166+
/// Identifies the BoxHeight bindable property.
167+
/// </summary>
168+
public static readonly BindableProperty BoxHeightProperty =
169+
BindableProperty.Create(nameof(BoxHeight), typeof(double), typeof(SfOtpInput), 40.0, BindingMode.TwoWay, propertyChanged: OnBoxSizePropertyChanged);
158170
#endregion
159171
#region BindableProperties
160172

@@ -303,6 +315,8 @@ public SfOtpInput()
303315
{
304316
ThemeElement.InitializeThemeResources(this, "SfOtpInputTheme");
305317
DrawingOrder = DrawingOrder.BelowContent;
318+
_entryWidth = (float)BoxWidth;
319+
_entryHeight = (float)BoxHeight;
306320
InitializeFields();
307321
#if IOS
308322
this.IgnoreSafeArea = true;
@@ -737,6 +751,24 @@ public Color InputBackground
737751
{
738752
get { return (Color)GetValue(InputBackgroundProperty); }
739753
set { SetValue(InputBackgroundProperty, value); }
754+
}
755+
756+
/// <summary>
757+
/// Gets or sets the width of each OTP input box.
758+
/// </summary>
759+
public double BoxWidth
760+
{
761+
get => (double)GetValue(BoxWidthProperty);
762+
set => SetValue(BoxWidthProperty, value);
763+
}
764+
765+
/// <summary>
766+
/// Gets or sets the height of each OTP input box.
767+
/// </summary>
768+
public double BoxHeight
769+
{
770+
get => (double)GetValue(BoxHeightProperty);
771+
set => SetValue(BoxHeightProperty, value);
740772
}
741773

742774
#endregion
@@ -1121,6 +1153,20 @@ static void OnStrokePropertyChanged(BindableObject bindable, object oldValue, ob
11211153
}
11221154
}
11231155

1156+
/// <summary>
1157+
/// Add this property changed handler
1158+
/// </summary>
1159+
static void OnBoxSizePropertyChanged(BindableObject bindable, object oldValue, object newValue)
1160+
{
1161+
if (bindable is SfOtpInput otpInput)
1162+
{
1163+
otpInput._entryWidth = (float)otpInput.BoxWidth;
1164+
otpInput._entryHeight = (float)otpInput.BoxHeight;
1165+
otpInput.InvalidateMeasure();
1166+
otpInput.InvalidateDrawable();
1167+
}
1168+
}
1169+
11241170
#endregion
11251171

11261172
#region Public Methods
@@ -1970,7 +2016,7 @@ void DetachEvents(OTPEntry otpEntry)
19702016
/// Handles key down events for OTP input fields.
19712017
/// </summary>
19722018
/// <param name="sender">The object that triggered the event.</param>
1973-
/// <param name="e">Event arguments containing key information.</param>
2019+
/// <param { get; set; }="e">Event arguments containing key information.</param>
19742020
void OnKeyDown(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
19752021
{
19762022
if (_otpEntries is null)
@@ -2257,7 +2303,7 @@ void OnPreviewKeyDown(KeyEventArgs e)
22572303
/// Sets up platform-specific event handlers for key input validation and handling.
22582304
/// </summary>
22592305
/// <param name="sender">The OTPEntry control whose handler has changed.</param>
2260-
/// <param name="e">Event arguments containing details of the change.</param>
2306+
/// <param { get; set; }="e">Event arguments containing details of the change.</param>
22612307
void OnHandlerChanged(object? sender, EventArgs e)
22622308
{
22632309
if (sender is OTPEntry textBox)

0 commit comments

Comments
 (0)