1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-29 14:43:50 +00:00

Extended controls

This commit is contained in:
Kyle Spearrin
2016-05-09 23:25:37 -04:00
parent b4144a393a
commit 3f251d0d12
14 changed files with 336 additions and 16 deletions

View File

@@ -0,0 +1,95 @@
using System;
using System.ComponentModel;
using Bit.App.Controls;
using Bit.iOS.Controls;
using CoreAnimation;
using CoreGraphics;
using Foundation;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(ExtendedEntry), typeof(ExtendedEntryRenderer))]
namespace Bit.iOS.Controls
{
public class ExtendedEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
var view = e.NewElement as ExtendedEntry;
if(view != null)
{
SetBorder(view);
SetPlaceholderTextColor(view);
SetMaxLength(view);
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
var view = (ExtendedEntry)Element;
if(e.PropertyName == ExtendedEntry.HasBorderProperty.PropertyName
|| e.PropertyName == ExtendedEntry.HasOnlyBottomBorderProperty.PropertyName
|| e.PropertyName == ExtendedEntry.BorderColorProperty.PropertyName)
{
SetBorder(view);
}
if(e.PropertyName == ExtendedEntry.PlaceholderTextColorProperty.PropertyName)
{
SetPlaceholderTextColor(view);
}
}
private void SetBorder(ExtendedEntry view)
{
if(view.HasBorder && 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;
Control.Layer.AddSublayer(borderLayer);
Control.BorderStyle = UITextBorderStyle.None;
}
else if(view.HasBorder)
{
Control.BorderStyle = UITextBorderStyle.Line;
}
else
{
Control.BorderStyle = UITextBorderStyle.None;
}
}
private void SetMaxLength(ExtendedEntry view)
{
Control.ShouldChangeCharacters = (textField, range, replacementString) =>
{
var newLength = textField.Text.Length + replacementString.Length - range.Length;
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;
}
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using Bit.App.Controls;
using Bit.iOS.Controls;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(ExtendedTabbedPage), typeof(ExtendedTabbedPageRenderer))]
namespace Bit.iOS.Controls
{
public class ExtendedTabbedPageRenderer: TabbedRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
var page = (ExtendedTabbedPage)Element;
TabBar.TintColor = page.TintColor.ToUIColor();
TabBar.BarTintColor = page.BarTintColor.ToUIColor();
TabBar.BackgroundColor = page.BackgroundColor.ToUIColor();
}
}
}

View File

@@ -22,7 +22,7 @@
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>MinimumOSVersion</key>
<string>8.0</string>
<string>9.3</string>
<key>CFBundleDisplayName</key>
<string>bitwarden</string>
<key>CFBundleIdentifier</key>

View File

@@ -23,9 +23,19 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchArch>i386, x86_64</MtouchArch>
<MtouchArch>x86_64</MtouchArch>
<MtouchLink>None</MtouchLink>
<MtouchDebug>true</MtouchDebug>
<MtouchDebug>True</MtouchDebug>
<MtouchSdkVersion>9.3</MtouchSdkVersion>
<MtouchProfiling>False</MtouchProfiling>
<MtouchFastDev>False</MtouchFastDev>
<MtouchUseLlvm>False</MtouchUseLlvm>
<MtouchUseThumb>False</MtouchUseThumb>
<MtouchUseSGen>False</MtouchUseSGen>
<MtouchUseRefCounting>False</MtouchUseRefCounting>
<OptimizePNGs>True</OptimizePNGs>
<MtouchFloat32>False</MtouchFloat32>
<MtouchI18n />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>none</DebugType>
@@ -91,6 +101,8 @@
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
</PropertyGroup>
<ItemGroup>
<Compile Include="Controls\ExtendedEntryRenderer.cs" />
<Compile Include="Controls\ExtendedTabbedPageRenderer.cs" />
<Compile Include="Services\ClipboardService.cs" />
<Compile Include="Services\KeyChainStorageService.cs" />
<Compile Include="Main.cs" />