From 15be1cbf43710a0caeb1d98b8c34e9838e78b08a Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 10 May 2016 22:53:34 -0400 Subject: [PATCH] Android styles and theme, updated to extended controls --- src/Android/Android.csproj | 9 ++ src/Android/Controls/ExtendedEntryRenderer.cs | 15 +-- src/Android/Properties/AndroidManifest.xml | 2 +- src/Android/Resources/Resource.Designer.cs | 66 ++++++---- src/Android/Resources/values-v21/styles.xml | 9 ++ src/Android/Resources/values/colors.xml | 8 ++ src/Android/Resources/values/styles.xml | 9 ++ src/App/App.csproj | 1 + src/App/Controls/BottomBorderEntry.cs | 2 +- src/App/Controls/ExtendedEntry.cs | 19 +-- src/App/Controls/ExtendedPicker.cs | 35 +++++ src/App/Pages/SyncPage.cs | 27 ++-- src/App/Pages/VaultAddSitePage.cs | 123 +++++++++--------- src/iOS/Controls/ExtendedEntryRenderer.cs | 32 +---- src/iOS/Controls/ExtendedPickerRenderer.cs | 64 +++++++++ src/iOS/iOS.csproj | 1 + 16 files changed, 274 insertions(+), 148 deletions(-) create mode 100644 src/Android/Resources/values-v21/styles.xml create mode 100644 src/Android/Resources/values/colors.xml create mode 100644 src/Android/Resources/values/styles.xml create mode 100644 src/App/Controls/ExtendedPicker.cs create mode 100644 src/iOS/Controls/ExtendedPickerRenderer.cs diff --git a/src/Android/Android.csproj b/src/Android/Android.csproj index 1a58f0a73..2d0a6a541 100644 --- a/src/Android/Android.csproj +++ b/src/Android/Android.csproj @@ -224,6 +224,15 @@ App + + + + + + + + + diff --git a/src/Android/Controls/ExtendedEntryRenderer.cs b/src/Android/Controls/ExtendedEntryRenderer.cs index a1e39d5f4..dada4bc15 100644 --- a/src/Android/Controls/ExtendedEntryRenderer.cs +++ b/src/Android/Controls/ExtendedEntryRenderer.cs @@ -26,7 +26,6 @@ namespace Bit.Android.Controls } SetBorder(view); - SetPlaceholderTextColor(view); SetMaxLength(view); } @@ -36,14 +35,10 @@ namespace Bit.Android.Controls if(e.PropertyName == ExtendedEntry.HasBorderProperty.PropertyName || e.PropertyName == ExtendedEntry.HasOnlyBottomBorderProperty.PropertyName - || e.PropertyName == ExtendedEntry.BorderColorProperty.PropertyName) + || e.PropertyName == ExtendedEntry.BottomBorderColorProperty.PropertyName) { SetBorder(view); } - if(e.PropertyName == ExtendedEntry.PlaceholderTextColorProperty.PropertyName) - { - SetPlaceholderTextColor(view); - } else { base.OnElementPropertyChanged(sender, e); @@ -63,13 +58,5 @@ namespace Bit.Android.Controls { Control.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(view.MaxLength) }); } - - private void SetPlaceholderTextColor(ExtendedEntry view) - { - if(view.PlaceholderTextColor != Xamarin.Forms.Color.Default) - { - Control.SetHintTextColor(view.PlaceholderTextColor.ToAndroid()); - } - } } } diff --git a/src/Android/Properties/AndroidManifest.xml b/src/Android/Properties/AndroidManifest.xml index 8b466acce..641055128 100644 --- a/src/Android/Properties/AndroidManifest.xml +++ b/src/Android/Properties/AndroidManifest.xml @@ -2,5 +2,5 @@ - + \ No newline at end of file diff --git a/src/Android/Resources/Resource.Designer.cs b/src/Android/Resources/Resource.Designer.cs index 269d5f82e..d19ac139b 100644 --- a/src/Android/Resources/Resource.Designer.cs +++ b/src/Android/Resources/Resource.Designer.cs @@ -1166,32 +1166,32 @@ namespace Bit.Android public partial class Color { - // aapt resource value: 0x7f0b0048 - public const int abc_background_cache_hint_selector_material_dark = 2131427400; + // aapt resource value: 0x7f0b004d + public const int abc_background_cache_hint_selector_material_dark = 2131427405; - // aapt resource value: 0x7f0b0049 - public const int abc_background_cache_hint_selector_material_light = 2131427401; + // aapt resource value: 0x7f0b004e + public const int abc_background_cache_hint_selector_material_light = 2131427406; - // aapt resource value: 0x7f0b004a - public const int abc_color_highlight_material = 2131427402; + // aapt resource value: 0x7f0b004f + public const int abc_color_highlight_material = 2131427407; // aapt resource value: 0x7f0b0004 public const int abc_input_method_navigation_guard = 2131427332; - // aapt resource value: 0x7f0b004b - public const int abc_primary_text_disable_only_material_dark = 2131427403; + // aapt resource value: 0x7f0b0050 + public const int abc_primary_text_disable_only_material_dark = 2131427408; - // aapt resource value: 0x7f0b004c - public const int abc_primary_text_disable_only_material_light = 2131427404; + // aapt resource value: 0x7f0b0051 + public const int abc_primary_text_disable_only_material_light = 2131427409; - // aapt resource value: 0x7f0b004d - public const int abc_primary_text_material_dark = 2131427405; + // aapt resource value: 0x7f0b0052 + public const int abc_primary_text_material_dark = 2131427410; - // aapt resource value: 0x7f0b004e - public const int abc_primary_text_material_light = 2131427406; + // aapt resource value: 0x7f0b0053 + public const int abc_primary_text_material_light = 2131427411; - // aapt resource value: 0x7f0b004f - public const int abc_search_url_text = 2131427407; + // aapt resource value: 0x7f0b0054 + public const int abc_search_url_text = 2131427412; // aapt resource value: 0x7f0b0005 public const int abc_search_url_text_normal = 2131427333; @@ -1202,11 +1202,14 @@ namespace Bit.Android // aapt resource value: 0x7f0b0007 public const int abc_search_url_text_selected = 2131427335; - // aapt resource value: 0x7f0b0050 - public const int abc_secondary_text_material_dark = 2131427408; + // aapt resource value: 0x7f0b0055 + public const int abc_secondary_text_material_dark = 2131427413; - // aapt resource value: 0x7f0b0051 - public const int abc_secondary_text_material_light = 2131427409; + // aapt resource value: 0x7f0b0056 + public const int abc_secondary_text_material_light = 2131427414; + + // aapt resource value: 0x7f0b004c + public const int accent = 2131427404; // aapt resource value: 0x7f0b0008 public const int accent_material_dark = 2131427336; @@ -1262,6 +1265,9 @@ namespace Bit.Android // aapt resource value: 0x7f0b0003 public const int cardview_shadow_start_color = 2131427331; + // aapt resource value: 0x7f0b0049 + public const int darkgray = 2131427401; + // aapt resource value: 0x7f0b003e public const int design_fab_shadow_end_color = 2131427390; @@ -1310,6 +1316,9 @@ namespace Bit.Android // aapt resource value: 0x7f0b001b public const int foreground_material_light = 2131427355; + // aapt resource value: 0x7f0b004a + public const int gray = 2131427402; + // aapt resource value: 0x7f0b001c public const int highlighted_text_material_dark = 2131427356; @@ -1358,6 +1367,9 @@ namespace Bit.Android // aapt resource value: 0x7f0b002b public const int material_grey_900 = 2131427371; + // aapt resource value: 0x7f0b004b + public const int primary = 2131427403; + // aapt resource value: 0x7f0b002c public const int primary_dark_material_dark = 2131427372; @@ -1406,11 +1418,11 @@ namespace Bit.Android // aapt resource value: 0x7f0b003b public const int switch_thumb_disabled_material_light = 2131427387; - // aapt resource value: 0x7f0b0052 - public const int switch_thumb_material_dark = 2131427410; + // aapt resource value: 0x7f0b0057 + public const int switch_thumb_material_dark = 2131427415; - // aapt resource value: 0x7f0b0053 - public const int switch_thumb_material_light = 2131427411; + // aapt resource value: 0x7f0b0058 + public const int switch_thumb_material_light = 2131427416; // aapt resource value: 0x7f0b003c public const int switch_thumb_normal_material_dark = 2131427388; @@ -1418,6 +1430,9 @@ namespace Bit.Android // aapt resource value: 0x7f0b003d public const int switch_thumb_normal_material_light = 2131427389; + // aapt resource value: 0x7f0b0048 + public const int white = 2131427400; + static Color() { global::Android.Runtime.ResourceIdManager.UpdateIdValues(); @@ -3610,6 +3625,9 @@ namespace Bit.Android // aapt resource value: 0x7f0a015b public const int Base_Widget_Design_TabLayout = 2131362139; + // aapt resource value: 0x7f0a0172 + public const int BitwardenTheme = 2131362162; + // aapt resource value: 0x7f0a0017 public const int CardView = 2131361815; diff --git a/src/Android/Resources/values-v21/styles.xml b/src/Android/Resources/values-v21/styles.xml new file mode 100644 index 000000000..3f5cd69cb --- /dev/null +++ b/src/Android/Resources/values-v21/styles.xml @@ -0,0 +1,9 @@ + + + + diff --git a/src/Android/Resources/values/colors.xml b/src/Android/Resources/values/colors.xml new file mode 100644 index 000000000..56cc94782 --- /dev/null +++ b/src/Android/Resources/values/colors.xml @@ -0,0 +1,8 @@ + + + #FFFFFF + #333333 + #738182 + #222d32 + #3c8dbc + diff --git a/src/Android/Resources/values/styles.xml b/src/Android/Resources/values/styles.xml new file mode 100644 index 000000000..c3a06ef5d --- /dev/null +++ b/src/Android/Resources/values/styles.xml @@ -0,0 +1,9 @@ + + + + diff --git a/src/App/App.csproj b/src/App/App.csproj index 2ce30f8b0..38ec682a8 100644 --- a/src/App/App.csproj +++ b/src/App/App.csproj @@ -46,6 +46,7 @@ + diff --git a/src/App/Controls/BottomBorderEntry.cs b/src/App/Controls/BottomBorderEntry.cs index 6c947c842..279bf344e 100644 --- a/src/App/Controls/BottomBorderEntry.cs +++ b/src/App/Controls/BottomBorderEntry.cs @@ -7,7 +7,7 @@ namespace Bit.App.Controls public BottomBorderEntry() { HasBorder = HasOnlyBottomBorder = true; - BorderColor = Color.FromHex("d2d6de"); + BottomBorderColor = Color.FromHex("d2d6de"); } } } diff --git a/src/App/Controls/ExtendedEntry.cs b/src/App/Controls/ExtendedEntry.cs index 7e27c1254..600f6bdbe 100644 --- a/src/App/Controls/ExtendedEntry.cs +++ b/src/App/Controls/ExtendedEntry.cs @@ -11,11 +11,8 @@ namespace Bit.App.Controls public static readonly BindableProperty HasOnlyBottomBorderProperty = BindableProperty.Create(nameof(HasOnlyBottomBorder), typeof(bool), typeof(ExtendedEntry), false); - public static readonly BindableProperty BorderColorProperty = - BindableProperty.Create(nameof(BorderColor), typeof(Color), typeof(ExtendedEntry), Color.Default); - - public static readonly BindableProperty PlaceholderTextColorProperty = - BindableProperty.Create(nameof(PlaceholderTextColor), typeof(Color), typeof(ExtendedEntry), Color.Default); + public static readonly BindableProperty BottomBorderColorProperty = + BindableProperty.Create(nameof(BottomBorderColor), typeof(Color), typeof(ExtendedEntry), Color.Default); public static readonly BindableProperty MaxLengthProperty = BindableProperty.Create(nameof(MaxLength), typeof(int), typeof(ExtendedEntry), int.MaxValue); @@ -32,16 +29,10 @@ namespace Bit.App.Controls set { SetValue(HasOnlyBottomBorderProperty, value); } } - public Color BorderColor + public Color BottomBorderColor { - get { return (Color)GetValue(BorderColorProperty); } - set { SetValue(BorderColorProperty, value); } - } - - public Color PlaceholderTextColor - { - get { return (Color)GetValue(PlaceholderTextColorProperty); } - set { SetValue(PlaceholderTextColorProperty, value); } + get { return (Color)GetValue(BottomBorderColorProperty); } + set { SetValue(BottomBorderColorProperty, value); } } public int MaxLength diff --git a/src/App/Controls/ExtendedPicker.cs b/src/App/Controls/ExtendedPicker.cs new file mode 100644 index 000000000..15ca80227 --- /dev/null +++ b/src/App/Controls/ExtendedPicker.cs @@ -0,0 +1,35 @@ +using System; +using Xamarin.Forms; + +namespace Bit.App.Controls +{ + public class ExtendedPicker : Picker + { + public static readonly BindableProperty HasBorderProperty = + BindableProperty.Create(nameof(HasBorder), typeof(bool), typeof(ExtendedEntry), true); + + public static readonly BindableProperty HasOnlyBottomBorderProperty = + BindableProperty.Create(nameof(HasOnlyBottomBorder), typeof(bool), typeof(ExtendedEntry), false); + + public static readonly BindableProperty BottomBorderColorProperty = + BindableProperty.Create(nameof(BottomBorderColor), typeof(Color), typeof(ExtendedEntry), Color.Default); + + public bool HasBorder + { + get { return (bool)GetValue(HasBorderProperty); } + set { SetValue(HasBorderProperty, value); } + } + + public bool HasOnlyBottomBorder + { + get { return (bool)GetValue(HasOnlyBottomBorderProperty); } + set { SetValue(HasOnlyBottomBorderProperty, value); } + } + + public Color BottomBorderColor + { + get { return (Color)GetValue(BottomBorderColorProperty); } + set { SetValue(BottomBorderColorProperty, value); } + } + } +} diff --git a/src/App/Pages/SyncPage.cs b/src/App/Pages/SyncPage.cs index 64fd0dd57..f96a05a71 100644 --- a/src/App/Pages/SyncPage.cs +++ b/src/App/Pages/SyncPage.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Acr.UserDialogs; using Bit.App.Abstractions; +using Bit.App.Controls; using Bit.App.Resources; using Plugin.Connectivity.Abstractions; using Xamarin.Forms; @@ -29,17 +30,25 @@ namespace Bit.App.Pages var syncButton = new Button { Text = "Sync Vault", - Command = new Command(async () => await SyncAsync()) + Command = new Command( async () => await SyncAsync() ) }; var stackLayout = new StackLayout { }; - stackLayout.Children.Add(syncButton); + stackLayout.Children.Add( syncButton ); + stackLayout.Children.Add( new ExtendedEntry + { + BottomBorderColor = Color.Black, + HasBorder = true, + HasOnlyBottomBorder = true, + Placeholder = "Some placeholder", + PlaceholderColor = Color.Red + } ); Title = "Sync"; Content = stackLayout; Icon = "fa-refresh"; - if(!_connectivity.IsConnected) + if( !_connectivity.IsConnected ) { AlertNoConnection(); } @@ -47,28 +56,28 @@ namespace Bit.App.Pages public async Task SyncAsync() { - if(!_connectivity.IsConnected) + if( !_connectivity.IsConnected ) { AlertNoConnection(); return; } - _userDialogs.ShowLoading("Syncing...", MaskType.Black); + _userDialogs.ShowLoading( "Syncing...", MaskType.Black ); var succeeded = await _syncService.SyncAsync(); _userDialogs.HideLoading(); - if(succeeded) + if( succeeded ) { - _userDialogs.SuccessToast("Syncing complete."); + _userDialogs.SuccessToast( "Syncing complete." ); } else { - _userDialogs.ErrorToast("Syncing failed."); + _userDialogs.ErrorToast( "Syncing failed." ); } } public void AlertNoConnection() { - DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok); + DisplayAlert( AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok ); } } } diff --git a/src/App/Pages/VaultAddSitePage.cs b/src/App/Pages/VaultAddSitePage.cs index 63921647d..10c6692dd 100644 --- a/src/App/Pages/VaultAddSitePage.cs +++ b/src/App/Pages/VaultAddSitePage.cs @@ -30,34 +30,39 @@ namespace Bit.App.Pages private void Init() { - var folders = _folderService.GetAllAsync().GetAwaiter().GetResult().OrderBy(f => f.Name?.Decrypt()); + var folders = _folderService.GetAllAsync().GetAwaiter().GetResult().OrderBy( f => f.Name?.Decrypt() ); var uriEntry = new BottomBorderEntry { Keyboard = Keyboard.Url }; var nameEntry = new BottomBorderEntry(); - var folderPicker = new Picker { Title = AppResources.Folder }; - folderPicker.Items.Add(AppResources.FolderNone); - folderPicker.SelectedIndex = 0; - foreach(var folder in folders) + var folderPicker = new ExtendedPicker { - folderPicker.Items.Add(folder.Name.Decrypt()); + Title = AppResources.Folder, + BottomBorderColor = Color.FromHex( "d2d6de" ), + HasOnlyBottomBorder = true + }; + folderPicker.Items.Add( AppResources.FolderNone ); + folderPicker.SelectedIndex = 0; + foreach( var folder in folders ) + { + folderPicker.Items.Add( folder.Name.Decrypt() ); } var usernameEntry = new BottomBorderEntry(); var passwordEntry = new BottomBorderEntry { IsPassword = true }; - var notesEditor = new Editor(); + var notesEditor = new Editor { HeightRequest = 75 }; - var stackLayout = new StackLayout { Padding = new Thickness(15) }; - stackLayout.Children.Add(new EntryLabel { Text = AppResources.URI }); - stackLayout.Children.Add(uriEntry); - stackLayout.Children.Add(new EntryLabel { Text = AppResources.Name }); - stackLayout.Children.Add(nameEntry); - stackLayout.Children.Add(new EntryLabel { Text = AppResources.Folder }); - stackLayout.Children.Add(folderPicker); - stackLayout.Children.Add(new EntryLabel { Text = AppResources.Username }); - stackLayout.Children.Add(usernameEntry); - stackLayout.Children.Add(new EntryLabel { Text = AppResources.Password }); - stackLayout.Children.Add(passwordEntry); - stackLayout.Children.Add(new EntryLabel { Text = AppResources.Notes }); - stackLayout.Children.Add(notesEditor); + var stackLayout = new StackLayout { Padding = new Thickness( 15 ) }; + stackLayout.Children.Add( new EntryLabel { Text = AppResources.URI } ); + stackLayout.Children.Add( uriEntry ); + stackLayout.Children.Add( new EntryLabel { Text = AppResources.Name, Margin = new Thickness( 0, 15, 0, 0 ) } ); + stackLayout.Children.Add( nameEntry ); + stackLayout.Children.Add( new EntryLabel { Text = AppResources.Folder, Margin = new Thickness( 0, 15, 0, 0 ) } ); + stackLayout.Children.Add( folderPicker ); + stackLayout.Children.Add( new EntryLabel { Text = AppResources.Username, Margin = new Thickness( 0, 15, 0, 0 ) } ); + stackLayout.Children.Add( usernameEntry ); + stackLayout.Children.Add( new EntryLabel { Text = AppResources.Password, Margin = new Thickness( 0, 15, 0, 0 ) } ); + stackLayout.Children.Add( passwordEntry ); + stackLayout.Children.Add( new EntryLabel { Text = AppResources.Notes, Margin = new Thickness( 0, 15, 0, 0 ) } ); + stackLayout.Children.Add( notesEditor ); var scrollView = new ScrollView { @@ -65,54 +70,54 @@ namespace Bit.App.Pages Orientation = ScrollOrientation.Vertical }; - var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () => - { - if(!_connectivity.IsConnected) - { - AlertNoConnection(); - return; - } + var saveToolBarItem = new ToolbarItem( AppResources.Save, null, async () => + { + if( !_connectivity.IsConnected ) + { + AlertNoConnection(); + return; + } - if(string.IsNullOrWhiteSpace(uriEntry.Text)) - { - await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.URI), AppResources.Ok); - return; - } + if( string.IsNullOrWhiteSpace( uriEntry.Text ) ) + { + await DisplayAlert( AppResources.AnErrorHasOccurred, string.Format( AppResources.ValidationFieldRequired, AppResources.URI ), AppResources.Ok ); + return; + } - if(string.IsNullOrWhiteSpace(nameEntry.Text)) - { - await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Name), AppResources.Ok); - return; - } + if( string.IsNullOrWhiteSpace( nameEntry.Text ) ) + { + await DisplayAlert( AppResources.AnErrorHasOccurred, string.Format( AppResources.ValidationFieldRequired, AppResources.Name ), AppResources.Ok ); + return; + } - var site = new Site - { - Uri = uriEntry.Text.Encrypt(), - Name = nameEntry.Text.Encrypt(), - Username = usernameEntry.Text?.Encrypt(), - Password = passwordEntry.Text?.Encrypt(), - Notes = notesEditor.Text?.Encrypt(), - }; + var site = new Site + { + Uri = uriEntry.Text.Encrypt(), + Name = nameEntry.Text.Encrypt(), + Username = usernameEntry.Text?.Encrypt(), + Password = passwordEntry.Text?.Encrypt(), + Notes = notesEditor.Text?.Encrypt(), + }; - if(folderPicker.SelectedIndex > 0) - { - site.FolderId = folders.ElementAt(folderPicker.SelectedIndex - 1).Id; - } + if( folderPicker.SelectedIndex > 0 ) + { + site.FolderId = folders.ElementAt( folderPicker.SelectedIndex - 1 ).Id; + } - var saveTask = _siteService.SaveAsync(site); - _userDialogs.ShowLoading("Saving...", MaskType.Black); - await saveTask; + var saveTask = _siteService.SaveAsync( site ); + _userDialogs.ShowLoading( "Saving...", MaskType.Black ); + await saveTask; - _userDialogs.HideLoading(); - await Navigation.PopAsync(); - _userDialogs.SuccessToast(nameEntry.Text, "New site created."); - }, ToolbarItemOrder.Default, 0); + _userDialogs.HideLoading(); + await Navigation.PopAsync(); + _userDialogs.SuccessToast( nameEntry.Text, "New site created." ); + }, ToolbarItemOrder.Default, 0 ); Title = AppResources.AddSite; Content = scrollView; - ToolbarItems.Add(saveToolBarItem); + ToolbarItems.Add( saveToolBarItem ); - if(!_connectivity.IsConnected) + if( !_connectivity.IsConnected ) { AlertNoConnection(); } @@ -120,7 +125,7 @@ namespace Bit.App.Pages private void AlertNoConnection() { - DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok); + DisplayAlert( AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok ); } } } diff --git a/src/iOS/Controls/ExtendedEntryRenderer.cs b/src/iOS/Controls/ExtendedEntryRenderer.cs index 480a950ed..b4511a96f 100644 --- a/src/iOS/Controls/ExtendedEntryRenderer.cs +++ b/src/iOS/Controls/ExtendedEntryRenderer.cs @@ -22,7 +22,6 @@ namespace Bit.iOS.Controls if(view != null) { SetBorder(view); - SetPlaceholderTextColor(view); SetMaxLength(view); } } @@ -35,32 +34,28 @@ namespace Bit.iOS.Controls if(e.PropertyName == ExtendedEntry.HasBorderProperty.PropertyName || e.PropertyName == ExtendedEntry.HasOnlyBottomBorderProperty.PropertyName - || e.PropertyName == ExtendedEntry.BorderColorProperty.PropertyName) + || e.PropertyName == ExtendedEntry.BottomBorderColorProperty.PropertyName) { SetBorder(view); } - if(e.PropertyName == ExtendedEntry.PlaceholderTextColorProperty.PropertyName) - { - SetPlaceholderTextColor(view); - } } private void SetBorder(ExtendedEntry view) { - if(view.HasBorder && view.HasOnlyBottomBorder) + if(view.HasOnlyBottomBorder) { var borderLayer = new CALayer(); borderLayer.MasksToBounds = true; - borderLayer.Frame = new CGRect(0f, Frame.Height / 2, Frame.Width, 1f); - borderLayer.BorderColor = view.BorderColor.ToCGColor(); - borderLayer.BorderWidth = 1.0f; + borderLayer.Frame = new CGRect(0f, Frame.Height / 2, Frame.Width * 2, 1f); + borderLayer.BorderColor = view.BottomBorderColor.ToCGColor(); + borderLayer.BorderWidth = 1f; Control.Layer.AddSublayer(borderLayer); Control.BorderStyle = UITextBorderStyle.None; } else if(view.HasBorder) { - Control.BorderStyle = UITextBorderStyle.Line; + Control.BorderStyle = UITextBorderStyle.RoundedRect; } else { @@ -76,20 +71,5 @@ namespace Bit.iOS.Controls return newLength <= view.MaxLength; }; } - - private void SetPlaceholderTextColor(ExtendedEntry view) - { - if(string.IsNullOrEmpty(view.Placeholder) == false && view.PlaceholderTextColor != Color.Default) - { - var placeholderString = new NSAttributedString( - view.Placeholder, - new UIStringAttributes() - { - ForegroundColor = view.PlaceholderTextColor.ToUIColor() - }); - - Control.AttributedPlaceholder = placeholderString; - } - } } } diff --git a/src/iOS/Controls/ExtendedPickerRenderer.cs b/src/iOS/Controls/ExtendedPickerRenderer.cs new file mode 100644 index 000000000..8879c4674 --- /dev/null +++ b/src/iOS/Controls/ExtendedPickerRenderer.cs @@ -0,0 +1,64 @@ +using System; +using System.ComponentModel; +using Bit.App.Controls; +using Bit.iOS.Controls; +using CoreAnimation; +using CoreGraphics; +using UIKit; +using Xamarin.Forms; +using Xamarin.Forms.Platform.iOS; + +[assembly: ExportRenderer(typeof(ExtendedPicker), typeof( ExtendedPickerRenderer ) )] +namespace Bit.iOS.Controls +{ + public class ExtendedPickerRenderer : PickerRenderer + { + protected override void OnElementChanged(ElementChangedEventArgs e) + { + base.OnElementChanged(e); + + var view = e.NewElement as ExtendedPicker; + if(view != null) + { + SetBorder(view); + } + } + + protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) + { + base.OnElementPropertyChanged(sender, e); + + var view = (ExtendedPicker)Element; + + if(e.PropertyName == ExtendedPicker.HasBorderProperty.PropertyName + || e.PropertyName == ExtendedPicker.HasOnlyBottomBorderProperty.PropertyName + || e.PropertyName == ExtendedPicker.BottomBorderColorProperty.PropertyName) + { + SetBorder(view); + } + } + + private void SetBorder( ExtendedPicker view ) + { + if(view.HasOnlyBottomBorder) + { + var borderLayer = new CALayer(); + borderLayer.MasksToBounds = true; + borderLayer.Frame = new CGRect( 0f, Frame.Height / 2, Frame.Width * 2, 1f ); + borderLayer.BorderColor = view.BottomBorderColor.ToCGColor(); + borderLayer.BorderWidth = 1f; + + Control.Layer.AddSublayer( borderLayer ); + Control.BorderStyle = UITextBorderStyle.None; + } + else if(view.HasBorder) + { + Control.BorderStyle = UITextBorderStyle.RoundedRect; + } + else + { + Control.BorderStyle = UITextBorderStyle.None; + } + } + } +} diff --git a/src/iOS/iOS.csproj b/src/iOS/iOS.csproj index 4065adba6..7ccb8493f 100644 --- a/src/iOS/iOS.csproj +++ b/src/iOS/iOS.csproj @@ -101,6 +101,7 @@ Entitlements.plist +