1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-04 09:33:16 +00:00

Moved cells from storyboard into being managed in controller code. new ios views for tableview cells.

This commit is contained in:
Kyle Spearrin
2016-07-09 01:07:02 -04:00
parent 3291a0d78d
commit 3a82653ae5
10 changed files with 395 additions and 364 deletions

View File

@@ -0,0 +1,111 @@
using System;
using UIKit;
namespace Bit.iOS.Core.Views
{
public class FormEntryTableViewCell : UITableViewCell
{
public FormEntryTableViewCell(
string labelName = null,
bool useTextView = false,
nfloat? height = null)
: base(UITableViewCellStyle.Default, nameof(FormEntryTableViewCell))
{
var descriptor = UIFontDescriptor.PreferredBody;
var pointSize = descriptor.PointSize;
if(labelName != null)
{
Label = new UILabel
{
Text = labelName,
TranslatesAutoresizingMaskIntoConstraints = false,
Font = UIFont.FromDescriptor(descriptor, 0.8f * pointSize),
TextColor = new UIColor(red: 0.47f, green: 0.47f, blue: 0.47f, alpha: 1.0f)
};
ContentView.Add(Label);
}
if(useTextView)
{
TextView = new UITextView
{
TranslatesAutoresizingMaskIntoConstraints = false,
Font = UIFont.FromDescriptor(descriptor, pointSize)
};
ContentView.Add(TextView);
ContentView.AddConstraints(new NSLayoutConstraint[] {
NSLayoutConstraint.Create(TextView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Leading, 1f, 15f),
NSLayoutConstraint.Create(ContentView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, TextView, NSLayoutAttribute.Trailing, 1f, 15f),
NSLayoutConstraint.Create(ContentView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, TextView, NSLayoutAttribute.Bottom, 1f, 10f)
});
if(labelName != null)
{
ContentView.AddConstraint(
NSLayoutConstraint.Create(TextView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, Label, NSLayoutAttribute.Bottom, 1f, 10f));
}
else
{
ContentView.AddConstraint(
NSLayoutConstraint.Create(TextView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Top, 1f, 10f));
}
if(height.HasValue)
{
ContentView.AddConstraint(
NSLayoutConstraint.Create(TextView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1f, height.Value));
}
}
else
{
TextField = new UITextField
{
TranslatesAutoresizingMaskIntoConstraints = false,
BorderStyle = UITextBorderStyle.None,
Font = UIFont.FromDescriptor(descriptor, pointSize),
ClearButtonMode = UITextFieldViewMode.WhileEditing
};
ContentView.Add(TextField);
ContentView.AddConstraints(new NSLayoutConstraint[] {
NSLayoutConstraint.Create(TextField, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Leading, 1f, 15f),
NSLayoutConstraint.Create(ContentView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, TextField, NSLayoutAttribute.Trailing, 1f, 15f),
NSLayoutConstraint.Create(ContentView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, TextField, NSLayoutAttribute.Bottom, 1f, 10f)
});
if(labelName != null)
{
ContentView.AddConstraint(
NSLayoutConstraint.Create(TextField, NSLayoutAttribute.Top, NSLayoutRelation.Equal, Label, NSLayoutAttribute.Bottom, 1f, 10f));
}
else
{
ContentView.AddConstraint(
NSLayoutConstraint.Create(TextField, NSLayoutAttribute.Top, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Top, 1f, 10f));
}
if(height.HasValue)
{
ContentView.AddConstraint(
NSLayoutConstraint.Create(TextField, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1f, height.Value));
}
}
if(labelName != null)
{
ContentView.AddConstraints(new NSLayoutConstraint[] {
NSLayoutConstraint.Create(Label, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Leading, 1f, 15f),
NSLayoutConstraint.Create(Label, NSLayoutAttribute.Top, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Top, 1f, 10f),
NSLayoutConstraint.Create(ContentView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, Label, NSLayoutAttribute.Trailing, 1f, 15f)
});
}
}
public UILabel Label { get; set; }
public UITextField TextField { get; set; }
public UITextView TextView { get; set; }
}
}

View File

@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using UIKit;
namespace Bit.iOS.Core.Views
{
public class PickerTableViewCell : UITableViewCell
{
public PickerTableViewCell(string labelName)
: base(UITableViewCellStyle.Default, nameof(PickerTableViewCell))
{
TextLabel.Text = labelName;
var entry = new UITextField { BorderStyle = UITextBorderStyle.RoundedRect };
entry.Started += Entry_Started;
entry.Ended += Entry_Ended;
var width = (float)UIScreen.MainScreen.Bounds.Width;
var toolbar = new UIToolbar(new RectangleF(0, 0, width, 44))
{
BarStyle = UIBarStyle.Default,
Translucent = true
};
var spacer = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);
var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (o, a) =>
{
var s = (PickerSource)Picker.Model;
if(s.SelectedIndex == -1 && Items != null && Items.Count > 0)
{
}
entry.ResignFirstResponder();
});
toolbar.SetItems(new[] { spacer, doneButton }, false);
entry.InputView = Picker;
entry.InputAccessoryView = toolbar;
}
public UIPickerView Picker { get; set; } = new UIPickerView();
public int MyProperty { get; set; }
public List<string> Items { get; set; } = new List<string>();
public int SelectedIndex { get; set; }
private void Entry_Ended(object sender, EventArgs e)
{
//throw new NotImplementedException();
}
private void Entry_Started(object sender, EventArgs e)
{
//throw new NotImplementedException();
}
private class PickerSource : UIPickerViewModel
{
readonly PickerTableViewCell _cell;
public PickerSource(PickerTableViewCell cell)
{
_cell = cell;
}
public int SelectedIndex { get; internal set; }
public string SelectedItem { get; internal set; }
public override nint GetComponentCount(UIPickerView picker)
{
return 1;
}
public override nint GetRowsInComponent(UIPickerView pickerView, nint component)
{
return _cell.Items != null ? _cell.Items.Count : 0;
}
public override string GetTitle(UIPickerView picker, nint row, nint component)
{
return _cell.Items[(int)row];
}
public override void Selected(UIPickerView picker, nint row, nint component)
{
if(_cell.Items.Count == 0)
{
SelectedItem = null;
SelectedIndex = -1;
}
else
{
SelectedItem = _cell.Items[(int)row];
SelectedIndex = (int)row;
}
//_renderer.UpdatePickerFromModel(this);
}
}
}
}

View File

@@ -0,0 +1,17 @@
using System;
using UIKit;
namespace Bit.iOS.Core.Views
{
public class SwitchTableViewCell : UITableViewCell
{
public SwitchTableViewCell(string labelName)
: base(UITableViewCellStyle.Default, nameof(SwitchTableViewCell))
{
TextLabel.Text = labelName;
AccessoryView = Switch;
}
public UISwitch Switch { get; set; } = new UISwitch();
}
}

View File

@@ -67,6 +67,9 @@
<Compile Include="Services\KeyChainStorageService.cs" />
<Compile Include="Services\Settings.cs" />
<Compile Include="Services\SqlService.cs" />
<Compile Include="Views\PickerTableViewCell.cs" />
<Compile Include="Views\SwitchTableViewCell.cs" />
<Compile Include="Views\FormEntryTableViewCell.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />