mirror of
https://github.com/bitwarden/mobile
synced 2026-01-03 09:03:35 +00:00
Add SelectableLabel Custom Renderer to allow copy of note text (#1564)
* Add SelectableLabel Custom Renderer to allow copy of note text - Remove SelectableLabelEffect * Remove editor changes from text custom field
This commit is contained in:
67
src/iOS.Core/Renderers/SelectableLabelRenderer.cs
Normal file
67
src/iOS.Core/Renderers/SelectableLabelRenderer.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using Bit.App.Controls;
|
||||
using Bit.iOS.Core.Renderers;
|
||||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.iOS;
|
||||
|
||||
[assembly: ExportRenderer(typeof(SelectableLabel), typeof(SelectableLabelRenderer))]
|
||||
namespace Bit.iOS.Core.Renderers
|
||||
{
|
||||
public class SelectableLabelRenderer : ViewRenderer<Label, UITextView>
|
||||
{
|
||||
UITextView uiTextView;
|
||||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
|
||||
{
|
||||
base.OnElementChanged(e);
|
||||
|
||||
if (Control == null)
|
||||
{
|
||||
uiTextView = new UITextView();
|
||||
}
|
||||
|
||||
uiTextView.Selectable = true;
|
||||
uiTextView.Editable = false;
|
||||
uiTextView.ScrollEnabled = false;
|
||||
uiTextView.TextContainerInset = UIEdgeInsets.Zero;
|
||||
uiTextView.TextContainer.LineFragmentPadding = 0;
|
||||
uiTextView.BackgroundColor = UIColor.Clear;
|
||||
|
||||
uiTextView.Text = Element.Text;
|
||||
uiTextView.TextColor = Element.TextColor.ToUIColor();
|
||||
switch (Element.FontAttributes)
|
||||
{
|
||||
case FontAttributes.None:
|
||||
uiTextView.Font = UIFont.SystemFontOfSize(new nfloat(Element.FontSize));
|
||||
break;
|
||||
case FontAttributes.Bold:
|
||||
uiTextView.Font = UIFont.BoldSystemFontOfSize(new nfloat(Element.FontSize));
|
||||
break;
|
||||
case FontAttributes.Italic:
|
||||
uiTextView.Font = UIFont.ItalicSystemFontOfSize(new nfloat(Element.FontSize));
|
||||
break;
|
||||
default:
|
||||
uiTextView.Font = UIFont.BoldSystemFontOfSize(new nfloat(Element.FontSize));
|
||||
break;
|
||||
}
|
||||
|
||||
SetNativeControl(uiTextView);
|
||||
}
|
||||
|
||||
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnElementPropertyChanged(sender, e);
|
||||
|
||||
if (e.PropertyName == Label.TextProperty.PropertyName)
|
||||
{
|
||||
if (Control != null && Element != null && !string.IsNullOrWhiteSpace(Element.Text))
|
||||
{
|
||||
uiTextView.Text = Element.Text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -188,6 +188,7 @@
|
||||
<Compile Include="Views\StepperTableViewCell.cs" />
|
||||
<Compile Include="Views\SwitchTableViewCell.cs" />
|
||||
<Compile Include="Views\Toast.cs" />
|
||||
<Compile Include="Renderers\SelectableLabelRenderer.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\App\App.csproj">
|
||||
|
||||
Reference in New Issue
Block a user