Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some updates for MaterialTextField & MaterialSelectionControl #411

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Samples/MaterialMvvmSample.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected override void OnCreate(Bundle savedInstanceState)
ToolbarResource = Resource.Layout.Toolbar;

base.OnCreate(savedInstanceState);
Rg.Plugins.Popup.Popup.Init(this, savedInstanceState);
Rg.Plugins.Popup.Popup.Init(this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has this been removed ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you do not remove "savedInstanceState" Rg.Plugins.Popup gives compile error.

Xamarin.Forms.Forms.Init(this, savedInstanceState);
Material.Init(this, savedInstanceState);

Expand All @@ -31,4 +31,4 @@ public override void OnBackPressed()
Material.HandleBackButton(base.OnBackPressed);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,9 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties TriggeredFromHotReload="False" />
</VisualStudio>
</ProjectExtensions>
</Project>
11 changes: 11 additions & 0 deletions Samples/MaterialMvvmSample/Images/eye-slash-solid-18dp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions Samples/MaterialMvvmSample/Images/eye-solid-18dp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Samples/MaterialMvvmSample/MaterialMvvmSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
</PropertyGroup>

<ItemGroup>
<None Remove="Images\eye-slash-solid-18dp.svg" />
<None Remove="Images\eye-solid-18dp.svg" />
Comment on lines +13 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove these lines :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added new icon for password show hide example.

</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Images\eye-slash-solid-18dp.svg" />
<EmbeddedResource Include="Images\eye-solid-18dp.svg" />
<EmbeddedResource Include="Images\slideshow-black-18dp.svg" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System.Windows.Input;
using Xamarin.Forms;
using XamSvg.XamForms;
using XF.Material.Forms.UI;
using XF.Material.Forms.UI.Dialogs;

namespace MaterialMvvmSample.ViewModels
Expand All @@ -16,13 +18,45 @@ public class MaterialTextFieldViewModel : BaseViewModel
};

public ICommand OpenCustomChoiceCommand { get; }
public ICommand CustomChoiceParameterUsingCommand { get; }

public MaterialTextFieldViewModel()
{
OpenCustomChoiceCommand = new Command(async () =>
{
await MaterialDialog.Instance.AlertAsync("Command tapped. Do what you want ! You can open a custom popup, ask some data, and update the textfield text with this data");
});

CustomChoiceParameterUsingCommand = new Command<MaterialTextField>(async (e) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a viewmodel should not receive a UI object. Using MaterialTextField, which is a UI object, as a parameter is a very bad practive. Instead create a new class with the interesting parameters only.

To change a property of a ui item, use binding and datatriggers instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a sample for testing ChoiceCommandParameter. I use this approach for example hide show datepicker for cross platform. Whay do you think that is not good practive?

{

if (e != null)
{

if (e.InputType == MaterialTextFieldInputType.Password)
{
e.InputType = MaterialTextFieldInputType.Plain;
e.TrailingIconTintColor = Color.Gray;
e.TrailingIcon = new SvgImageSource()
{
Svg = "res:images.eye-solid-18dp"
};
}
else
{
e.InputType = MaterialTextFieldInputType.Password;
e.TrailingIconTintColor = Color.Black;
e.TrailingIcon = new SvgImageSource()
{
Svg = "res:images.eye-slash-solid-18dp"
};
}
}

});



}
}
}
57 changes: 51 additions & 6 deletions Samples/MaterialMvvmSample/Views/CheckboxesView.xaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:material="clr-namespace:XF.Material.Forms.UI;assembly=XF.Material"
x:Class="MaterialMvvmSample.Views.CheckboxesView">
<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage
x:Class="MaterialMvvmSample.Views.CheckboxesView"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:material="clr-namespace:XF.Material.Forms.UI;assembly=XF.Material">
<ContentPage.Content>
<StackLayout Orientation="Vertical">
<material:MaterialCheckbox Text="My Material Checkbox" />

<material:MaterialCheckbox
HorizontalOptions="Center"
HorizontalSize="Auto"
Text="My Material Checkbox Horizontal Size Auto" />

<material:MaterialCheckbox
HorizontalSize="Fill"
Text="My Material Checkbox Letter Spacing"
TextLetterSpacing="5" />

