2016-05-24 04:56:38 +03:00
|
|
|
|
using System;
|
|
|
|
|
using Xamarin.Forms;
|
2016-05-13 07:11:32 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.App.Controls
|
|
|
|
|
{
|
2016-05-18 04:28:19 +03:00
|
|
|
|
public class FormEntryCell : ExtendedViewCell
|
2016-05-13 07:11:32 +03:00
|
|
|
|
{
|
2016-06-28 05:17:49 +03:00
|
|
|
|
public FormEntryCell(
|
|
|
|
|
string labelText,
|
|
|
|
|
Keyboard entryKeyboard = null,
|
|
|
|
|
bool IsPassword = false,
|
|
|
|
|
VisualElement nextElement = null,
|
|
|
|
|
bool useLabelAsPlaceholder = false,
|
2016-07-03 07:27:10 +03:00
|
|
|
|
string imageSource = null,
|
|
|
|
|
Thickness? containerPadding = null)
|
2016-05-13 07:11:32 +03:00
|
|
|
|
{
|
2016-06-28 03:56:59 +03:00
|
|
|
|
if(!useLabelAsPlaceholder)
|
2016-05-13 07:11:32 +03:00
|
|
|
|
{
|
2016-06-28 03:56:59 +03:00
|
|
|
|
Label = new Label
|
|
|
|
|
{
|
|
|
|
|
Text = labelText,
|
|
|
|
|
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
|
|
|
|
|
VerticalOptions = LayoutOptions.Start,
|
2016-06-28 05:17:49 +03:00
|
|
|
|
Style = (Style)Application.Current.Resources["text-muted"],
|
|
|
|
|
HorizontalOptions = LayoutOptions.FillAndExpand
|
2016-06-28 03:56:59 +03:00
|
|
|
|
};
|
2016-08-14 04:43:15 +03:00
|
|
|
|
|
|
|
|
|
if(Device.OS == TargetPlatform.Android)
|
|
|
|
|
{
|
|
|
|
|
Label.FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label));
|
|
|
|
|
}
|
2016-06-28 03:56:59 +03:00
|
|
|
|
}
|
2016-05-13 07:11:32 +03:00
|
|
|
|
|
|
|
|
|
Entry = new ExtendedEntry
|
|
|
|
|
{
|
|
|
|
|
Keyboard = entryKeyboard,
|
2016-05-17 06:54:24 +03:00
|
|
|
|
HasBorder = false,
|
2016-05-24 04:56:38 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.CenterAndExpand,
|
2016-06-28 05:17:49 +03:00
|
|
|
|
IsPassword = IsPassword,
|
|
|
|
|
AllowClear = true,
|
|
|
|
|
HorizontalOptions = LayoutOptions.FillAndExpand
|
2016-05-13 07:11:32 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-08-14 04:43:15 +03:00
|
|
|
|
if(Device.OS == TargetPlatform.Android)
|
|
|
|
|
{
|
|
|
|
|
Entry.FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label));
|
|
|
|
|
Entry.TextColor = Color.Black;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 03:56:59 +03:00
|
|
|
|
if(useLabelAsPlaceholder)
|
|
|
|
|
{
|
|
|
|
|
Entry.Placeholder = labelText;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-24 04:56:38 +03:00
|
|
|
|
if(nextElement != null)
|
|
|
|
|
{
|
|
|
|
|
Entry.ReturnType = Enums.ReturnType.Next;
|
|
|
|
|
Entry.Completed += (object sender, EventArgs e) => { nextElement.Focus(); };
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 05:17:49 +03:00
|
|
|
|
var imageStackLayout = new StackLayout
|
2016-05-13 07:11:32 +03:00
|
|
|
|
{
|
2016-07-03 07:27:10 +03:00
|
|
|
|
Padding = containerPadding ?? new Thickness(15, 10),
|
2016-06-28 05:17:49 +03:00
|
|
|
|
Orientation = StackOrientation.Horizontal,
|
|
|
|
|
Spacing = 10,
|
|
|
|
|
HorizontalOptions = LayoutOptions.FillAndExpand,
|
|
|
|
|
VerticalOptions = LayoutOptions.FillAndExpand
|
2016-05-13 07:11:32 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-06-28 05:17:49 +03:00
|
|
|
|
if(imageSource != null)
|
|
|
|
|
{
|
|
|
|
|
var tgr = new TapGestureRecognizer();
|
|
|
|
|
tgr.Tapped += Tgr_Tapped;
|
|
|
|
|
|
|
|
|
|
var theImage = new Image
|
|
|
|
|
{
|
|
|
|
|
Source = imageSource,
|
|
|
|
|
HorizontalOptions = LayoutOptions.Start,
|
|
|
|
|
VerticalOptions = LayoutOptions.Center
|
|
|
|
|
};
|
|
|
|
|
theImage.GestureRecognizers.Add(tgr);
|
|
|
|
|
|
|
|
|
|
imageStackLayout.Children.Add(theImage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var formStackLayout = new StackLayout
|
|
|
|
|
{
|
|
|
|
|
HorizontalOptions = LayoutOptions.FillAndExpand,
|
|
|
|
|
VerticalOptions = LayoutOptions.FillAndExpand
|
|
|
|
|
};
|
2016-06-28 03:56:59 +03:00
|
|
|
|
if(!useLabelAsPlaceholder)
|
|
|
|
|
{
|
2016-06-28 05:17:49 +03:00
|
|
|
|
formStackLayout.Children.Add(Label);
|
2016-06-28 03:56:59 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 05:17:49 +03:00
|
|
|
|
formStackLayout.Children.Add(Entry);
|
|
|
|
|
imageStackLayout.Children.Add(formStackLayout);
|
2016-05-13 07:11:32 +03:00
|
|
|
|
|
2016-07-05 05:35:49 +03:00
|
|
|
|
Tapped += FormEntryCell_Tapped;
|
|
|
|
|
|
2016-06-28 05:17:49 +03:00
|
|
|
|
View = imageStackLayout;
|
2016-05-13 07:11:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Label Label { get; private set; }
|
|
|
|
|
public ExtendedEntry Entry { get; private set; }
|
2016-06-28 05:17:49 +03:00
|
|
|
|
|
|
|
|
|
private void Tgr_Tapped(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Entry.Focus();
|
|
|
|
|
}
|
2016-07-05 05:35:49 +03:00
|
|
|
|
|
|
|
|
|
private void FormEntryCell_Tapped(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Entry.Focus();
|
|
|
|
|
}
|
2016-05-13 07:11:32 +03:00
|
|
|
|
}
|
|
|
|
|
}
|