Skip to content

Commit

Permalink
Merge pull request #47 from Choza-rajan/NumericEntryAndUpDown
Browse files Browse the repository at this point in the history
Implementation of the SfNumericEntry and SfNumericUpDown Control in MAUI Toolkit
  • Loading branch information
PaulAndersonS authored Dec 4, 2024
2 parents 7cb6532 + fe46dfb commit eef59b0
Show file tree
Hide file tree
Showing 24 changed files with 14,130 additions and 4,174 deletions.
3 changes: 3 additions & 0 deletions maui/src/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

[assembly: InternalsVisibleTo("Syncfusion.Maui.Toolkit.UnitTest")]
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.BottomSheet")]
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.Buttons")]
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.Calendar")]
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.Carousel")]
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.Charts")]
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.Chips")]
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.EffectsView")]
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.NavigationDrawer")]
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.NumericEntry")]
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.NumericUpDown")]
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.PullToRefresh")]
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.SegmentedControl")]
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.Shimmer")]
Expand Down
190 changes: 190 additions & 0 deletions maui/src/Core/EntryView/SfEntryView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
using Color = Microsoft.Maui.Graphics.Color;
#if WINDOWS
using WColor = Windows.UI.Color;
using GradientBrush = Microsoft.UI.Xaml.Media.GradientBrush;
#elif ANDROID
using Android.Content;
using Android.OS;
using Android.Util;
#endif

namespace Syncfusion.Maui.Toolkit.EntryView
{
/// <summary>
/// The SfEntryView is a entry component which is used to create input view entry for NumericEntry.
/// </summary>
internal partial class SfEntryView : Entry
{
#region Fields

IDrawable? _drawable;

#if MACCATALYST || IOS
Color? _focusedColor = Color.FromArgb("#8EBDFF");
#else
Color? _focusedColor = Colors.Gray;
#endif

#endregion

#region Constructor

/// <summary>
/// Initializes a new instance of the <see cref="SfEntryView"/> class.
/// </summary>
public SfEntryView()
{
Initialize();
}

void Initialize()
{
Style = new Style(typeof(SfEntryView));
BackgroundColor = Colors.Transparent;
TextColor = Colors.Black;
FontSize = 14d;
}

#endregion

#region Properties

/// <summary>
/// Gets or sets the value for focused stroke.
/// </summary>
internal Color? FocusedStroke
{
get
{
return _focusedColor;
}
set
{
_focusedColor = value;
}
}

/// <summary>
/// Gets or sets the drawable value.
/// </summary>
internal IDrawable? Drawable
{
get { return _drawable; }
set { _drawable = value; }
}


/// <summary>
/// Gets or sets the button size value.
/// </summary>
internal double ButtonSize { get; set; }

#endregion

#region Override Methods

/// <summary>
/// Handler changed method.
/// </summary>
protected override void OnHandlerChanged()
{
base.OnHandlerChanged();
// Unsubscribe from events to avoid duplicate handlers
Focused -= SfEntry_Focused;
Unfocused -= SfEntry_Unfocused;

// Check if the Handler is available for attaching event handlers
if (Handler != null)
{
#if WINDOWS
if (Handler.PlatformView is Microsoft.UI.Xaml.Controls.TextBox textbox)
{
AdjustWindowsTextBoxStyles(textbox);
}
#elif ANDROID
if (Handler.PlatformView is AndroidX.AppCompat.Widget.AppCompatEditText textbox)
{
AdjustAndroidTextBoxStyles(textbox);
}
#endif
// Subscribe to events when the handler is set
Focused += SfEntry_Focused;
Unfocused += SfEntry_Unfocused;
}
}

#if WINDOWS
private void AdjustWindowsTextBoxStyles(Microsoft.UI.Xaml.Controls.TextBox textbox)
{
textbox.BorderThickness = new Microsoft.UI.Xaml.Thickness(0);
textbox.Resources["TextControlBorderThemeThicknessFocused"] = textbox.BorderThickness;

if (textbox.Resources["TextControlBorderBrushFocused"] is GradientBrush brush &&
brush.GradientStops.FirstOrDefault()?.Color is WColor color)
{
FocusedStroke = new Color(color.R, color.G, color.B, color.A);
}
}
#endif

#if ANDROID
private void AdjustAndroidTextBoxStyles(AndroidX.AppCompat.Widget.AppCompatEditText textbox)
{
textbox.SetBackgroundColor(Android.Graphics.Color.Transparent);
var themeAccentColor = textbox.Context != null ? GetThemeAccentColor(textbox.Context) : Android.Graphics.Color.Transparent.ToArgb();
var color = new Android.Graphics.Color(themeAccentColor);
FocusedStroke = new Color(color.R, color.G, color.B, color.A);
}
#endif

#endregion

#region Methods

/// <summary>
/// It invoked when entry get unfocused.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The focus event args.</param>
void SfEntry_Unfocused(object? sender, FocusEventArgs e)
{
if (_drawable is SfView sfView)
{
sfView.InvalidateDrawable();
}
}

/// <summary>
/// It invoked when the entry get focus.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The focus event args.</param>
void SfEntry_Focused(object? sender, FocusEventArgs e)
{
if (_drawable is SfView sfView)
{
sfView.InvalidateDrawable();
}
}

#if ANDROID
/// <summary>
/// Get theme accent color method.
/// </summary>
/// <param name="context">The context.</param>
static int GetThemeAccentColor(Context context)
{
int colorAttr = Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop
? Android.Resource.Attribute.ColorAccent
: context.Resources?.GetIdentifier("colorAccent", "attr", context.PackageName)
?? Android.Resource.Color.BackgroundDark;

TypedValue outValue = new();
bool resolved = context.Theme?.ResolveAttribute(colorAttr, outValue, true) ?? false;

return resolved ? outValue.Data : Android.Resource.Color.BackgroundDark;
}
#endif
#endregion
}
}
46 changes: 46 additions & 0 deletions maui/src/Core/Theme/Resources/DefaultTheme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,52 @@
<sys:Double x:Key="SfPyramidChartLegendFontSize">12</sys:Double>
<local:StaticThemeResource x:Key="SfPyramidChartLegendDisableBrush" ResourceKey="ForegroundDisabled" />

