Skip to content

Commit

Permalink
Merge pull request #2 from DevEddy/develop
Browse files Browse the repository at this point in the history
Develop into main
  • Loading branch information
DevEddy authored Mar 28, 2023
2 parents 23f255c + 8e35452 commit 91becc3
Show file tree
Hide file tree
Showing 13 changed files with 2,316 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,4 @@ obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
/.idea/
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ xmlns:resolvedControls="clr-namespace:Resolved.It.Maui.Controls;assembly=Resolve
Placeholder="E-Mail"
ValidatableObject="{Binding Email}">
<resolvedControls:EnhancedEntry.MainContent>
<Entry Text="{Binding Email.Value}" Keyboard="Email" IsSpellCheckEnabled="False" />
<Entry Keyboard="Email" IsSpellCheckEnabled="False" />
</resolvedControls:EnhancedEntry.MainContent>
</resolvedControls:EnhancedEntry>
```
Expand Down Expand Up @@ -89,7 +89,6 @@ All platforms supported by .NET MAUI are supported by this library.

## Roadmap
- Support for entry types **Editor**, **Picker** and **DatePicker**
- Icons support for password toggle button
- Theme switcher for system, light and dark mode

## Screenshots
Expand Down
Binary file modified art/screenshot_android.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified art/screenshot_windows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ trigger:
branches:
include:
- main
- develop
tags:
include:
- '*'
Expand Down Expand Up @@ -101,4 +100,4 @@ jobs:
displayName: 'Publish NuGets'
inputs:
artifactName: nuget
pathToPublish: '$(Build.ArtifactStagingDirectory)'
pathToPublish: '$(Build.ArtifactStagingDirectory)'
6 changes: 4 additions & 2 deletions src/Resolved.It.Maui.App/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
Value="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}" />
<Setter Property="FocusedOutlineColor"
Value="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource Primary}}" />
<Setter Property="PlaceholderErrorColor"
Value="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource Primary}}" />
<Setter Property="PlaceholderColor"
Value="{AppThemeBinding Light={StaticResource Gray900}, Dark={StaticResource Gray200}}" />
<Setter Property="PlaceholderFocusedColor"
Expand Down Expand Up @@ -51,7 +53,7 @@
Placeholder="E-Mail"
ValidatableObject="{Binding Email}">
<resolvedControls:EnhancedEntry.MainContent>
<Entry Text="{Binding Email.Value}" Keyboard="Email" IsSpellCheckEnabled="False" />
<Entry Keyboard="Email" IsSpellCheckEnabled="False" />
</resolvedControls:EnhancedEntry.MainContent>
</resolvedControls:EnhancedEntry>

Expand All @@ -61,7 +63,7 @@
EnablePasswordToggle="True"
IsPassword="True">
<resolvedControls:EnhancedEntry.MainContent>
<Entry Text="{Binding Password.Value}" />
<Entry />
</resolvedControls:EnhancedEntry.MainContent>
</resolvedControls:EnhancedEntry>

Expand Down
5 changes: 3 additions & 2 deletions src/Resolved.It.Maui.App/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public partial class MainPageViewModel : BasePageViewModel
public MainPageViewModel()
{
AddValidations();

Email.Value = "[email protected]";
}

private bool IsInputValid() => IsValid;

[RelayCommand(CanExecute = nameof(IsInputValid))]
Expand Down Expand Up @@ -53,13 +56,11 @@ private void AddValidations()

Email.OnValidated = _ =>
{
Password.Validate(false);
CheckValidation();
};

Password.OnValidated = _ =>
{
Email.Validate(false);
CheckValidation();
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Globalization;
using Microsoft.Maui.Controls;

namespace Resolved.It.Maui.Controls.Converters;

internal class BoolToVisibilityGlyphConverter : IValueConverter
{
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value is true ? Core.Icons.Material.Visibility : Core.Icons.Material.Visibility_off;
}

public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value?.ToString() == Core.Icons.Material.Visibility;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Devices;
using Microsoft.Maui.Graphics;
using Resolved.It.Maui.Controls.Converters;
using Resolved.It.Maui.Core.Validations;

// ReSharper disable once CheckNamespace
Expand Down Expand Up @@ -87,7 +88,8 @@ public partial class EnhancedEntry : Grid
returnType: typeof(IValidatableValue),
declaringType: typeof(EnhancedEntry),
defaultValue: null,
defaultBindingMode: BindingMode.TwoWay);
defaultBindingMode: BindingMode.TwoWay,
propertyChanged: ValidatableObjectChanged);

private static readonly BindableProperty ErrorTextProperty = BindableProperty.Create(
propertyName: nameof(ErrorText),
Expand Down Expand Up @@ -220,7 +222,6 @@ private void SetupStyle()
new() { Width = GridLength.Auto }
};

_passwordToggleImage.BackgroundColor = IsPassword ? Colors.Green : Colors.Red;
_passwordToggleImage.WidthRequest = 21;
_passwordToggleImage.HeightRequest = 21;
_passwordToggleImage.Margin = DeviceInfo.Platform == DevicePlatform.WinUI
Expand All @@ -247,8 +248,6 @@ private void SetupStyle()
private void PasswordToggleImageTapGestureOnTapped(object? sender, TappedEventArgs? e)
{
IsPassword = !IsPassword;
_passwordToggleImage.BackgroundColor = IsPassword ? Colors.Green : Colors.Red;

_mainEntryControl?.Focus();
}

Expand All @@ -260,10 +259,23 @@ private void SetupView()
Grid.SetRow(_placeholderLabel, 0);
Grid.SetRow(_errorLabel, 1);

var passwordToggleImageSource = new FontImageSource
{
FontFamily = "MaterialIconsRegular",
Color = FocusedOutlineColor,
Size = 80,
FontAutoScalingEnabled = true,
Glyph = Core.Icons.Material.Visibility_off
};
passwordToggleImageSource.SetBinding(FontImageSource.ColorProperty, new Binding(nameof(FocusedOutlineColor), source: this));
passwordToggleImageSource.SetBinding(FontImageSource.GlyphProperty, new Binding(nameof(IsPassword), source: this, converter: new BoolToVisibilityGlyphConverter()));

var passwordToggleImageTapGesture = new TapGestureRecognizer();
passwordToggleImageTapGesture.Tapped += PasswordToggleImageTapGestureOnTapped;
_passwordToggleImage.GestureRecognizers.Add(passwordToggleImageTapGesture);
_passwordToggleImage.SetBinding(IsVisibleProperty, new Binding(nameof(EnablePasswordToggle), source: this, mode: BindingMode.TwoWay));
_passwordToggleImage.Source = passwordToggleImageSource;

_entryFrameContent.Children.Add(_passwordToggleImage);

_entryFrame.Content = _entryFrameContent;
Expand All @@ -275,10 +287,27 @@ private void SetupView()
Children.Add(_errorLabel);
}

private static void OnContentPropertyChanged(
BindableObject bindable,
object oldValue,
object newValue)
private static void ValidatableObjectChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is not EnhancedEntry enhancedEntry)
return;

enhancedEntry.OnValidatableObjectChanged(newValue);
}

private void OnValidatableObjectChanged(object newValue)
{
switch (_mainEntryControl)
{
case Entry entry:
entry.SetBinding(Entry.TextProperty, new Binding("Value", source: newValue, mode: BindingMode.TwoWay));
break;
}

Validate();
}

private static void OnContentPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is not EnhancedEntry enhancedEntry)
return;
Expand All @@ -299,6 +328,8 @@ private void OnMainContentChanged(object oldValue, object newValue)
oldEntry.TextChanged -= Handle_EntryValueChanged;
oldEntry.Focused -= Handle_EntryFocused;
oldEntry.Unfocused -= Handle_EntryUnfocused;
oldEntry.RemoveBinding(Entry.IsPasswordProperty);
oldEntry.RemoveBinding(Entry.TextProperty);
break;
}
_entryFrameContent.Children.Remove(oldView);
Expand All @@ -315,9 +346,12 @@ private void OnMainContentChanged(object oldValue, object newValue)
newEntry.Focused += Handle_EntryFocused;
newEntry.Unfocused += Handle_EntryUnfocused;
newEntry.RemoveBinding(Entry.PlaceholderProperty);
newEntry.RemoveBinding(Entry.TextProperty);
newEntry.Placeholder = "";
newEntry.SetBinding(Entry.IsPasswordProperty, new Binding(nameof(IsPassword), source: this, mode: BindingMode.TwoWay));
break;
default:
throw new NotSupportedException($"Content type {_mainEntryControl?.GetType().Name} is not supported yet.");
}

_mainEntryControl.HandlerChanging += NewViewOnHandlerChanging;
Expand Down
4 changes: 4 additions & 0 deletions src/Resolved.It.Maui.Core/AppBuilderExtensions.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public static class AppBuilderExtensions
{
public static MauiAppBuilder UseResolvedItMauiCore(this MauiAppBuilder builder, Action<Options>? options = default)
{
builder.ConfigureFonts(fonts =>
{
fonts.AddFont("MaterialIcons-Regular.ttf", "MaterialIconsRegular");
});
options?.Invoke(new Options());
return builder;
}
Expand Down
Loading

0 comments on commit 91becc3

Please sign in to comment.