mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 15:15:34 +03:00
* Fixed long secure notes edition scrolling when focused issue (#1257) * Improved fix long secure notes edition scrolling when focused issue to not use a new editor custom renderer but an effect (#1257) * Fixed long editor, on text and notes on send when scrolling when focused issue (#1257)
This commit is contained in:
parent
a07ef1a1d6
commit
b8c1107c94
7 changed files with 131 additions and 4 deletions
|
@ -124,6 +124,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\" />
|
||||
<Folder Include="Behaviors\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -411,4 +412,7 @@
|
|||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Behaviors\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
using Xamarin.Essentials;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Bit.App.Behaviors
|
||||
{
|
||||
/// <summary>
|
||||
/// This behavior prevents the Editor to be automatically scrolled to the bottom on focus.
|
||||
/// This is needed due to this Xamarin Forms issue: https://github.com/xamarin/Xamarin.Forms/issues/2233
|
||||
/// </summary>
|
||||
public class EditorPreventAutoBottomScrollingOnFocusedBehavior : Behavior<Editor>
|
||||
{
|
||||
public static readonly BindableProperty ParentScrollViewProperty
|
||||
= BindableProperty.Create(nameof(ParentScrollView), typeof(ScrollView), typeof(EditorPreventAutoBottomScrollingOnFocusedBehavior));
|
||||
|
||||
public ScrollView ParentScrollView
|
||||
{
|
||||
get => (ScrollView)GetValue(ParentScrollViewProperty);
|
||||
set => SetValue(ParentScrollViewProperty, value);
|
||||
}
|
||||
|
||||
protected override void OnAttachedTo(Editor bindable)
|
||||
{
|
||||
base.OnAttachedTo(bindable);
|
||||
|
||||
bindable.Focused += OnFocused;
|
||||
}
|
||||
|
||||
private void OnFocused(object sender, FocusEventArgs e)
|
||||
{
|
||||
if (DeviceInfo.Platform.Equals(DevicePlatform.iOS) && ParentScrollView != null)
|
||||
{
|
||||
ParentScrollView.ScrollToAsync(ParentScrollView.ScrollX, ParentScrollView.ScrollY, true);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDetachingFrom(Editor bindable)
|
||||
{
|
||||
bindable.Focused -= OnFocused;
|
||||
|
||||
base.OnDetachingFrom(bindable);
|
||||
}
|
||||
}
|
||||
}
|
25
src/App/Effects/ScrollEnabledEffect.cs
Normal file
25
src/App/Effects/ScrollEnabledEffect.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using Xamarin.Forms;
|
||||
|
||||
namespace Bit.App.Effects
|
||||
{
|
||||
public class ScrollEnabledEffect : RoutingEffect
|
||||
{
|
||||
public static readonly BindableProperty IsScrollEnabledProperty =
|
||||
BindableProperty.CreateAttached("IsScrollEnabled", typeof(bool), typeof(ScrollEnabledEffect), true);
|
||||
|
||||
public static bool GetIsScrollEnabled(BindableObject view)
|
||||
{
|
||||
return (bool)view.GetValue(IsScrollEnabledProperty);
|
||||
}
|
||||
|
||||
public static void SetIsScrollEnabled(BindableObject view, bool value)
|
||||
{
|
||||
view.SetValue(IsScrollEnabledProperty, value);
|
||||
}
|
||||
|
||||
public ScrollEnabledEffect()
|
||||
: base("Bitwarden.ScrollEnabledEffect")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,8 @@
|
|||
xmlns:pages="clr-namespace:Bit.App.Pages"
|
||||
xmlns:u="clr-namespace:Bit.App.Utilities"
|
||||
xmlns:controls="clr-namespace:Bit.App.Controls"
|
||||
xmlns:behaviors="clr-namespace:Bit.App.Behaviors"
|
||||
xmlns:effects="clr-namespace:Bit.App.Effects"
|
||||
x:DataType="pages:SendAddEditPageViewModel"
|
||||
x:Name="_page"
|
||||
Title="{Binding PageTitle}">
|
||||
|
@ -201,7 +203,15 @@
|
|||
Text="{Binding Send.Text.Text}"
|
||||
IsEnabled="{Binding SendEnabled}"
|
||||
StyleClass="box-value"
|
||||
Margin="{Binding EditorMargins}" />
|
||||
Margin="{Binding EditorMargins}"
|
||||
effects:ScrollEnabledEffect.IsScrollEnabled="false" >
|
||||
<Editor.Behaviors>
|
||||
<behaviors:EditorPreventAutoBottomScrollingOnFocusedBehavior ParentScrollView="{x:Reference _scrollView}" />
|
||||
</Editor.Behaviors>
|
||||
<Editor.Effects>
|
||||
<effects:ScrollEnabledEffect />
|
||||
</Editor.Effects>
|
||||
</Editor>
|
||||
<BoxView
|
||||
StyleClass="box-row-separator"
|
||||
IsVisible="{Binding ShowEditorSeparators}" />
|
||||
|
@ -443,7 +453,15 @@
|
|||
Text="{Binding Send.Notes}"
|
||||
IsEnabled="{Binding SendEnabled}"
|
||||
StyleClass="box-value"
|
||||
Margin="{Binding EditorMargins}" />
|
||||
Margin="{Binding EditorMargins}"
|
||||
effects:ScrollEnabledEffect.IsScrollEnabled="false" >
|
||||
<Editor.Behaviors>
|
||||
<behaviors:EditorPreventAutoBottomScrollingOnFocusedBehavior ParentScrollView="{x:Reference _scrollView}" />
|
||||
</Editor.Behaviors>
|
||||
<Editor.Effects>
|
||||
<effects:ScrollEnabledEffect />
|
||||
</Editor.Effects>
|
||||
</Editor>
|
||||
<BoxView
|
||||
StyleClass="box-row-separator"
|
||||
IsVisible="{Binding ShowEditorSeparators}" />
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
xmlns:u="clr-namespace:Bit.App.Utilities"
|
||||
xmlns:controls="clr-namespace:Bit.App.Controls"
|
||||
xmlns:views="clr-namespace:Bit.Core.Models.View;assembly=BitwardenCore"
|
||||
xmlns:behaviors="clr-namespace:Bit.App.Behaviors"
|
||||
xmlns:effects="clr-namespace:Bit.App.Effects"
|
||||
x:DataType="pages:AddEditPageViewModel"
|
||||
x:Name="_page"
|
||||
Title="{Binding PageTitle}">
|
||||
|
@ -584,8 +586,16 @@
|
|||
<Editor
|
||||
x:Name="_notesEditor"
|
||||
AutoSize="TextChanges"
|
||||
Text="{Binding Cipher.Notes}"
|
||||
StyleClass="box-value" />
|
||||
StyleClass="box-value"
|
||||
effects:ScrollEnabledEffect.IsScrollEnabled="false"
|
||||
Text="{Binding Cipher.Notes}">
|
||||
<Editor.Behaviors>
|
||||
<behaviors:EditorPreventAutoBottomScrollingOnFocusedBehavior ParentScrollView="{x:Reference _scrollView}" />
|
||||
</Editor.Behaviors>
|
||||
<Editor.Effects>
|
||||
<effects:ScrollEnabledEffect />
|
||||
</Editor.Effects>
|
||||
</Editor>
|
||||
</StackLayout>
|
||||
<BoxView StyleClass="box-row-separator" IsVisible="{Binding ShowNotesSeparator}" />
|
||||
</StackLayout>
|
||||
|
|
25
src/iOS.Core/Effects/ScrollEnabledEffect.cs
Normal file
25
src/iOS.Core/Effects/ScrollEnabledEffect.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using Bit.iOS.Core.Effects;
|
||||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.iOS;
|
||||
|
||||
[assembly: ResolutionGroupName("Bitwarden")]
|
||||
[assembly: ExportEffect(typeof(ScrollEnabledEffect), "ScrollEnabledEffect")]
|
||||
namespace Bit.iOS.Core.Effects
|
||||
{
|
||||
public class ScrollEnabledEffect : PlatformEffect
|
||||
{
|
||||
protected override void OnAttached()
|
||||
{
|
||||
// this can be for any view that inherits from UIScrollView like UITextView.
|
||||
if (Element != null && Control is UIScrollView scrollView)
|
||||
{
|
||||
scrollView.ScrollEnabled = App.Effects.ScrollEnabledEffect.GetIsScrollEnabled(Element);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDetached()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -137,6 +137,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\" />
|
||||
<Folder Include="Effects\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Constants.cs" />
|
||||
|
@ -189,6 +190,7 @@
|
|||
<Compile Include="Views\SwitchTableViewCell.cs" />
|
||||
<Compile Include="Views\Toast.cs" />
|
||||
<Compile Include="Renderers\SelectableLabelRenderer.cs" />
|
||||
<Compile Include="Effects\ScrollEnabledEffect.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\App\App.csproj">
|
||||
|
|
Loading…
Reference in a new issue