<!--SfNumericEntryTheme-->
<x:String x:Key="SfNumericEntryTheme">CommonTheme</x:String>
<local:StaticThemeResource x:Key="SfNumericEntryNormalTextColor" ResourceKey="ContentForeground"/>
<local:StaticThemeResource x:Key="SfNumericEntryDisabledTextColor" ResourceKey="ForegroundDisabled"/>
<local:StaticThemeResource x:Key="SfNumericEntryFocusedTextColor" ResourceKey="ContentForeground"/>
<local:StaticThemeResource x:Key="SfNumericEntryMouseHoveredTextColor" ResourceKey="ContentForeground"/>
<local:StaticThemeResource x:Key="SfNumericEntryNormalBackground" ResourceKey="Transparent"/>
<local:StaticThemeResource x:Key="SfNumericEntryDisabledBackground" ResourceKey="Transparent" />
<local:StaticThemeResource x:Key="SfNumericEntryMouseHoveredBackground" ResourceKey="Transparent" />
<local:StaticThemeResource x:Key="SfNumericEntryFocusedBackground" ResourceKey="Transparent" />
<local:StaticThemeResource x:Key="SfNumericEntryNormalClearButtonColor" ResourceKey="IconColor" />
<local:StaticThemeResource x:Key="SfNumericEntryPlaceholderTextColor" ResourceKey="PlaceholderForeground"/>
<local:StaticThemeResource x:Key="SfNumericEntryDisabledClearButtonColor" ResourceKey="IconColorDisabled" />
<local:StaticThemeResource x:Key="SfNumericEntryPressedClearButtonColor" ResourceKey="IconColorPressed" />
<local:StaticThemeResource x:Key="SfNumericEntryMouseHoveredClearButtonColor" ResourceKey="IconColorHovered" />
<local:StaticThemeResource x:Key="SfNumericEntryNormalStroke" ResourceKey="InputBoxBorder" />
<local:StaticThemeResource x:Key="SfNumericEntryFocusedStroke" ResourceKey="PrimaryBackground" />
<local:StaticThemeResource x:Key="SfNumericEntryDisabledStroke" ResourceKey="InputBorderDisabled" />
<local:StaticThemeResource x:Key="SfNumericEntryMouseHoveredStroke" ResourceKey="InputBorderHovered" />
<sys:Double x:Key="SfNumericEntryNormalFontSize">16</sys:Double>

