mirror of
https://github.com/bitwarden/android.git
synced 2024-12-18 23:31:52 +03:00
Extended table view more for iOS
This commit is contained in:
parent
2ece75b2c0
commit
8ec957c39c
4 changed files with 81 additions and 19 deletions
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue