Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
enisn authored Mar 21, 2024
2 parents 05b1858 + 26cff06 commit 6b6c99f
Show file tree
Hide file tree
Showing 16 changed files with 240 additions and 50 deletions.
2 changes: 1 addition & 1 deletion common.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.8.0-pre.5</Version>
<Version>2.9.0-pre.1</Version>
<PackageIcon>logo_128.png</PackageIcon>
<NeutralLanguage>en</NeutralLanguage>
<RepositoryUrl>https://github.com/enisn/UraniumUI</RepositoryUrl>
Expand Down
39 changes: 38 additions & 1 deletion docs/en/themes/material/components/InputField.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,41 @@ public class TimePickerField : InputField

`HasValue` property should be overriden. That property is responsible for determining if the control has a value or not. If the control has a value, the title will be moved up. If the control does not have a value, the title will be moved down when unfocused. The following example shows how to implement the `HasValue` property for the Editor control.

![MAUI Material Input](images/inputfield-demo-custom.gif)
![MAUI Material Input](images/inputfield-demo-custom.gif)


## Styling
InputField has the following style classes that can be used to style the control:

```xml
<Style TargetType="Label" Class="InputField.Title">
<Setter Property="FontAttributes" Value="Bold" />
<!--...-->
</Style>

<Style TargetType="Border" Class="InputField.Border">
<Setter Property="MaximumHeightRequest" Value="80" />
<!--...-->
</Style>

<Style TargetType="Image" Class="InputField.Icon">
<Setter Property="HeightRequest" Value="10" />
<Setter Property="WidthRequest" Value="10" />
<!--...-->
</Style>

<Style TargetType="HorizontalStackLayout" Class="InputField.Attachments">
<Setter Property="Spacing" Value="8" />
<!--...-->
</Style>
<Style TargetType="Path" Class="InputField.ValidationIcon">
<Setter Property="Fill" Value="MediumVioletRed" />
<Setter Property="Data" Value="M7 11V1H8V11H7ZM8 13V14.01H7V13H8Z" />
<!--...-->
</Style>

<Style TargetType="Label" Class="InputField.ValidationLabel">
<Setter Property="TextColor" Value="MediumVioletRed" />
<!--...-->
</Style>
```
45 changes: 44 additions & 1 deletion docs/en/themes/material/components/TextField.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,47 @@ TextField is fully compatible with [FormView](https://enisn-projects.io/docs/en/

| Light | Dark |
| --- | --- |
| ![MAUI Material Input](images/textfield-formview-light-android.gif) | ![MAUI Material Input](images/textfield-formview-dark-windows.gif) |
| ![MAUI Material Input](images/textfield-formview-light-android.gif) | ![MAUI Material Input](images/textfield-formview-dark-windows.gif) |


## Styling
TextField has the following style classes that can be used to style the control:

```xml
<Style TargetType="Label" Class="InputField.Title">
<Setter Property="FontAttributes" Value="Bold" />
<!--...-->
</Style>

<Style TargetType="Border" Class="InputField.Border">
<Setter Property="MaximumHeightRequest" Value="80" />
<!--...-->
</Style>

<Style TargetType="Image" Class="InputField.Icon">
<Setter Property="HeightRequest" Value="10" />
<Setter Property="WidthRequest" Value="10" />
<!--...-->
</Style>

<Style TargetType="HorizontalStackLayout" Class="InputField.Attachments">
<Setter Property="Spacing" Value="8" />
<!--...-->
</Style>
<Style TargetType="Path" Class="InputField.ValidationIcon">
<Setter Property="Fill" Value="MediumVioletRed" />
<Setter Property="Data" Value="M7 11V1H8V11H7ZM8 13V14.01H7V13H8Z" />
<!--...-->
</Style>

<Style TargetType="Label" Class="InputField.ValidationLabel">
<Setter Property="TextColor" Value="MediumVioletRed" />
<!--...-->
</Style>

<Style TargetType="Path" Class="TextField.ClearIcon">
<Setter Property="Fill" Value="LightGray" />
<Setter Property="Data" Value="M1.5 1.5L13.5 13.5M1.5 13.5L13.5 1.5" />
<!--...-->
</Style>
```
1 change: 1 addition & 0 deletions src/UraniumUI.Material/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[assembly: XmlnsDefinition(Constants.XamlNamespace, Constants.NamespacePrefix + nameof(UraniumUI.Material.Attachments))]
[assembly: XmlnsDefinition(Constants.XamlNamespace, Constants.NamespacePrefix + nameof(UraniumUI.Material.Controls))]
[assembly: XmlnsDefinition(Constants.XamlNamespace, Constants.NamespacePrefix + nameof(UraniumUI.Material.Extensions))]
[assembly: XmlnsDefinition(Constants.XamlNamespace, Constants.NamespacePrefix + nameof(UraniumUI.Material.Resources))]

[assembly: Microsoft.Maui.Controls.XmlnsPrefix(Constants.XamlNamespace, "material")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ public partial class DataGrid
public static readonly BindableProperty EmptyViewTemplateProperty =
BindableProperty.Create(nameof(EmptyViewTemplate), typeof(DataTemplate), typeof(DataGrid),
propertyChanged: (bo, ov, nv) => (bo as DataGrid).OnEmptyViewTemplateSet());

public IList<DataGridColumn> Columns { get => (IList<DataGridColumn>)GetValue(ColumnsProperty); set => SetValue(ColumnsProperty, value); }

public static readonly BindableProperty ColumnsProperty =
BindableProperty.Create(nameof(Columns), typeof(IList<DataGridColumn>), typeof(DataGrid), defaultValueCreator: (bindable)=> new ObservableCollection<DataGridColumn>(),
propertyChanged: (bo, ov, nv) => (bo as DataGrid).OnColumnsSet((IList<DataGridColumn>) ov, (IList<DataGridColumn>) nv));
}
21 changes: 18 additions & 3 deletions src/UraniumUI.Material/Controls/DataGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public partial class DataGrid : Border

public Type CurrentType { get; protected set; }

public IList<DataGridColumn> Columns { get; protected set; } = new ObservableCollection<DataGridColumn>();

public bool ReadyToRender => Columns?.Any() ?? false;

public DataGrid()
Expand All @@ -27,10 +25,27 @@ public DataGrid()

InitializeFactoryMethods();
this.Padding = new Thickness(0, 10);
(Columns as INotifyCollectionChanged).CollectionChanged += Columns_CollectionChanged;
if (Columns is INotifyCollectionChanged observableColumnds)
{
observableColumnds.CollectionChanged += Columns_CollectionChanged;
}

RenderEmptyView();
}

