Permalink
Browse files

Added Arrow for expanding sections.

  • Loading branch information...
1 parent 466c467 commit a15dc881d09d62ec317ef4a78f82277f58c6e064 @RobertKozak committed Jul 11, 2011
View
29 Dialog/DialogViewController/DialogViewDataSource.cs
@@ -1,4 +1,3 @@
-using MonoTouch.ObjCRuntime;
//
// DialogViewDataSource.cs
//
@@ -32,14 +31,17 @@
namespace MonoMobile.MVVM
{
using System;
- using MonoTouch.UIKit;
using System.Drawing;
using System.Linq;
+ using MonoTouch.CoreAnimation;
using MonoTouch.Foundation;
+ using MonoTouch.ObjCRuntime;
+ using MonoTouch.UIKit;
public class DialogViewDataSource : UITableViewSource
{
private HeaderTapGestureRecognizer tapRecognizer;
+ private Selector _HeaderSelector = new Selector("headerTap");
private const float _SnapBoundary = 65;
protected DialogViewController Container;
@@ -144,9 +146,17 @@ public override UIView GetViewForHeader(UITableView tableView, int sectionIdx)
if (section.HeaderView != null)
{
- tapRecognizer = new HeaderTapGestureRecognizer(section, this, new Selector("headerTap"));
+ if (section.IsExpandable)
+ {
+ section.ArrowView.Bounds = new RectangleF(0, 0, 16, 16);
+ section.ArrowView.Frame = new RectangleF(5, 8, 16, 16);
+ section.HeaderView.Add(section.ArrowView);
+
+ tapRecognizer = new HeaderTapGestureRecognizer(section, this, _HeaderSelector);
- section.HeaderView.AddGestureRecognizer(tapRecognizer);
+ section.HeaderView.AddGestureRecognizer(tapRecognizer);
+ Flip(section);
+ }
}
return section.HeaderView;
}
@@ -163,8 +173,19 @@ public void HeaderTap(HeaderTapGestureRecognizer recognizer)
section.ExpandState = ExpandState.Closed;
else
section.ExpandState = ExpandState.Opened;
+
+ Flip(section);
}
}
+
+ private void Flip(ISection section)
+ {
+ UIView.BeginAnimations(null);
+ UIView.SetAnimationDuration(0.18f);
+ section.ArrowView.Layer.Transform = section.ExpandState == ExpandState.Closed ? CATransform3D.MakeRotation((float)Math.PI * 1.5f, 0, 0, 1) : CATransform3D.MakeRotation((float)Math.PI * 2f, 0, 0, 1);
+
+ UIView.CommitAnimations();
+ }
public override float GetHeightForHeader(UITableView tableView, int sectionIdx)
{
View
11 Dialog/Section.cs
@@ -62,7 +62,9 @@ public ExpandState ExpandState
get { return _ExpandState; }
set { SetExpandState(value); }
}
- public bool IsExpandable { get; set; }
+ public bool IsExpandable {get; set; }
+
+ public UIImageView ArrowView { get; set; }
public new IRoot Root { get { return Parent as IRoot; } }
@@ -83,7 +85,8 @@ public Section() : this((string)null)
public Section(string caption) : base(caption)
{
Elements = new ObservableCollection<IElement>();
-
+ ArrowView = new UIImageView(UIImage.FromResource(null, "ArrowDown.png"));
+
// if (DataTemplate != null)
// {
// DataTemplate.BindProperties();
@@ -249,7 +252,7 @@ public void SetExpandState(ExpandState state)
if (_ExpandState != state)
{
_ExpandState = state;
-
+
if (Root != null && IsExpandable)
{
if (_HiddenElements == null)
@@ -269,7 +272,7 @@ public void SetExpandState(ExpandState state)
}
- Root.TableView.ReloadSections(new NSIndexSet((uint)Index), UITableViewRowAnimation.Fade);
+ Root.TableView.ReloadSections(new NSIndexSet((uint)Index), UITableViewRowAnimation.None);
Root.TableView.EndUpdates();
}
}
View
BIN Images/ArrowDown.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
3 Interfaces/ISection.cs
@@ -56,7 +56,8 @@ public interface ISection : IThemeable, IDisposable, IInitializable
string FooterText { get; set; }
UIView HeaderView { get; set; }
UIView FooterView { get; set; }
-
+ UIImageView ArrowView { get; set; }
+
bool IsExpandable { get; set;}
ExpandState ExpandState { get; set; }
View
3 MonoMobile.MVVM.csproj
@@ -355,5 +355,8 @@
<EmbeddedResource Include="Images\checkmark.png">
<LogicalName>checkmark.png</LogicalName>
</EmbeddedResource>
+ <EmbeddedResource Include="Images\ArrowDown.png">
+ <LogicalName>ArrowDown.png</LogicalName>
+ </EmbeddedResource>
</ItemGroup>
</Project>
View
364 Samples/Views/MovieListView.cs
@@ -22,66 +22,66 @@ namespace Samples
// [EnableSearch(true, IncrementalSearch = true)]
public class MovieListView: View, INotifyPropertyChanged
{
-// [Section(Order = 2)]
-//// [EnableSearch(true, IncrementalSearch = false)]
-//// public List<ISection> Search(ISection[] sections, string searchText)
-//// {
-//// var result = new List<ISection>();
-////
-//// foreach(var section in sections)
-//// foreach(var element in section.Elements)
-//// {
-//// if (element.Caption.Contains(searchText))
-//// result.Add(new Section() { element });
-//// }
-////
-//// return result;
-//// }
-//
-// private View1 _View1 = new View1();
-// private View2 _View2 = new View2();
-//
-// [Multiline]
-// [DefaultValue("Test Entry. This is a sample of some very long text.")]
-// // [Theme(typeof(CorkStyle))]
-// public string TestEntry2 { get; set; }
-//
-// [DefaultValue(true)]
-// //[Checkbox]
-// public bool TestBool { get; set; }
-//
-// [Date]
-// // [Theme(typeof(MarbledTheme))]
-// public DateTime Date {get; set;}
-//
-// [Time]
-// // [Theme(typeof(GraniteStyle))]
-// public DateTime Time {get; set;}
-//
-// [Password("Enter passsword")]
-// [DefaultValue("Test String")]
-// public string MyString
-// {
-// get;
-// set;
-// }
-//
-// [Section]
-// [Root(ViewType = typeof(MovieView))]
-// // [List(ViewType = typeof(MovieView))]//, ThemeType = typeof(WoodenTheme))]
-// public ObservableCollection<MovieViewModel> Movies
-// {
-// get;
-// set;
-// }
-//
-// [LoadMore]
-// public void Activity()
-// {
-// Thread.Sleep(1500);
-// }
+ // [EnableSearch(true, IncrementalSearch = false)]
+ public List<ISection> Search(ISection[] sections, string searchText)
+ {
+ var result = new List<ISection>();
+
+ foreach(var section in sections)
+ foreach(var element in section.Elements)
+ {
+ if (element.Caption.Contains(searchText))
+ result.Add(new Section() { element });
+ }
+
+ return result;
+ }
+
+ private View1 _View1 = new View1();
+ private View2 _View2 = new View2();
+
+ [Section("Test Section", "",Order = 2, IsExpandable = true)]
+ [Multiline]
+ [DefaultValue("Test Entry. This is a sample of some very long text.")]
+ // [Theme(typeof(CorkStyle))]
+ public string TestEntry2 { get; set; }
+
+ [DefaultValue(true)]
+ //[Checkbox]
+ public bool TestBool { get; set; }
+
+ [Date]
+ // [Theme(typeof(MarbledTheme))]
+ public DateTime Date {get; set;}
+
+ [Time]
+ // [Theme(typeof(GraniteStyle))]
+ public DateTime Time {get; set;}
- [Section("Using a DataTemplate", "This is a footer", IsExpandable = true, ExpandState = ExpandState.Closed)]
+ [Password("Enter passsword")]
+ [DefaultValue("Test String")]
+ public string MyString
+ {
+ get;
+ set;
+ }
+
+ [Section]
+ [Root(ViewType = typeof(MovieView))]
+ // [List(ViewType = typeof(MovieView))]//, ThemeType = typeof(WoodenTheme))]
+ public ObservableCollection<MovieViewModel> Movies
+ {
+ get;
+ set;
+ }
+
+ [LoadMore]
+ public void Activity()
+ {
+ Thread.Sleep(1500);
+ }
+
+ [Section("Using a DataTemplate", "This is a footer")]
[Root(ViewType = typeof(MovieView))]
[NavbarButton(UIBarButtonSystemItem.Add)]
public ObservableCollection<MovieViewModel> Movies2
@@ -118,138 +118,138 @@ public string TestEntry
set;// { Set(()=>TestEntry, value); }
}
-// [Section]
-// [Root(CellStyle = UITableViewCellStyle.Subtitle)]
-// [Caption("Root Address")]
-// public AddressView AddressView
-// {
-// get;// { return Get(()=>AddressView, new AddressView() {Number = "4751", Street ="Wilshire Blvd", City ="LA", State="CA", Zip ="90010" }); }
-// set;// { Set(()=>AddressView, value); }
-// }
-//
-// private IView _DynamicView;
-// [Section(Order = 10)]
-// [Root]
-// public IView DynamicView
-// {
-// get { return _DynamicView; }
-// set
-// {
-// _DynamicView = value;
-// if (PropertyChanged != null)
-// PropertyChanged(this, new PropertyChangedEventArgs("DynamicView"));
-// } // { Set(()=>DynamicView, value); }
-// }
-//
-// [MultiSelection]
-// public List<string> MovieClasses { get; set; }
-//
-// [Section]
-// // [CellStyle(typeof(ClearStyle))]
-// //[CellStyle(typeof(ButtonCellStyle))]
-// public View WebSamples
-// {
-// get;// { return Get(()=>WebSamples, new WebSamples()); }
-// set;// { Set(()=>WebSamples, value); }
-// }
-//
-// private bool _CanChangeStyle;
-// [Checkmark]
-// public bool CanChangeStyle
-// {
-// get { return _CanChangeStyle; }
-// set
-// {
-// if (_CanChangeStyle != value)
-// {
-// _CanChangeStyle = value;
-// if (PropertyChanged != null)
-// PropertyChanged(this, new PropertyChangedEventArgs("CanChangeStyle"));
-// }
-// }
-// }
-//
-// [Button]
-// [Section(Order = 11)]
-// public void ChangeDynamicView()
-// {
-// if(DynamicView.GetType() == typeof(View1))
-// DynamicView = _View2;
-// else
-// DynamicView = _View1;
-// }
-//
-// [Button("CanChangeStyle", CommandOption = CommandOption.Hide)]
-// public void ChangeStyle()
-// {
-//
-// }
-//// [List]
-//// [Section("", "This Address is the same as Root Address above")]
-//// public AddressView InlineAddress
-//// {
-//// get { return Get(()=>AddressView); }
-//// set { Set(()=>AddressView, value); }
-//// }
-//
-// [Section]
-// [Root]
-// public InterestingView InterestingStuff
-// {
-// get;// { return Get(()=>InterestingStuff, new InterestingView()); }
-// set;// { Set(()=>InterestingStuff, value); }
-// }
-//
-// // [PullToRefresh]
-// public void RefreshData()
+ [Section]
+ [Root(CellStyle = UITableViewCellStyle.Subtitle)]
+ [Caption("Root Address")]
+ public AddressView AddressView
+ {
+ get;// { return Get(()=>AddressView, new AddressView() {Number = "4751", Street ="Wilshire Blvd", City ="LA", State="CA", Zip ="90010" }); }
+ set;// { Set(()=>AddressView, value); }
+ }
+
+ private IView _DynamicView;
+ [Section(Order = 10)]
+ [Root]
+ public IView DynamicView
+ {
+ get { return _DynamicView; }
+ set
+ {
+ _DynamicView = value;
+ if (PropertyChanged != null)
+ PropertyChanged(this, new PropertyChangedEventArgs("DynamicView"));
+ } // { Set(()=>DynamicView, value); }
+ }
+
+ [MultiSelection]
+ public List<string> MovieClasses { get; set; }
+
+ [Section]
+ // [CellStyle(typeof(ClearStyle))]
+ //[CellStyle(typeof(ButtonCellStyle))]
+ public View WebSamples
+ {
+ get;// { return Get(()=>WebSamples, new WebSamples()); }
+ set;// { Set(()=>WebSamples, value); }
+ }
+
+ private bool _CanChangeStyle;
+ [Checkmark]
+ public bool CanChangeStyle
+ {
+ get { return _CanChangeStyle; }
+ set
+ {
+ if (_CanChangeStyle != value)
+ {
+ _CanChangeStyle = value;
+ if (PropertyChanged != null)
+ PropertyChanged(this, new PropertyChangedEventArgs("CanChangeStyle"));
+ }
+ }
+ }
+
+ [Button]
+ [Section(Order = 11)]
+ public void ChangeDynamicView()
+ {
+ if(DynamicView.GetType() == typeof(View1))
+ DynamicView = _View2;
+ else
+ DynamicView = _View1;
+ }
+
+ [Button("CanChangeStyle", CommandOption = CommandOption.Hide)]
+ public void ChangeStyle()
+ {
+
+ }
+// [List]
+// [Section("", "This Address is the same as Root Address above")]
+// public AddressView InlineAddress
// {
-// for(var index = 0; index < 100; index++)
-// System.Threading.Thread.Sleep(50);
+// get { return Get(()=>AddressView); }
+// set { Set(()=>AddressView, value); }
// }
-//
-// public HoneyDoListView HoneyDoList { get; set; }
-// [List]
-// public Genre Genre { get; set; }
+
+ [Section]
+ [Root]
+ public InterestingView InterestingStuff
+ {
+ get;// { return Get(()=>InterestingStuff, new InterestingView()); }
+ set;// { Set(()=>InterestingStuff, value); }
+ }
+
+ // [PullToRefresh]
+ public void RefreshData()
+ {
+ for(var index = 0; index < 100; index++)
+ System.Threading.Thread.Sleep(50);
+ }
+
+ public HoneyDoListView HoneyDoList { get; set; }
+ [List]
+ public Genre Genre { get; set; }
public MovieListView()
{
DataContext = new MovieListViewModel();// { TestEntry = "TestEntry string" };
-// HoneyDoList = new HoneyDoListView();
-//
-// var enumType = typeof(Genre);
-// var enumItems = from field in enumType.GetFields()
-// where field.IsLiteral
-// select EnumExtensions.GetDescriptionValue(field.Name, enumType);
-//
-// MovieClasses = new List<string>(enumItems.ToList());
-//
-// Movies = new ObservableCollection<MovieViewModel>();
-// var dataModel = new MovieDataModel();
-// dataModel.Load();
-// Movies =dataModel.Movies;
-// MyString = "Test string";
-//
-//InterestingStuff = new InterestingView();
-//
-// Location = new CLLocationCoordinate2D(-33.867139,151.207114);
-//
-//DynamicView = new View1();
-// AddressView = new AddressView() {Number = "4751", Street ="Wilshire Blvd", City ="LA", State="CA", Zip ="90010" };
-// WebSamples = new WebSamples();
+ HoneyDoList = new HoneyDoListView();
+
+ var enumType = typeof(Genre);
+ var enumItems = from field in enumType.GetFields()
+ where field.IsLiteral
+ select EnumExtensions.GetDescriptionValue(field.Name, enumType);
+
+ MovieClasses = new List<string>(enumItems.ToList());
+
+ Movies = new ObservableCollection<MovieViewModel>();
+ var dataModel = new MovieDataModel();
+ dataModel.Load();
+ Movies =dataModel.Movies;
+ MyString = "Test string";
+
+InterestingStuff = new InterestingView();
+
+ Location = new CLLocationCoordinate2D(-33.867139,151.207114);
+
+DynamicView = new View1();
+ AddressView = new AddressView() {Number = "4751", Street ="Wilshire Blvd", City ="LA", State="CA", Zip ="90010" };
+ WebSamples = new WebSamples();
+
+//// foreach(var movie in dataModel.Movies)
+//// {
+//// Movies.Add(new MovieView() { DataContext = movie });
+//// }
//
-////// foreach(var movie in dataModel.Movies)
-////// {
-////// Movies.Add(new MovieView() { DataContext = movie });
-////// }
-////
-////Movies2 = Movies;
-//
-// Time = DateTime.Now;
-// Date = DateTime.Now;
-//
-// CanChangeStyle = true;
+//Movies2 = Movies;
+
+ Time = DateTime.Now;
+ Date = DateTime.Now;
+
+ CanChangeStyle = true;
}

0 comments on commit a15dc88

Please sign in to comment.