From 05e8da4bcce9f88bfa672f7b2fb5d124e1a09571 Mon Sep 17 00:00:00 2001 From: Matt Portune <59324545+mportune-bw@users.noreply.github.com> Date: Wed, 30 Jun 2021 17:46:59 -0400 Subject: [PATCH] Workaround for off-screen draw bug in XF4.5+ (#1447) * workaround for off-screen draw bug in xf4.5+ * check cols even if orgId is present --- src/App/Pages/Vault/AddEditPage.xaml | 5 ++++- src/App/Pages/Vault/AddEditPage.xaml.cs | 2 ++ src/App/Pages/Vault/AddEditPageViewModel.cs | 25 +++++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/App/Pages/Vault/AddEditPage.xaml b/src/App/Pages/Vault/AddEditPage.xaml index cfc246f08..0c6858a65 100644 --- a/src/App/Pages/Vault/AddEditPage.xaml +++ b/src/App/Pages/Vault/AddEditPage.xaml @@ -710,7 +710,10 @@ - + diff --git a/src/App/Pages/Vault/AddEditPage.xaml.cs b/src/App/Pages/Vault/AddEditPage.xaml.cs index f8c7b53ac..e475a875a 100644 --- a/src/App/Pages/Vault/AddEditPage.xaml.cs +++ b/src/App/Pages/Vault/AddEditPage.xaml.cs @@ -47,6 +47,7 @@ namespace Bit.App.Pages _vm.CipherId = cipherId; _vm.FolderId = folderId == "none" ? null : folderId; _vm.CollectionIds = collectionId != null ? new HashSet(new List { collectionId }) : null; + _vm.CollectionsRepeaterView = _collectionsRepeaterView; _vm.Type = type; _vm.DefaultName = name ?? appOptions?.SaveName; _vm.DefaultUri = uri ?? appOptions?.Uri; @@ -158,6 +159,7 @@ namespace Bit.App.Pages { RequestFocus(_nameEntry); } + _scrollView.Scrolled += (sender, args) => _vm.HandleScroll(); }); } diff --git a/src/App/Pages/Vault/AddEditPageViewModel.cs b/src/App/Pages/Vault/AddEditPageViewModel.cs index 5cd66b3b5..86df1dd28 100644 --- a/src/App/Pages/Vault/AddEditPageViewModel.cs +++ b/src/App/Pages/Vault/AddEditPageViewModel.cs @@ -1,4 +1,5 @@ -using Bit.App.Abstractions; +using System; +using Bit.App.Abstractions; using Bit.App.Models; using Bit.App.Resources; using Bit.Core.Abstractions; @@ -9,6 +10,7 @@ using Bit.Core.Utilities; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Bit.App.Controls; using Xamarin.Forms; using View = Xamarin.Forms.View; @@ -39,6 +41,7 @@ namespace Bit.App.Pages private int _ownershipSelectedIndex; private bool _hasCollections; private string _previousCipherId; + private DateTime _lastHandledScrollTime; private List _writeableCollections; private string[] _additionalCipherProperties = new string[] { @@ -166,6 +169,7 @@ namespace Bit.App.Pages public ExtendedObservableCollection Uris { get; set; } public ExtendedObservableCollection Fields { get; set; } public ExtendedObservableCollection Collections { get; set; } + public RepeaterView CollectionsRepeaterView { get; set; } public int TypeSelectedIndex { get => _typeSelectedIndex; @@ -800,13 +804,30 @@ namespace Bit.App.Pages { var cols = _writeableCollections.Where(c => c.OrganizationId == Cipher.OrganizationId) .Select(c => new CollectionViewModel { Collection = c }).ToList(); + HasCollections = cols.Any(); Collections.ResetWithRange(cols); + Collections = new ExtendedObservableCollection(cols); } else { + HasCollections = false; Collections.ResetWithRange(new List()); + Collections = new ExtendedObservableCollection(new List()); } - HasCollections = Collections.Any(); + } + + public void HandleScroll() + { + // workaround for https://github.com/xamarin/Xamarin.Forms/issues/13607 + // required for org ownership/collections to render properly in XF4.5+ + if (!HasCollections || + EditMode || + (DateTime.Now - _lastHandledScrollTime < TimeSpan.FromMilliseconds(200))) + { + return; + } + CollectionsRepeaterView.ItemsSource = Collections; + _lastHandledScrollTime = DateTime.Now; } private void TriggerCipherChanged()