private void OnColumnsSet(IList<DataGridColumn> oldValue, IList<DataGridColumn> newValue)
{
if (oldValue is INotifyCollectionChanged oldObservableColumns)
{
oldObservableColumns.CollectionChanged -= Columns_CollectionChanged;
}

if (newValue is INotifyCollectionChanged newObservableColumns)
{
newObservableColumns.CollectionChanged += Columns_CollectionChanged;
}
}

private void OnItemSourceSet(IList oldSource, IList newSource)
{
var sourceType = newSource?.GetType();
Expand Down
22 changes: 10 additions & 12 deletions src/UraniumUI.Material/Controls/DatePickerField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ public class DatePickerField : InputField
{
VerticalOptions = LayoutOptions.Center,
Margin = new Thickness(10, 0),
#if IOS || MACCATALYST
Opacity = 0.10,
#else
Opacity = 0,
#endif
};

protected StatefulContentView iconClear = new StatefulContentView
Expand All @@ -46,16 +42,20 @@ public DatePickerField()
DatePickerView.SetBinding(DatePickerView.DateProperty, new Binding(nameof(Date), source: this));
DatePickerView.SetBinding(DatePickerView.IsEnabledProperty, new Binding(nameof(IsEnabled), source: this));

#if MACCATALYST
labelTitle.InputTransparent = false;
labelTitle.GestureRecognizers.Add(new TapGestureRecognizer
#if MACCATALYST || IOS
labelTitle.InputTransparent = true;
base.border.GestureRecognizers.Add(new TapGestureRecognizer
{
Command = new Command(() =>
{
#if MACCATALYST
if (!HasValue)
{
Date = (DateTime)DatePicker.DateProperty.DefaultValue;
}
#else
DatePickerView.Focus();
#endif
})
});
#endif
Expand All @@ -71,6 +71,9 @@ protected virtual void OnClearTapped(object parameter)
if (IsEnabled)
{
Date = null;
#if MACCATALYST
DatePickerView.Unfocus();
#endif
}
}

Expand All @@ -79,12 +82,7 @@ protected virtual void OnDateChanged()
OnPropertyChanged(nameof(Date));
CheckAndShowValidations();

#if IOS || MACCATALYST
DatePickerView.Opacity = Date == null ? 0.1 : 1;
#else
DatePickerView.Opacity = Date == null ? 0 : 1;
#endif

if (AllowClear)
{
iconClear.IsVisible = Date != null;
Expand Down
2 changes: 2 additions & 0 deletions src/UraniumUI.Material/Controls/InputField.Validation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ public partial class InputField : IValidatable
Margin = new Thickness(0, 0, 5, 0),
Content = new Path
{
StyleClass = new[] { "InputField.ValidationIcon" },
Fill = ColorResource.GetColor("Error", "ErrorDark", Colors.Red),
Data = UraniumShapes.ExclamationCircle,
}
});

