Skip to content

Commit

Permalink
Merge pull request #42 from muak/fixCellHeight
Browse files Browse the repository at this point in the history
Fix PickerCell / iOS Cell Constraints
  • Loading branch information
muak authored Oct 4, 2018
2 parents 369bcc0 + 11ab82b commit 191a552
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 92 deletions.
94 changes: 16 additions & 78 deletions Sample/Sample/ViewModels/PickerSurveyViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
using System.Windows.Input;
using Xamarin.Forms;
using System;
using Prism.Navigation;
using Reactive.Bindings;
using System.Collections.Generic;
using System.Linq;
using Prism.Mvvm;

namespace Sample.ViewModels
{
class PickerSurveyViewModel
public class PickerSurveyViewModel:BindableBase,INavigatingAware
{
public ObservableCollection<Person> MasterItemsSource { get; } = new ObservableCollection<Person>();
public ObservableCollection<Person> MasterItemsSourceSelectedItems { get; } = new ObservableCollection<Person>();

public ObservableCollection<Person> SlaveItemsSource { get; } = new ObservableCollection<Person>();
public ObservableCollection<Person> SlaveItemsSourceSelectedItems { get; } = new ObservableCollection<Person>();
public ObservableCollection<Person> MasterItemsSource { get; set; }
public ObservableCollection<Person> MasterItemsSourceSelectedItems { get; set; } = new ObservableCollection<Person>();

string[] type = { "letters", "number" };

Expand All @@ -21,87 +23,23 @@ class PickerSurveyViewModel

public PickerSurveyViewModel()
{
foreach (var item in type)
{
MasterItemsSource.Add(new Person()
{
Name = item,
Age = 1
});
}

}

ICommand selectMasterCommand;
public ICommand SelectMasterCommand =>
selectMasterCommand ?? (selectMasterCommand = new Command(async () => await ExecuteSelectMasterCommand()));

async Task ExecuteSelectMasterCommand()
public void OnNavigatingTo(NavigationParameters parameters)
{
try
{

if (MasterItemsSourceSelectedItems.Count == 0)
return;

SlaveItemsSource.Clear();
SlaveItemsSourceSelectedItems.Clear();


await Task.Delay(100);

switch (MasterItemsSourceSelectedItems[0].Name)
{
case "letters":

foreach (var item in listLetters)
{
SlaveItemsSource.Add(new Person()
{
Name = item,
Age = 1
});
}
var list = new List<Person>{
new Person {Name = "A",Age = 20},
new Person {Name = "B",Age = 30}
};

MasterItemsSource = new ObservableCollection<Person>(list);
MasterItemsSourceSelectedItems.Add(list[0]);

break;
case "number":
foreach (var item in listNumbers)
{
SlaveItemsSource.Add(new Person()
{
Name = item,
Age = 1
});
}

RaisePropertyChanged(nameof(MasterItemsSource));

break;

default:
break;
}


SlaveItemsSourceSelectedItems.Add(SlaveItemsSource[0]);

}
catch (Exception ex)
{

}
finally
{

}
}
}

//public class Person
//{
// public string Name { get; set; }
// public int Age { get; set; }
//}


}
11 changes: 3 additions & 8 deletions Sample/Sample/Views/PickerSurvey.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,12 @@

<sv:SettingsView HasUnevenRows="true" HeaderHeight="36" HeaderPadding="14,0,0,6" HeaderTextVerticalAlign="End" FooterPadding="14,4,4,6">

<sv:Section x:Name="svv" Title="Select a letter and then select a number..." FooterText="...the old letter value is still visible, even if you clear the selecteditems in viewmode">
<sv:Section x:Name="svv">

<sv:PickerCell Title="number o letter?" ItemsSource="{Binding MasterItemsSource}" DisplayMember="Name" MaxSelectedNumber="1"
SelectedItems="{Binding MasterItemsSourceSelectedItems}" SelectedCommand="{Binding SelectMasterCommand}" ValueText=""
<sv:PickerCell Title="Select" ItemsSource="{Binding MasterItemsSource}" DisplayMember="Name" MaxSelectedNumber="1"
SelectedItems="{Binding MasterItemsSourceSelectedItems}" SelectedCommand="{Binding SelectMasterCommand}"
KeepSelectedUntilBack="true" PageTitle="Select" />
</sv:Section>

