Skip to content

Commit eef59b0

Browse files
Merge pull request #47 from Choza-rajan/NumericEntryAndUpDown
Implementation of the SfNumericEntry and SfNumericUpDown Control in MAUI Toolkit
2 parents 7cb6532 + fe46dfb commit eef59b0

24 files changed

+14130
-4174
lines changed

maui/src/AssemblyInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
[assembly: InternalsVisibleTo("Syncfusion.Maui.Toolkit.UnitTest")]
44
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.BottomSheet")]
5+
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.Buttons")]
56
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.Calendar")]
67
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.Carousel")]
78
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.Charts")]
89
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.Chips")]
910
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.EffectsView")]
1011
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.NavigationDrawer")]
12+
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.NumericEntry")]
13+
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.NumericUpDown")]
1114
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.PullToRefresh")]
1215
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.SegmentedControl")]
1316
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.Shimmer")]
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
using Color = Microsoft.Maui.Graphics.Color;
2+
#if WINDOWS
3+
using WColor = Windows.UI.Color;
4+
using GradientBrush = Microsoft.UI.Xaml.Media.GradientBrush;
5+
#elif ANDROID
6+
using Android.Content;
7+
using Android.OS;
8+
using Android.Util;
9+
#endif
10+
11+
namespace Syncfusion.Maui.Toolkit.EntryView
12+
{
13+
/// <summary>
14+
/// The SfEntryView is a entry component which is used to create input view entry for NumericEntry.
15+
/// </summary>
16+
internal partial class SfEntryView : Entry
17+
{
18+
#region Fields
19+
20+
IDrawable? _drawable;
21+
22+
#if MACCATALYST || IOS
23+
Color? _focusedColor = Color.FromArgb("#8EBDFF");
24+
#else
25+
Color? _focusedColor = Colors.Gray;
26+
#endif
27+
28+
#endregion
29+
30+
#region Constructor
31+
32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="SfEntryView"/> class.
34+
/// </summary>
35+
public SfEntryView()
36+
{
37+
Initialize();
38+
}
39+
40+
void Initialize()
41+
{
42+
Style = new Style(typeof(SfEntryView));
43+
BackgroundColor = Colors.Transparent;
44+
TextColor = Colors.Black;
45+
FontSize = 14d;
46+
}
47+
48+
#endregion
49+
50+
#region Properties
51+
52+
/// <summary>
53+
/// Gets or sets the value for focused stroke.
54+
/// </summary>
55+
internal Color? FocusedStroke
56+
{
57+
get
58+
{
59+
return _focusedColor;
60+
}
61+
set
62+
{
63+
_focusedColor = value;
64+
}
65+
}
66+
67+
/// <summary>
68+
/// Gets or sets the drawable value.
69+
/// </summary>
70+
internal IDrawable? Drawable
71+
{
72+
get { return _drawable; }
73+
set { _drawable = value; }
74+
}
75+
76+
77+
/// <summary>
78+
/// Gets or sets the button size value.
79+
/// </summary>
80+
internal double ButtonSize { get; set; }
81+
82+
#endregion
83+
84+
#region Override Methods
85+
86+
/// <summary>
87+
/// Handler changed method.
88+
/// </summary>
89+
protected override void OnHandlerChanged()
90+
{
91+
base.OnHandlerChanged();
92+
// Unsubscribe from events to avoid duplicate handlers
93+
Focused -= SfEntry_Focused;
94+
Unfocused -= SfEntry_Unfocused;
95+
96+
// Check if the Handler is available for attaching event handlers
97+
if (Handler != null)
98+
{
99+
#if WINDOWS
100+
if (Handler.PlatformView is Microsoft.UI.Xaml.Controls.TextBox textbox)
101+
{
102+
AdjustWindowsTextBoxStyles(textbox);
103+
}
104+
#elif ANDROID
105+
if (Handler.PlatformView is AndroidX.AppCompat.Widget.AppCompatEditText textbox)
106+
{
107+
AdjustAndroidTextBoxStyles(textbox);
108+
}
109+
#endif
110+
// Subscribe to events when the handler is set
111+
Focused += SfEntry_Focused;
112+
Unfocused += SfEntry_Unfocused;
113+
}
114+
}
115+
116+
#if WINDOWS
117+
private void AdjustWindowsTextBoxStyles(Microsoft.UI.Xaml.Controls.TextBox textbox)
118+
{
119+
textbox.BorderThickness = new Microsoft.UI.Xaml.Thickness(0);
120+
textbox.Resources["TextControlBorderThemeThicknessFocused"] = textbox.BorderThickness;
121+
122+
if (textbox.Resources["TextControlBorderBrushFocused"] is GradientBrush brush &&
123+
brush.GradientStops.FirstOrDefault()?.Color is WColor color)
124+
{
125+
FocusedStroke = new Color(color.R, color.G, color.B, color.A);
126+
}
127+
}
128+
#endif
129+
130+
#if ANDROID
131+
private void AdjustAndroidTextBoxStyles(AndroidX.AppCompat.Widget.AppCompatEditText textbox)
132+
{
133+
textbox.SetBackgroundColor(Android.Graphics.Color.Transparent);
134+
var themeAccentColor = textbox.Context != null ? GetThemeAccentColor(textbox.Context) : Android.Graphics.Color.Transparent.ToArgb();
135+
var color = new Android.Graphics.Color(themeAccentColor);
136+
FocusedStroke = new Color(color.R, color.G, color.B, color.A);
137+
}
138+
#endif
139+
140+
#endregion
141+
142+
#region Methods
143+
144+
/// <summary>
145+
/// It invoked when entry get unfocused.
146+
/// </summary>
147+
/// <param name="sender">The sender.</param>
148+
/// <param name="e">The focus event args.</param>
149+
void SfEntry_Unfocused(object? sender, FocusEventArgs e)
150+
{
151+
if (_drawable is SfView sfView)
152+
{
153+
sfView.InvalidateDrawable();
154+
}
155+
}
156+
157+
/// <summary>
158+
/// It invoked when the entry get focus.
159+
/// </summary>
160+
/// <param name="sender">The sender.</param>
161+
/// <param name="e">The focus event args.</param>
162+
void SfEntry_Focused(object? sender, FocusEventArgs e)
163+
{
164+
if (_drawable is SfView sfView)
165+
{
166+
sfView.InvalidateDrawable();
167+
}
168+
}
169+
170+
#if ANDROID
171+
/// <summary>
172+
/// Get theme accent color method.
173+
/// </summary>
174+
/// <param name="context">The context.</param>
175+
static int GetThemeAccentColor(Context context)
176+
{
177+
int colorAttr = Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop
178+
? Android.Resource.Attribute.ColorAccent
179+
: context.Resources?.GetIdentifier("colorAccent", "attr", context.PackageName)
180+
?? Android.Resource.Color.BackgroundDark;
181+
182+
TypedValue outValue = new();
183+
bool resolved = context.Theme?.ResolveAttribute(colorAttr, outValue, true) ?? false;
184+
185+
return resolved ? outValue.Data : Android.Resource.Color.BackgroundDark;
186+
}
187+
#endif
188+
#endregion
189+
}
190+
}