protected Lazy<Label> labelValidation = new Lazy<Label>(() => new Label
{
StyleClass = new[] { "InputField.ValidationLabel" },
HorizontalOptions = LayoutOptions.Start,
TextColor = ColorResource.GetColor("Error", "ErrorDark", Colors.Red),
});
Expand Down
10 changes: 7 additions & 3 deletions src/UraniumUI.Material/Controls/InputField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public virtual View Content

protected Label labelTitle = new Label()
{
Text = "Title",
StyleClass = new [] { "InputField.Title" },
HorizontalOptions = LayoutOptions.Start,
VerticalOptions = LayoutOptions.Start,
InputTransparent = true,
Expand All @@ -41,7 +41,7 @@ public virtual View Content

protected Border border = new Border
{
Padding = 0,
StyleClass = new [] { "InputField.Border" },
StrokeThickness = 1,
StrokeDashOffset = 0,
BackgroundColor = Colors.Transparent,
Expand All @@ -53,6 +53,7 @@ public virtual View Content
{
return new Image
{
StyleClass = new [] { "InputField.Icon" },
HorizontalOptions = LayoutOptions.Start,
VerticalOptions = LayoutOptions.Center,
WidthRequest = 20,
Expand All @@ -61,7 +62,10 @@ public virtual View Content
};
});

protected HorizontalStackLayout endIconsContainer = new HorizontalStackLayout();
protected readonly HorizontalStackLayout endIconsContainer = new HorizontalStackLayout
{
StyleClass = new[] { "InputField.Attachments" },
};

public IList<IView> Attachments => endIconsContainer.Children;

Expand Down
31 changes: 31 additions & 0 deletions src/UraniumUI.Material/Controls/TextField.BindableProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Windows.Input;
using UraniumUI.Resources;
using UraniumUI.Material.Extensions;

namespace UraniumUI.Material.Controls;

Expand Down Expand Up @@ -157,4 +158,34 @@ public partial class TextField
defaultValue: Label.FontSizeProperty.DefaultValue,
propertyChanged: (bindable, oldValue, newValue) => (bindable as TextField).EntryView.FontSize = (double)newValue
);