<sv:Section Title="Select detail">
<sv:PickerCell Title="Detail" ItemsSource="{Binding SlaveItemsSource}" DisplayMember="Name" MaxSelectedNumber="1"
SelectedItems="{Binding SlaveItemsSourceSelectedItems}" KeepSelectedUntilBack="true" PageTitle="Select" ValueText="" />
</sv:Section>

</sv:SettingsView>

Expand Down
3 changes: 2 additions & 1 deletion SettingsView.Droid/Cells/PickerCellRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public override void CellPropertyChanged(object sender, System.ComponentModel.Pr
}
}
else if (e.PropertyName == PickerCell.ItemsSourceProperty.PropertyName) {
UpdateCollectionChanged();
UpdateCollectionChanged();
UpdateSelectedItems(true);
}
}

Expand Down
7 changes: 4 additions & 3 deletions SettingsView.iOS/Cells/CellBaseView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void UpdateIconSize()
_iconConstraintHeight = IconView.HeightAnchor.ConstraintEqualTo((nfloat)size.Height);
_iconConstraintWidth = IconView.WidthAnchor.ConstraintEqualTo((nfloat)size.Width);

_iconConstraintHeight.Priority = 250f; // fix warning-log:Unable to simultaneously satisfy constraints.
_iconConstraintHeight.Priority = 999f; // fix warning-log:Unable to simultaneously satisfy constraints.
_iconConstraintHeight.Active = true;
_iconConstraintWidth.Active = true;

Expand Down Expand Up @@ -432,7 +432,7 @@ void UpdateMinRowHeight()

if (CellParent.HasUnevenRows) {
_minheightConstraint = _stackH.HeightAnchor.ConstraintGreaterThanOrEqualTo(CellParent.RowHeight);
_minheightConstraint.Priority = 250f;
_minheightConstraint.Priority = 999f;
_minheightConstraint.Active = true;

}
Expand Down Expand Up @@ -637,10 +637,11 @@ void SetUpContentView()
_stackH.BottomAnchor.ConstraintEqualTo(ContentView.BottomAnchor).Active = true;
_stackH.RightAnchor.ConstraintEqualTo(ContentView.RightAnchor).Active = true;


var minHeight = Math.Max(CellParent?.RowHeight ?? 44, SettingsViewRenderer.MinRowHeight);
_minheightConstraint = _stackH.HeightAnchor.ConstraintGreaterThanOrEqualTo(minHeight);
// fix warning-log:Unable to simultaneously satisfy constraints.
_minheightConstraint.Priority = 250f;
_minheightConstraint.Priority = 999f; // this is superior to any other view.
_minheightConstraint.Active = true;
}

Expand Down
1 change: 1 addition & 0 deletions SettingsView.iOS/Cells/PickerCellRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public override void CellPropertyChanged(object sender, System.ComponentModel.Pr
}
if(e.PropertyName == PickerCell.ItemsSourceProperty.PropertyName){
UpdateCollectionChanged();
UpdateSelectedItems(true);
}
}

Expand Down
5 changes: 3 additions & 2 deletions nuget/SettingsView_mac.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>AiForms.SettingsView</id>
<version>0.3.1</version>
<version>0.3.2</version>
<title>SettingsView for Xamarin.Forms</title>
<authors>kamu</authors>
<owners>kamu</owners>
Expand All @@ -16,7 +16,8 @@ There are various cells such as (LabelCell,ButtonCell,CommandCell,SwitchCell,Che
<releaseNotes>
## Bug fixes

* [iOS] keep outputting warning on console by contradiction of cell constrains.
* [PickerCell] Depending on the order of setting properties, SelectedItems's text is not correctly displayed.
* [iOS] Fix broken constraints.
</releaseNotes>
<tags>Xamarin.Forms TableView Cell Setting Configuration Option ListView UITableView RecyclerView ReOrder DragDrop</tags>
<language>en-US</language>
Expand Down

0 comments on commit 191a552

Please sign in to comment.