maui/src/Core/Theme/Resources/DefaultTheme.xaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,52 @@
310310
<sys:Double x:Key="SfPyramidChartLegendFontSize">12</sys:Double>
311311
<local:StaticThemeResource x:Key="SfPyramidChartLegendDisableBrush" ResourceKey="ForegroundDisabled" />
312312

313+
<!--SfNumericEntryTheme-->
314+
<x:String x:Key="SfNumericEntryTheme">CommonTheme</x:String>
315+
<local:StaticThemeResource x:Key="SfNumericEntryNormalTextColor" ResourceKey="ContentForeground"/>
316+
<local:StaticThemeResource x:Key="SfNumericEntryDisabledTextColor" ResourceKey="ForegroundDisabled"/>
317+
<local:StaticThemeResource x:Key="SfNumericEntryFocusedTextColor" ResourceKey="ContentForeground"/>
318+
<local:StaticThemeResource x:Key="SfNumericEntryMouseHoveredTextColor" ResourceKey="ContentForeground"/>
319+
<local:StaticThemeResource x:Key="SfNumericEntryNormalBackground" ResourceKey="Transparent"/>
320+
<local:StaticThemeResource x:Key="SfNumericEntryDisabledBackground" ResourceKey="Transparent" />
321+
<local:StaticThemeResource x:Key="SfNumericEntryMouseHoveredBackground" ResourceKey="Transparent" />
322+
<local:StaticThemeResource x:Key="SfNumericEntryFocusedBackground" ResourceKey="Transparent" />
323+
<local:StaticThemeResource x:Key="SfNumericEntryNormalClearButtonColor" ResourceKey="IconColor" />
324+
<local:StaticThemeResource x:Key="SfNumericEntryPlaceholderTextColor" ResourceKey="PlaceholderForeground"/>
325+
<local:StaticThemeResource x:Key="SfNumericEntryDisabledClearButtonColor" ResourceKey="IconColorDisabled" />
326+
<local:StaticThemeResource x:Key="SfNumericEntryPressedClearButtonColor" ResourceKey="IconColorPressed" />
327+
<local:StaticThemeResource x:Key="SfNumericEntryMouseHoveredClearButtonColor" ResourceKey="IconColorHovered" />
328+
<local:StaticThemeResource x:Key="SfNumericEntryNormalStroke" ResourceKey="InputBoxBorder" />
329+
<local:StaticThemeResource x:Key="SfNumericEntryFocusedStroke" ResourceKey="PrimaryBackground" />
330+
<local:StaticThemeResource x:Key="SfNumericEntryDisabledStroke" ResourceKey="InputBorderDisabled" />
331+
<local:StaticThemeResource x:Key="SfNumericEntryMouseHoveredStroke" ResourceKey="InputBorderHovered" />
332+
<sys:Double x:Key="SfNumericEntryNormalFontSize">16</sys:Double>
333+
334+
<!--SfNumericUpDownTheme-->
335+
<x:String x:Key="SfNumericUpDownTheme">CommonTheme</x:String>
336+
<local:StaticThemeResource x:Key="SfNumericUpDownNormalTextColor" ResourceKey="ContentForeground"/>
337+
<local:StaticThemeResource x:Key="SfNumericUpDownDisabledTextColor" ResourceKey="ForegroundDisabled"/>
338+
<local:StaticThemeResource x:Key="SfNumericUpDownFocusedTextColor" ResourceKey="ContentForeground"/>
339+
<local:StaticThemeResource x:Key="SfNumericUpDownMouseHoveredTextColor" ResourceKey="ContentForeground"/>
340+
<local:StaticThemeResource x:Key="SfNumericUpDownNormalBackground" ResourceKey="Transparent"/>
341+
<local:StaticThemeResource x:Key="SfNumericUpDownDisabledBackground" ResourceKey="Transparent" />
342+
<local:StaticThemeResource x:Key="SfNumericUpDownMouseHoveredBackground" ResourceKey="Transparent" />
343+
<local:StaticThemeResource x:Key="SfNumericUpDownFocusedBackground" ResourceKey="Transparent" />
344+
<local:StaticThemeResource x:Key="SfNumericUpDownNormalArrowColor" ResourceKey="IconColor" />
345+
<local:StaticThemeResource x:Key="SfNumericUpDownDisabledArrowColor" ResourceKey="IconColorDisabled" />
346+
<local:StaticThemeResource x:Key="SfNumericUpDownPressedArrowColor" ResourceKey="IconColorPressed" />
347+
<local:StaticThemeResource x:Key="SfNumericUpDownMouseHoveredArrowColor" ResourceKey="IconColorHovered" />
348+
<local:StaticThemeResource x:Key="SfNumericUpDownNormalClearButtonColor" ResourceKey="IconColor" />
349+
<local:StaticThemeResource x:Key="SfNumericUpDownPlaceholderTextColor" ResourceKey="PlaceholderForeground"/>
350+
<local:StaticThemeResource x:Key="SfNumericUpDownDisabledClearButtonColor" ResourceKey="IconColorDisabled" />
351+
<local:StaticThemeResource x:Key="SfNumericUpDownPressedClearButtonColor" ResourceKey="IconColorPressed" />
352+
<local:StaticThemeResource x:Key="SfNumericUpDownMouseHoveredClearButtonColor" ResourceKey="IconColorHovered" />
353+
<local:StaticThemeResource x:Key="SfNumericUpDownNormalStroke" ResourceKey="InputBoxBorder" />
354+
<local:StaticThemeResource x:Key="SfNumericUpDownFocusedStroke" ResourceKey="PrimaryBackground" />
355+
<local:StaticThemeResource x:Key="SfNumericUpDownDisabledStroke" ResourceKey="InputBorderDisabled" />
356+
<local:StaticThemeResource x:Key="SfNumericUpDownMouseHoveredStroke" ResourceKey="InputBorderHovered" />
357+
<sys:Double x:Key="SfNumericUpDownNormalFontSize">16</sys:Double>
358+
313359
<!--BottomSheet-->
314360
<x:String x:Key="SfBottomSheetTheme">CommonTheme</x:String>
315361
<local:StaticThemeResource x:Key="SfBottomSheetBackground" ResourceKey="ContentBackgroundAlt1"/>

0 commit comments

Comments
 (0)