mirror of
https://github.com/bitwarden/android.git
synced 2024-12-20 08:12:26 +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 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 Bit.App.Resources;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
using XLabs.Ioc;
|
using XLabs.Ioc;
|
||||||
|
using Bit.App.Controls;
|
||||||
|
|
||||||
namespace Bit.App.Pages
|
namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
|
@ -22,8 +23,9 @@ namespace Bit.App.Pages
|
||||||
var foldersCell = new TextCell { Text = "Folders" };
|
var foldersCell = new TextCell { Text = "Folders" };
|
||||||
foldersCell.Tapped += FoldersCell_Tapped;
|
foldersCell.Tapped += FoldersCell_Tapped;
|
||||||
|
|
||||||
var table = new TableView
|
var table = new ExtendedTableView
|
||||||
{
|
{
|
||||||
|
EnableScrolling = false,
|
||||||
Intent = TableIntent.Menu,
|
Intent = TableIntent.Menu,
|
||||||
Root = new TableRoot
|
Root = new TableRoot
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace Bit.App.Pages
|
||||||
}
|
}
|
||||||
var usernameEntry = new ExtendedEntry { HasBorder = false };
|
var usernameEntry = new ExtendedEntry { HasBorder = false };
|
||||||
var passwordEntry = new ExtendedEntry { IsPassword = true, 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();
|
var uriStackLayout = new FormEntryStackLayout();
|
||||||
uriStackLayout.Children.Add(new EntryLabel { Text = AppResources.URI });
|
uriStackLayout.Children.Add(new EntryLabel { Text = AppResources.URI });
|
||||||
|
@ -83,7 +83,9 @@ namespace Bit.App.Pages
|
||||||
var mainTable = new ExtendedTableView
|
var mainTable = new ExtendedTableView
|
||||||
{
|
{
|
||||||
Intent = TableIntent.Settings,
|
Intent = TableIntent.Settings,
|
||||||
|
EnableScrolling = false,
|
||||||
HasUnevenRows = true,
|
HasUnevenRows = true,
|
||||||
|
EnableSelection = false,
|
||||||
Root = new TableRoot
|
Root = new TableRoot
|
||||||
{
|
{
|
||||||
new TableSection
|
new TableSection
|
||||||
|
@ -93,16 +95,7 @@ namespace Bit.App.Pages
|
||||||
folderCell,
|
folderCell,
|
||||||
usernameCell,
|
usernameCell,
|
||||||
passwordCell
|
passwordCell
|
||||||
}
|
},
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var notesTable = new ExtendedTableView
|
|
||||||
{
|
|
||||||
Intent = TableIntent.Settings,
|
|
||||||
HasUnevenRows = true,
|
|
||||||
Root = new TableRoot
|
|
||||||
{
|
|
||||||
new TableSection(AppResources.Notes)
|
new TableSection(AppResources.Notes)
|
||||||
{
|
{
|
||||||
notesCell
|
notesCell
|
||||||
|
@ -112,17 +105,13 @@ namespace Bit.App.Pages
|
||||||
|
|
||||||
if(Device.OS == TargetPlatform.iOS)
|
if(Device.OS == TargetPlatform.iOS)
|
||||||
{
|
{
|
||||||
mainTable.RowHeight = 70;
|
mainTable.RowHeight = -1;
|
||||||
notesTable.RowHeight = 90;
|
mainTable.EstimatedRowHeight = 70;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tablesStackLayout = new StackLayout();
|
|
||||||
tablesStackLayout.Children.Add(mainTable);
|
|
||||||
tablesStackLayout.Children.Add(notesTable);
|
|
||||||
|
|
||||||
var scrollView = new ScrollView
|
var scrollView = new ScrollView
|
||||||
{
|
{
|
||||||
Content = tablesStackLayout,
|
Content = mainTable,
|
||||||
Orientation = ScrollOrientation.Vertical
|
Orientation = ScrollOrientation.Vertical
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,10 @@ namespace Bit.iOS.Controls
|
||||||
if(view != null)
|
if(view != null)
|
||||||
{
|
{
|
||||||
CorrectMargins(view);
|
CorrectMargins(view);
|
||||||
|
SetScrolling(view);
|
||||||
|
SetSelection(view);
|
||||||
|
UpdateRowHeight(view);
|
||||||
|
UpdateEstimatedRowHeight(view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,11 +33,59 @@ namespace Bit.iOS.Controls
|
||||||
var view = (ExtendedTableView)Element;
|
var view = (ExtendedTableView)Element;
|
||||||
|
|
||||||
CorrectMargins(view);
|
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)
|
private void CorrectMargins(ExtendedTableView view)
|
||||||
{
|
{
|
||||||
Control.ContentInset = new UIEdgeInsets(-10, 0, -100, 0);
|
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