mirror of
https://github.com/bitwarden/android.git
synced 2025-01-11 18:57:39 +03: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:
parent
4aad34cd75
commit
d3734c63fc
8 changed files with 106 additions and 42 deletions
|
@ -111,7 +111,6 @@
|
||||||
<Compile Include="Autofill\SavedItem.cs" />
|
<Compile Include="Autofill\SavedItem.cs" />
|
||||||
<Compile Include="Effects\FabShadowEffect.cs" />
|
<Compile Include="Effects\FabShadowEffect.cs" />
|
||||||
<Compile Include="Effects\FixedSizeEffect.cs" />
|
<Compile Include="Effects\FixedSizeEffect.cs" />
|
||||||
<Compile Include="Effects\SelectableLabelEffect.cs" />
|
|
||||||
<Compile Include="Effects\TabBarEffect.cs" />
|
<Compile Include="Effects\TabBarEffect.cs" />
|
||||||
<Compile Include="Push\FirebaseMessagingService.cs" />
|
<Compile Include="Push\FirebaseMessagingService.cs" />
|
||||||
<Compile Include="Receivers\ClearClipboardAlarmReceiver.cs" />
|
<Compile Include="Receivers\ClearClipboardAlarmReceiver.cs" />
|
||||||
|
@ -148,6 +147,7 @@
|
||||||
<Compile Include="Utilities\AppCenterHelper.cs" />
|
<Compile Include="Utilities\AppCenterHelper.cs" />
|
||||||
<Compile Include="Utilities\ThemeHelpers.cs" />
|
<Compile Include="Utilities\ThemeHelpers.cs" />
|
||||||
<Compile Include="WebAuthCallbackActivity.cs" />
|
<Compile Include="WebAuthCallbackActivity.cs" />
|
||||||
|
<Compile Include="Renderers\SelectableLabelRenderer.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<AndroidAsset Include="Assets\FontAwesome.ttf" />
|
<AndroidAsset Include="Assets\FontAwesome.ttf" />
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
using Android.Widget;
|
|
||||||
using Bit.Droid.Effects;
|
|
||||||
using Xamarin.Forms;
|
|
||||||
using Xamarin.Forms.Platform.Android;
|
|
||||||
|
|
||||||
[assembly: ExportEffect(typeof(SelectableLabelEffect), "SelectableLabelEffect")]
|
|
||||||
namespace Bit.Droid.Effects
|
|
||||||
{
|
|
||||||
public class SelectableLabelEffect : PlatformEffect
|
|
||||||
{
|
|
||||||
protected override void OnAttached()
|
|
||||||
{
|
|
||||||
if (Control is TextView textView)
|
|
||||||
{
|
|
||||||
textView.SetTextIsSelectable(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnDetached()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
25
src/Android/Renderers/SelectableLabelRenderer.cs
Normal file
25
src/Android/Renderers/SelectableLabelRenderer.cs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
using System;
|
||||||
|
using Android.Content;
|
||||||
|
using Bit.App.Controls;
|
||||||
|
using Bit.Droid.Renderers;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using Xamarin.Forms.Platform.Android;
|
||||||
|
|
||||||
|
[assembly: ExportRenderer(typeof(SelectableLabel), typeof(SelectableLabelRenderer))]
|
||||||
|
namespace Bit.Droid.Renderers
|
||||||
|
{
|
||||||
|
public class SelectableLabelRenderer : LabelRenderer
|
||||||
|
{
|
||||||
|
public SelectableLabelRenderer(Context context) : base(context) { }
|
||||||
|
|
||||||
|
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
|
||||||
|
{
|
||||||
|
base.OnElementChanged(e);
|
||||||
|
|
||||||
|
if (Control != null)
|
||||||
|
{
|
||||||
|
Control.SetTextIsSelectable(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
src/App/Controls/SelectableLabel.cs
Normal file
10
src/App/Controls/SelectableLabel.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
using System;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace Bit.App.Controls
|
||||||
|
{
|
||||||
|
public class SelectableLabel : Label
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +0,0 @@
|
||||||
using Xamarin.Forms;
|
|
||||||
|
|
||||||
namespace Bit.App.Effects
|
|
||||||
{
|
|
||||||
public class SelectableLabelEffect : RoutingEffect
|
|
||||||
{
|
|
||||||
public SelectableLabelEffect()
|
|
||||||
: base("Bitwarden.SelectableLabelEffect")
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -526,14 +526,9 @@
|
||||||
StyleClass="box-header, box-header-platform" />
|
StyleClass="box-header, box-header-platform" />
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
<StackLayout StyleClass="box-row">
|
<StackLayout StyleClass="box-row">
|
||||||
<Label
|
<controls:SelectableLabel
|
||||||
Text="{Binding Cipher.Notes, Mode=OneWay}"
|
Text="{Binding Cipher.Notes, Mode=OneWay}"
|
||||||
StyleClass="box-value"
|
StyleClass="box-value"/>
|
||||||
LineBreakMode="WordWrap">
|
|
||||||
<Label.Effects>
|
|
||||||
<effects:SelectableLabelEffect />
|
|
||||||
</Label.Effects>
|
|
||||||
</Label>
|
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
<BoxView StyleClass="box-row-separator" />
|
<BoxView StyleClass="box-row-separator" />
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
|
|
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\StepperTableViewCell.cs" />
|
||||||
<Compile Include="Views\SwitchTableViewCell.cs" />
|
<Compile Include="Views\SwitchTableViewCell.cs" />
|
||||||
<Compile Include="Views\Toast.cs" />
|
<Compile Include="Views\Toast.cs" />
|
||||||
|
<Compile Include="Renderers\SelectableLabelRenderer.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\App\App.csproj">
|
<ProjectReference Include="..\App\App.csproj">
|
||||||
|
|
Loading…
Reference in a new issue