<material:MaterialRadioButtonGroup
BackgroundColor="Bisque"
HorizontalOptions="Fill"
Orientation="Vertical"
TextLetterSpacing="5">

<material:MaterialRadioButtonGroup.Choices>
<x:Array Type="{x:Type x:String}">
<x:String>Radio 1</x:String>
<x:String>Radio 2</x:String>
</x:Array>
</material:MaterialRadioButtonGroup.Choices>

</material:MaterialRadioButtonGroup>

<material:MaterialCheckboxGroup
BackgroundColor="LightYellow"
HorizontalOptions="Center"
Orientation="Horizontal">

<material:MaterialCheckboxGroup.Choices>
<x:Array Type="{x:Type x:String}">
<x:String>Checkbox 1</x:String>
<x:String>Checkbox 2</x:String>
</x:Array>
</material:MaterialCheckboxGroup.Choices>

</material:MaterialCheckboxGroup>


</StackLayout>




</ContentPage.Content>
</ContentPage>
128 changes: 92 additions & 36 deletions Samples/MaterialMvvmSample/Views/MaterialTextFieldView.xaml
Original file line number Diff line number Diff line change
@@ -1,59 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage
x:Class="MaterialMvvmSample.Views.MaterialTextFieldView"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:material="clr-namespace:XF.Material.Forms.UI;assembly=XF.Material"
xmlns:viewModels="clr-namespace:MaterialMvvmSample.ViewModels;assembly=MaterialMvvmSample"
xmlns:xamForms="clr-namespace:XamSvg.XamForms;assembly=XamSvg.XamForms"
x:Class="MaterialMvvmSample.Views.MaterialTextFieldView"
x:DataType="viewModels:MaterialTextFieldViewModel">

<ScrollView>
<StackLayout Orientation="Vertical"
Padding="20">
<material:MaterialTextField Placeholder="Auto Capitalization"
IsAutoCapitalizationEnabled="True" />
<StackLayout Padding="20" Orientation="Vertical">

<material:MaterialTextField
AlwaysShowUnderline="False"
CardCornerRadius="8,4"
FloatingPlaceholderEnabled="False"
LeadingIcon="icon_plus"
Placeholder="PlaceHolder = False"
ShouldAnimateUnderline="False"
TextFontSize="12" />

<material:MaterialTextField
CardCornerRadius="0"
FloatingPlaceholderEnabled="False"
Placeholder="PlaceHolder = False" />

<material:MaterialTextField Placeholder="ALL CAPS"
IsTextAllCaps="True" />
<material:MaterialTextField
ErrorText="You should write CAPS"
HasError="True"
HasErrorFalseOnTextChanged="True"
IsTextAllCaps="True"
Placeholder="ALL CAPS"
Unfocused="MaterialTextField_Unfocused" />

<material:MaterialTextField Placeholder="Auto Capitalization AND ALL CAPS"
IsTextAllCaps="True"
IsAutoCapitalizationEnabled="true" />
<material:MaterialTextField
IsAutoCapitalizationEnabled="true"
IsTextAllCaps="True"
Placeholder="Auto Capitalization AND ALL CAPS" />

<StackLayout Orientation="Horizontal">
<material:MaterialTextField Placeholder="With Icon"
LeadingIcon="icon_plus"
Style="{StaticResource GreenField}"
HorizontalOptions="FillAndExpand" />
<material:MaterialButton Text="OK" HorizontalOptions="Start" />
<material:MaterialTextField
HorizontalOptions="FillAndExpand"
LeadingIcon="icon_plus"
Placeholder="With Icon"
Style="{StaticResource GreenField}" />
<material:MaterialButton HorizontalOptions="Start" Text="OK" />
</StackLayout>