public FontAttributes FontAttributes { get => (FontAttributes)GetValue(FontAttributesProperty); set => SetValue(FontAttributesProperty, value); }

public static readonly BindableProperty FontAttributesProperty = BindableProperty.Create(
nameof(FontAttributes),
typeof(FontAttributes),
typeof(TextField),
defaultValue: Entry.FontAttributesProperty.DefaultValue,
propertyChanged: (bindable, oldValue, newValue) => (bindable as TextField).EntryView.FontAttributes = (FontAttributes)newValue
);

public TextAlignment HorizontalTextAlignment { get => (TextAlignment)GetValue(HorizontalTextAlignmentProperty); set => SetValue(HorizontalTextAlignmentProperty, value); }

public static readonly BindableProperty HorizontalTextAlignmentProperty = BindableProperty.Create(
nameof(HorizontalTextAlignment),
typeof(TextAlignment),
typeof(TextField),
defaultValue: Entry.HorizontalTextAlignmentProperty.DefaultValue,
propertyChanged: (bindable, oldValue, newValue) => (bindable as TextField).EntryView.HorizontalTextAlignment = (TextAlignment)newValue
);

public Color SelectionHighlightColor { get => (Color)GetValue(SelectionHighlightColorProperty); set => SetValue(SelectionHighlightColorProperty, value); }

public static readonly BindableProperty SelectionHighlightColorProperty = BindableProperty.Create(
nameof(SelectionHighlightColor),
typeof(Color),
typeof(TextField),
defaultValue: EntryProperties.SelectionHighlightColorProperty.DefaultValue,
propertyChanged: (bindable, oldValue, newValue) => EntryProperties.SetSelectionHighlightColor(bindable, (Color)newValue)
);
}
23 changes: 9 additions & 14 deletions src/UraniumUI.Material/Controls/TextField.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#if WINDOWS
using Microsoft.Maui.Platform;
#endif
using Plainer.Maui.Controls;
using Plainer.Maui.Controls;
using UraniumUI.Material.Extensions;
using UraniumUI.Pages;
using UraniumUI.Resources;
using UraniumUI.Views;
Expand Down Expand Up @@ -30,6 +28,7 @@ public partial class TextField : InputField
Margin = new Thickness(0, 0, 5, 0),
Content = new Path
{
StyleClass = new[] { "TextField.ClearIcon" },
Data = UraniumShapes.X,
Fill = ColorResource.GetColor("OnBackground", "OnBackgroundDark", Colors.DarkGray).WithAlpha(.5f),
}
Expand Down Expand Up @@ -63,16 +62,6 @@ public TextField()
protected override void OnHandlerChanged()
{
base.OnHandlerChanged();
#if WINDOWS
if (EntryView.Handler.PlatformView is Microsoft.UI.Xaml.Controls.TextBox textBox)
{
textBox.SelectionHighlightColor = new Microsoft.UI.Xaml.Media.SolidColorBrush(ColorResource.GetColor("Primary", "PrimaryDark", Colors.Purple).ToWindowsColor());
textBox.BorderThickness = new Microsoft.UI.Xaml.Thickness(0);

textBox.Style = null;
}
#endif

if (Handler is null)
{
EntryView.TextChanged -= EntryView_TextChanged;
Expand All @@ -82,9 +71,15 @@ protected override void OnHandlerChanged()
{
EntryView.TextChanged += EntryView_TextChanged;
EntryView.Completed += EntryView_Completed;
ApplyAttachedProperties();
}
}

protected virtual void ApplyAttachedProperties()
{
EntryProperties.SetSelectionHighlightColor(EntryView, SelectionHighlightColor);
}

private void EntryView_TextChanged(object sender, TextChangedEventArgs e)
{
if (string.IsNullOrEmpty(e.OldTextValue) || string.IsNullOrEmpty(e.NewTextValue))
Expand Down
Loading

0 comments on commit 6b6c99f

Please sign in to comment.