<!--SfNumericUpDownTheme-->
<x:String x:Key="SfNumericUpDownTheme">CommonTheme</x:String>
<local:StaticThemeResource x:Key="SfNumericUpDownNormalTextColor" ResourceKey="ContentForeground"/>
<local:StaticThemeResource x:Key="SfNumericUpDownDisabledTextColor" ResourceKey="ForegroundDisabled"/>
<local:StaticThemeResource x:Key="SfNumericUpDownFocusedTextColor" ResourceKey="ContentForeground"/>
<local:StaticThemeResource x:Key="SfNumericUpDownMouseHoveredTextColor" ResourceKey="ContentForeground"/>
<local:StaticThemeResource x:Key="SfNumericUpDownNormalBackground" ResourceKey="Transparent"/>
<local:StaticThemeResource x:Key="SfNumericUpDownDisabledBackground" ResourceKey="Transparent" />
<local:StaticThemeResource x:Key="SfNumericUpDownMouseHoveredBackground" ResourceKey="Transparent" />
<local:StaticThemeResource x:Key="SfNumericUpDownFocusedBackground" ResourceKey="Transparent" />
<local:StaticThemeResource x:Key="SfNumericUpDownNormalArrowColor" ResourceKey="IconColor" />
<local:StaticThemeResource x:Key="SfNumericUpDownDisabledArrowColor" ResourceKey="IconColorDisabled" />
<local:StaticThemeResource x:Key="SfNumericUpDownPressedArrowColor" ResourceKey="IconColorPressed" />
<local:StaticThemeResource x:Key="SfNumericUpDownMouseHoveredArrowColor" ResourceKey="IconColorHovered" />
<local:StaticThemeResource x:Key="SfNumericUpDownNormalClearButtonColor" ResourceKey="IconColor" />
<local:StaticThemeResource x:Key="SfNumericUpDownPlaceholderTextColor" ResourceKey="PlaceholderForeground"/>
<local:StaticThemeResource x:Key="SfNumericUpDownDisabledClearButtonColor" ResourceKey="IconColorDisabled" />
<local:StaticThemeResource x:Key="SfNumericUpDownPressedClearButtonColor" ResourceKey="IconColorPressed" />
<local:StaticThemeResource x:Key="SfNumericUpDownMouseHoveredClearButtonColor" ResourceKey="IconColorHovered" />
<local:StaticThemeResource x:Key="SfNumericUpDownNormalStroke" ResourceKey="InputBoxBorder" />
<local:StaticThemeResource x:Key="SfNumericUpDownFocusedStroke" ResourceKey="PrimaryBackground" />
<local:StaticThemeResource x:Key="SfNumericUpDownDisabledStroke" ResourceKey="InputBorderDisabled" />
<local:StaticThemeResource x:Key="SfNumericUpDownMouseHoveredStroke" ResourceKey="InputBorderHovered" />
<sys:Double x:Key="SfNumericUpDownNormalFontSize">16</sys:Double>

<!--BottomSheet-->
<x:String x:Key="SfBottomSheetTheme">CommonTheme</x:String>
<local:StaticThemeResource x:Key="SfBottomSheetBackground" ResourceKey="ContentBackgroundAlt1"/>
Expand Down
Loading

0 comments on commit eef59b0

Please sign in to comment.