<material:MaterialTextField Placeholder="Choices"
InputType="Choice"
Choices="{Binding Choices}" />
<material:MaterialTextField Placeholder="Quick single choice"
InputType="SingleImmediateChoice"
Choices="{Binding Choices}"/>
<material:MaterialTextField Placeholder="Custom command choice"
Text="Jean Dupond"
InputType="CommandChoice"
ChoiceSelectedCommand="{Binding OpenCustomChoiceCommand}" />
<material:MaterialTextField
Choices="{Binding Choices}"
InputType="Choice"
HasError="True"
ErrorText="Some Error"
HasErrorFalseOnTextChanged="True"
Placeholder="Choices" />
<material:MaterialTextField
Choices="{Binding Choices}"
InputType="SingleImmediateChoice"
Placeholder="Quick single choice" />
<material:MaterialTextField
ChoiceSelectedCommand="{Binding OpenCustomChoiceCommand}"
ChoiceSelectedCommandParameter="choice-selected-command-parameter"
InputType="CommandChoice"
Placeholder="Custom command choice"
Text="Jean Dupond" />
<material:MaterialDateField Placeholder="Date" />
<material:MaterialDateField Placeholder="Date, bottom tip, leading and trailing icons"
HelperText="Your birthday"
Date="2020/08/28"
Format="yyyy/MM/dd">

<material:MaterialDateField
Date="2020/08/28"
Format="yyyy/MM/dd"
HelperText="Your birthday"
Placeholder="Date, bottom tip, leading and trailing icons">
<material:MaterialDateField.LeadingIcon>
<xamForms:SvgImageSource Svg="res:images.slideshow-black-18dp" Height="200" />
<xamForms:SvgImageSource Height="200" Svg="res:images.slideshow-black-18dp" />
</material:MaterialDateField.LeadingIcon>
<material:MaterialDateField.DropDrownArrowIcon>
<xamForms:SvgImageSource Svg="res:images.slideshow-black-18dp" Height="200" />
<xamForms:SvgImageSource Height="200" Svg="res:images.slideshow-black-18dp" />
</material:MaterialDateField.DropDrownArrowIcon>
</material:MaterialDateField>
<material:MaterialDateField Placeholder="Error"
ErrorText="some error"
HasError="True" />
<material:MaterialDateField
ErrorText="some error"
HasError="True"
Placeholder="Error" />

<material:MaterialTextField
InputType="Password"
Placeholder="Trailing Icon Command"
Text="password"
TrailingIconCommand="{Binding CustomChoiceParameterUsingCommand}"
TrailingIconCommandParameter="{Binding Source={x:RelativeSource Mode=Self}}"
TrailingIconTintColor="Black">
<material:MaterialTextField.TrailingIcon>
<xamForms:SvgImageSource Height="200" Svg="res:images.eye-slash-solid-18dp" />
</material:MaterialTextField.TrailingIcon>

</material:MaterialTextField>

<material:MaterialTextField
ErrorText="Error Test"
HasError="False"
InputType="Password"
Placeholder="Trailing Icon Selected"
Text="password"
TrailingIconSelected="MaterialTextField_TrailingIconSelected"
TrailingIconSize="18"
TrailingIconTintColor="DodgerBlue">
<material:MaterialTextField.TrailingIcon>
<xamForms:SvgImageSource Height="200" Svg="res:images.eye-slash-solid-18dp" />
</material:MaterialTextField.TrailingIcon>

</material:MaterialTextField>

</StackLayout>
</ScrollView>
Expand Down
45 changes: 44 additions & 1 deletion Samples/MaterialMvvmSample/Views/MaterialTextFieldView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using MaterialMvvmSample.ViewModels;
using System.Diagnostics;
using MaterialMvvmSample.ViewModels;
using Xamarin.Forms;
using XamSvg.XamForms;
using XF.Material.Forms.UI;

namespace MaterialMvvmSample.Views
{
Expand All @@ -10,5 +13,45 @@ public MaterialTextFieldView()
InitializeComponent();
BindingContext = new MaterialTextFieldViewModel();
}

private void MaterialTextField_TrailingIconSelected(object sender, System.EventArgs e)
{

var s = sender as MaterialTextField;


if (s.InputType == MaterialTextFieldInputType.Password)
{
s.InputType = MaterialTextFieldInputType.Plain;
s.TrailingIcon = new SvgImageSource()
{
Svg = "res:images.eye-solid-18dp"
};
}
else
{
s.InputType = MaterialTextFieldInputType.Password;
s.TrailingIcon = new SvgImageSource()
{
Svg = "res:images.eye-slash-solid-18dp"
};
}





Debug.WriteLine(e);
}

private void MaterialTextField_Unfocused(object sender, FocusEventArgs e)
{
var s = sender as MaterialTextField;

if (s.Text != "CAPS")
{
s.HasError = true;
}
}
}
}
Loading