Skip to content

Commit

Permalink
Clean textfield bindable properties formatting
Browse files Browse the repository at this point in the history
Ensure bindable properties are also TwoWay
  • Loading branch information
DevFromDownUnder committed Mar 22, 2024
1 parent dc48dec commit ad444bb
Showing 1 changed file with 59 additions and 23 deletions.
82 changes: 59 additions & 23 deletions src/UraniumUI.Material/Controls/TextField.BindableProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public partial class TextField
typeof(string),
typeof(TextField),
string.Empty,
BindingMode.TwoWay, propertyChanging: (bindable, oldValue, newValue) =>
BindingMode.TwoWay,
propertyChanging: (bindable, oldValue, newValue) =>
{
var textField = (TextField)bindable;
textField.UpdateClearIconState();
(bindable as TextField).UpdateClearIconState();
});

public Color TextColor { get => (Color)GetValue(TextColorProperty); set => SetValue(TextColorProperty, value); }
Expand All @@ -28,7 +28,10 @@ public partial class TextField
typeof(Color),
typeof(TextField),
ColorResource.GetColor("OnBackground", "OnBackgroundDark", Colors.DarkGray),
propertyChanged: (bindable, oldValue, newValue) => (bindable as TextField).EntryView.TextColor = (Color)newValue);
propertyChanged: (bindable, oldValue, newValue) =>
{
(bindable as TextField).EntryView.TextColor = (Color)newValue;
});

public string FontFamily { get => (string)GetValue(FontFamilyProperty); set => SetValue(FontFamilyProperty, value); }

Expand All @@ -52,7 +55,10 @@ public partial class TextField
typeof(Keyboard),
typeof(TextField),
Keyboard.Default,
propertyChanged: (bindable, oldValue, newValue) => (bindable as TextField).EntryView.Keyboard = (Keyboard)newValue);
propertyChanged: (bindable, oldValue, newValue) =>
{
(bindable as TextField).EntryView.Keyboard = (Keyboard)newValue;
});

public ClearButtonVisibility ClearButtonVisibility { get => (ClearButtonVisibility)GetValue(ClearButtonVisibilityProperty); set => SetValue(ClearButtonVisibilityProperty, value); }

Expand All @@ -61,7 +67,10 @@ public partial class TextField
typeof(ClearButtonVisibility),
typeof(TextField),
ClearButtonVisibility.WhileEditing,
propertyChanged: (bindable, oldValue, newValue) => (bindable as TextField).EntryView.ClearButtonVisibility = (ClearButtonVisibility)newValue);
propertyChanged: (bindable, oldValue, newValue) =>
{
(bindable as TextField).EntryView.ClearButtonVisibility = (ClearButtonVisibility)newValue;
});

public bool IsPassword { get => (bool)GetValue(IsPasswordProperty); set => SetValue(IsPasswordProperty, value); }

Expand All @@ -70,67 +79,86 @@ public partial class TextField
typeof(bool),
typeof(TextField),
false,
propertyChanged: (bindable, oldValue, newValue) => (bindable as TextField).EntryView.IsPassword = (bool)newValue);
propertyChanged: (bindable, oldValue, newValue) =>
{
(bindable as TextField).EntryView.IsPassword = (bool)newValue;
});

public object ReturnCommandParameter { get => GetValue(ReturnCommandParameterProperty); set => SetValue(ReturnCommandParameterProperty, value); }

public static readonly BindableProperty ReturnCommandParameterProperty = BindableProperty.Create(
nameof(ReturnCommandParameter),
typeof(object),
typeof(TextField));
typeof(TextField),
defaultBindingMode: BindingMode.TwoWay);

public ICommand ReturnCommand { get => (ICommand)GetValue(ReturnCommandProperty); set => SetValue(ReturnCommandProperty, value); }

public static readonly BindableProperty ReturnCommandProperty = BindableProperty.Create(
nameof(ReturnCommand),
typeof(ICommand),
typeof(TextField), defaultBindingMode: BindingMode.TwoWay);
typeof(TextField),
defaultBindingMode: BindingMode.TwoWay);

public double CharacterSpacing { get => (double)GetValue(CharacterSpacingProperty); set => SetValue(CharacterSpacingProperty, value); }

public static readonly BindableProperty CharacterSpacingProperty = BindableProperty.Create(
nameof(CharacterSpacing),
typeof(double),
typeof(TextField),
propertyChanged: (bindable, oldValue, newValue) => (bindable as TextField).EntryView.CharacterSpacing = (double)newValue);
propertyChanged: (bindable, oldValue, newValue) =>
{
(bindable as TextField).EntryView.CharacterSpacing = (double)newValue;
});

