From 8ec957c39cf52de6987f61aaf55a41ace046b088 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 12 May 2016 21:30:02 -0400 Subject: [PATCH] Extended table view more for iOS --- src/App/Controls/ExtendedTableView.cs | 19 +++++++ src/App/Pages/SettingsPage.cs | 4 +- src/App/Pages/VaultAddSitePage.cs | 25 +++------ src/iOS/Controls/ExtendedTableViewRenderer.cs | 52 +++++++++++++++++++ 4 files changed, 81 insertions(+), 19 deletions(-) diff --git a/src/App/Controls/ExtendedTableView.cs b/src/App/Controls/ExtendedTableView.cs index 4f782a309..e3fc629c8 100644 --- a/src/App/Controls/ExtendedTableView.cs +++ b/src/App/Controls/ExtendedTableView.cs @@ -5,5 +5,24 @@ namespace Bit.App.Controls { public class ExtendedTableView : TableView { + public static readonly BindableProperty EnableScrollingProperty = + BindableProperty.Create(nameof(EnableScrolling), typeof(bool), typeof(ExtendedTableView), true); + + public static readonly BindableProperty EnableSelectionProperty = + BindableProperty.Create(nameof(EnableSelection), typeof(bool), typeof(ExtendedTableView), true); + + public bool EnableScrolling + { + get { return (bool)GetValue(EnableScrollingProperty); } + set { SetValue(EnableScrollingProperty, value); } + } + + public bool EnableSelection + { + get { return (bool)GetValue(EnableSelectionProperty); } + set { SetValue(EnableSelectionProperty, value); } + } + + public int EstimatedRowHeight { get; set; } } } diff --git a/src/App/Pages/SettingsPage.cs b/src/App/Pages/SettingsPage.cs index 9daacdc81..933f68534 100644 --- a/src/App/Pages/SettingsPage.cs +++ b/src/App/Pages/SettingsPage.cs @@ -3,6 +3,7 @@ using Bit.App.Abstractions; using Bit.App.Resources; using Xamarin.Forms; using XLabs.Ioc; +using Bit.App.Controls; namespace Bit.App.Pages { @@ -22,8 +23,9 @@ namespace Bit.App.Pages var foldersCell = new TextCell { Text = "Folders" }; foldersCell.Tapped += FoldersCell_Tapped; - var table = new TableView + var table = new ExtendedTableView { + EnableScrolling = false, Intent = TableIntent.Menu, Root = new TableRoot { diff --git a/src/App/Pages/VaultAddSitePage.cs b/src/App/Pages/VaultAddSitePage.cs index 9edbd9132..0464ecd0c 100644 --- a/src/App/Pages/VaultAddSitePage.cs +++ b/src/App/Pages/VaultAddSitePage.cs @@ -43,7 +43,7 @@ namespace Bit.App.Pages } var usernameEntry = new ExtendedEntry { HasBorder = false }; var passwordEntry = new ExtendedEntry { IsPassword = true, HasBorder = false }; - var notesEditor = new ExtendedEditor { HeightRequest = Device.OS == TargetPlatform.iOS ? 70 : 90, HasBorder = false }; + var notesEditor = new ExtendedEditor { HeightRequest = 90, HasBorder = false }; var uriStackLayout = new FormEntryStackLayout(); uriStackLayout.Children.Add(new EntryLabel { Text = AppResources.URI }); @@ -83,7 +83,9 @@ namespace Bit.App.Pages var mainTable = new ExtendedTableView { Intent = TableIntent.Settings, + EnableScrolling = false, HasUnevenRows = true, + EnableSelection = false, Root = new TableRoot { new TableSection @@ -93,16 +95,7 @@ namespace Bit.App.Pages folderCell, usernameCell, passwordCell - } - } - }; - - var notesTable = new ExtendedTableView - { - Intent = TableIntent.Settings, - HasUnevenRows = true, - Root = new TableRoot - { + }, new TableSection(AppResources.Notes) { notesCell @@ -112,17 +105,13 @@ namespace Bit.App.Pages if(Device.OS == TargetPlatform.iOS) { - mainTable.RowHeight = 70; - notesTable.RowHeight = 90; + mainTable.RowHeight = -1; + mainTable.EstimatedRowHeight = 70; } - var tablesStackLayout = new StackLayout(); - tablesStackLayout.Children.Add(mainTable); - tablesStackLayout.Children.Add(notesTable); - var scrollView = new ScrollView { - Content = tablesStackLayout, + Content = mainTable, Orientation = ScrollOrientation.Vertical }; diff --git a/src/iOS/Controls/ExtendedTableViewRenderer.cs b/src/iOS/Controls/ExtendedTableViewRenderer.cs index 3091f1cbb..1bb045d75 100644 --- a/src/iOS/Controls/ExtendedTableViewRenderer.cs +++ b/src/iOS/Controls/ExtendedTableViewRenderer.cs @@ -19,6 +19,10 @@ namespace Bit.iOS.Controls if(view != null) { CorrectMargins(view); + SetScrolling(view); + SetSelection(view); + UpdateRowHeight(view); + UpdateEstimatedRowHeight(view); } } @@ -29,11 +33,59 @@ namespace Bit.iOS.Controls var view = (ExtendedTableView)Element; CorrectMargins(view); + + if(e.PropertyName == ExtendedTableView.EnableScrollingProperty.PropertyName) + { + SetScrolling(view); + } + else if(e.PropertyName == ExtendedTableView.RowHeightProperty.PropertyName) + { + UpdateRowHeight(view); + } + else if(e.PropertyName == ExtendedTableView.EnableSelectionProperty.PropertyName) + { + SetSelection(view); + } } private void CorrectMargins(ExtendedTableView view) { Control.ContentInset = new UIEdgeInsets(-10, 0, -100, 0); } + + private void SetScrolling(ExtendedTableView view) + { + Control.ScrollEnabled = view.EnableScrolling; + } + + private void SetSelection(ExtendedTableView view) + { + Control.AllowsSelection = view.EnableSelection; + } + + private void UpdateRowHeight(ExtendedTableView view) + { + var rowHeight = view.RowHeight; + if(view.HasUnevenRows && rowHeight == -1) + { + Control.RowHeight = UITableView.AutomaticDimension; + } + else + { + Control.RowHeight = rowHeight <= 0 ? 44 : rowHeight; + } + } + + private void UpdateEstimatedRowHeight(ExtendedTableView view) + { + if(view.HasUnevenRows && view.RowHeight == -1) + { + Control.EstimatedRowHeight = view.EstimatedRowHeight; + } + else + { + Control.EstimatedRowHeight = 0; + } + } } }