public ReturnType ReturnType { get => (ReturnType)GetValue(ReturnTypeProperty); set => SetValue(ReturnTypeProperty, value); }

public static readonly BindableProperty ReturnTypeProperty = BindableProperty.Create(
nameof(ReturnType),
typeof(ReturnType),
typeof(TextField),
propertyChanged: (bindable, oldValue, newValue) => (bindable as TextField).EntryView.ReturnType = (ReturnType)newValue);
propertyChanged: (bindable, oldValue, newValue) =>
{
(bindable as TextField).EntryView.ReturnType = (ReturnType)newValue;
});

public int SelectionLength { get => (int)GetValue(SelectionLengthProperty); set => SetValue(SelectionLengthProperty, value); }

public static readonly BindableProperty SelectionLengthProperty = BindableProperty.Create(
nameof(SelectionLength),
typeof(int),
typeof(TextField));
typeof(TextField),
defaultBindingMode: BindingMode.TwoWay);

public int CursorPosition { get => (int)GetValue(CursorPositionProperty); set => SetValue(CursorPositionProperty, value); }

public static readonly BindableProperty CursorPositionProperty = BindableProperty.Create(
nameof(CursorPosition),
typeof(int),
typeof(TextField));
typeof(TextField),
defaultBindingMode: BindingMode.TwoWay);

public bool IsTextPredictionEnabled { get => (bool)GetValue(IsTextPredictionEnabledProperty); set => SetValue(IsTextPredictionEnabledProperty, value); }

public static readonly BindableProperty IsTextPredictionEnabledProperty = BindableProperty.Create(
nameof(IsTextPredictionEnabled),
typeof(bool),
typeof(TextField),
propertyChanged: (bindable, oldValue, newValue) => (bindable as TextField).EntryView.IsTextPredictionEnabled = (bool)newValue);
propertyChanged: (bindable, oldValue, newValue) =>
{
(bindable as TextField).EntryView.IsTextPredictionEnabled = (bool)newValue;
});

public int MaxLength { get => (int)GetValue(MaxLengthProperty); set => SetValue(MaxLengthProperty, value); }

public static readonly BindableProperty MaxLengthProperty = BindableProperty.Create(
nameof(MaxLength),
typeof(int),
typeof(TextField),
propertyChanged: (bindable, oldValue, newValue) => (bindable as TextField).EntryView.MaxLength = (int)newValue);
propertyChanged: (bindable, oldValue, newValue) =>
{
(bindable as TextField).EntryView.MaxLength = (int)newValue;
});

public bool AllowClear { get => (bool)GetValue(AllowClearProperty); set => SetValue(AllowClearProperty, value); }

Expand All @@ -156,8 +184,10 @@ public partial class TextField
typeof(double),
typeof(InputField),
defaultValue: Label.FontSizeProperty.DefaultValue,
propertyChanged: (bindable, oldValue, newValue) => (bindable as TextField).EntryView.FontSize = (double)newValue
);
propertyChanged: (bindable, oldValue, newValue) =>
{
(bindable as TextField).EntryView.FontSize = (double)newValue;
});

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

Expand All @@ -166,8 +196,10 @@ public partial class TextField
typeof(FontAttributes),
typeof(TextField),
defaultValue: Entry.FontAttributesProperty.DefaultValue,
propertyChanged: (bindable, oldValue, newValue) => (bindable as TextField).EntryView.FontAttributes = (FontAttributes)newValue
);
propertyChanged: (bindable, oldValue, newValue) =>
{
(bindable as TextField).EntryView.FontAttributes = (FontAttributes)newValue;
});

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

Expand All @@ -176,8 +208,10 @@ public partial class TextField
typeof(TextAlignment),
typeof(TextField),
defaultValue: Entry.HorizontalTextAlignmentProperty.DefaultValue,
propertyChanged: (bindable, oldValue, newValue) => (bindable as TextField).EntryView.HorizontalTextAlignment = (TextAlignment)newValue
);
propertyChanged: (bindable, oldValue, newValue) =>
{
(bindable as TextField).EntryView.HorizontalTextAlignment = (TextAlignment)newValue;
});

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

Expand All @@ -186,6 +220,8 @@ public partial class TextField
typeof(Color),
typeof(TextField),
defaultValue: EntryProperties.SelectionHighlightColorProperty.DefaultValue,
propertyChanged: (bindable, oldValue, newValue) => EntryProperties.SetSelectionHighlightColor(bindable, (Color)newValue)
);
propertyChanged: (bindable, oldValue, newValue) =>
{
EntryProperties.SetSelectionHighlightColor(bindable, (Color)newValue);
});
}

0 comments on commit ad444bb

Please sign in to comment.