public ComposableViewListCell(UITableViewCellStyle style, NSString reuseIdentifier, NSIndexPath indexPath, IList <Type> viewTypes, ListSource listSource) : base(style, reuseIdentifier) { Style = style; IndexPath = indexPath; ListSource = listSource; if (!ListSource.RowHeights.ContainsKey(ListSource.BaseIndexPath)) { ListSource.RowHeights.Add(ListSource.BaseIndexPath, ListSource.Controller.TableView.RowHeight); } _CompositeView = new UIView(Bounds); Theme = Theme.CreateTheme(listSource.Controller.Theme); if (ViewList == null) { CreateViewList(viewTypes); } AddSubview(_CompositeView); }
public static UITableViewSource ParseList(DialogViewController controller, MemberData memberData, List<Type> viewTypes) { object memberValue = memberData.Value; var member = memberData.Member; var type = memberData.Type; var isList = typeof(IEnumerable).IsAssignableFrom(type) || typeof(Enum).IsAssignableFrom(type); if (isList) { var data = type.CreateGenericListFromEnumerable(memberValue); var source = new ListSource(controller, (IList)data, viewTypes); if (source != null) { if (type.IsEnum) { source.SelectedItem = memberValue; source.SelectedItems.Add(source.SelectedItem); } else if (data != null && data.Count == 1) { source.SelectedItem = data[0]; source.SelectedItems.Add(source.SelectedItem); } source.Caption = GetCaption(member); var listAttribute = member.GetCustomAttribute<ListAttribute>(); if (listAttribute != null) { source.DisplayMode = listAttribute.DisplayMode; source.SelectionAction = listAttribute.SelectionAction; source.IsMultiselect = listAttribute.SelectionAction == SelectionAction.Multiselection; source.IsSelectable = source.SelectionAction != SelectionAction.NavigateToView; source.IsNavigable = listAttribute.DisplayMode != DisplayMode.Collapsable || listAttribute.SelectionAction == SelectionAction.NavigateToView; source.SelectedAccessoryViewType = listAttribute.SelectedAccessoryViewType; source.UnselectedAccessoryViewType = listAttribute.UnselectedAccessoryViewType; source.UnselectionBehavior = listAttribute.UnselectionBehavior; source.ReplaceCaptionWithSelection = listAttribute.ReplaceCaptionWithSelection; if (!string.IsNullOrEmpty(listAttribute.SelectedItemMemberName)) { source.SelectedItemMemberName = listAttribute.SelectedItemMemberName; } if (!string.IsNullOrEmpty(listAttribute.SelectedItemsMemberName)) { source.SelectedItemsMemberName = listAttribute.SelectedItemsMemberName; } } source.PopOnSelection = source.SelectionAction == SelectionAction.PopOnSelection; var memberAttributes = member.GetCustomAttributes(false); foreach(var memberAttribute in memberAttributes) { var navigable = memberAttribute as INavigable; if (navigable != null) { source.IsSelectable = false; source.NavigationViewType = navigable.NavigateToViewType; source.IsNavigable = navigable.NavigateToViewType != null; } } source.IsRootCell = source.DisplayMode != DisplayMode.List; return source; } } return null; }
public static UITableViewSource ParseList(DialogViewController controller, MemberData memberData, List <Type> viewTypes) { object memberValue = memberData.Value; var member = memberData.Member; var type = memberData.Type; var isList = typeof(IEnumerable).IsAssignableFrom(type) || typeof(Enum).IsAssignableFrom(type); if (isList) { var data = type.CreateGenericListFromEnumerable(memberValue); var source = new ListSource(controller, (IList)data, viewTypes); if (source != null) { if (type.IsEnum) { source.SelectedItem = memberValue; source.SelectedItems.Add(source.SelectedItem); } else if (data != null && data.Count == 1) { source.SelectedItem = data[0]; source.SelectedItems.Add(source.SelectedItem); } source.Caption = GetCaption(member); var listAttribute = member.GetCustomAttribute <ListAttribute>(); if (listAttribute != null) { source.DisplayMode = listAttribute.DisplayMode; source.SelectionAction = listAttribute.SelectionAction; source.IsMultiselect = listAttribute.SelectionAction == SelectionAction.Multiselection; source.IsSelectable = source.SelectionAction != SelectionAction.NavigateToView; source.IsNavigable = listAttribute.DisplayMode != DisplayMode.Collapsable || listAttribute.SelectionAction == SelectionAction.NavigateToView; source.SelectedAccessoryViewType = listAttribute.SelectedAccessoryViewType; source.UnselectedAccessoryViewType = listAttribute.UnselectedAccessoryViewType; source.UnselectionBehavior = listAttribute.UnselectionBehavior; source.ReplaceCaptionWithSelection = listAttribute.ReplaceCaptionWithSelection; if (!string.IsNullOrEmpty(listAttribute.SelectedItemMemberName)) { source.SelectedItemMemberName = listAttribute.SelectedItemMemberName; } if (!string.IsNullOrEmpty(listAttribute.SelectedItemsMemberName)) { source.SelectedItemsMemberName = listAttribute.SelectedItemsMemberName; } } source.PopOnSelection = source.SelectionAction == SelectionAction.PopOnSelection; var memberAttributes = member.GetCustomAttributes(false); foreach (var memberAttribute in memberAttributes) { var navigable = memberAttribute as INavigable; if (navigable != null) { source.IsSelectable = false; source.NavigationViewType = navigable.NavigateToViewType; source.IsNavigable = navigable.NavigateToViewType != null; } } source.IsRootCell = source.DisplayMode != DisplayMode.List; return(source); } } return(null); }
public void NavigateToList() { var section = Sections[0]; var data = GetSectionData(0); if (string.IsNullOrEmpty(Caption)) { Caption = data.ToString(); } var dvc = new DialogViewController(Caption, null, Controller.Theme, true) { ToolbarButtons = null, NavbarButtons = null }; if (NavigationSource == null) NavigationSource = new ListSource(dvc, data, section.ViewTypes[CellId]); NavigationSource.SelectionAction = SelectionAction; NavigationSource.IsSelectable = (SelectionAction == SelectionAction.PopOnSelection || SelectionAction == SelectionAction.Selection || SelectionAction == SelectionAction.Multiselection); NavigationSource.NavigationViewType = null; var viewType = NavigationViewType; if (viewType == null && SelectionAction == SelectionAction.NavigateToView) { var genericType = data.GetType().GetGenericArguments().FirstOrDefault(); viewType = ViewContainer.GetView(genericType); } if (viewType != null) { NavigationSource.IsNavigable = viewType == typeof(ObjectCellView<object>); NavigationSource.NavigationViewType = viewType; } NavigationSource.IsNavigable = !PopOnSelection && NavigationSource.IsNavigable && SelectionAction != SelectionAction.Custom; NavigationSource.CellFactory = CellFactory; NavigationSource.SelectedItem = SelectedItem; NavigationSource.SelectedItems = SelectedItems; NavigationSource.UnselectionBehavior = UnselectionBehavior; NavigationSource.IsMultiselect = IsMultiselect; // NavigationSource.IsSelectable = IsSelectable; if (data.Count > 0 && (data[0].GetType().IsPrimitive || data[0].GetType().IsEnum)) NavigationSource.IsSelectable = true; NavigationSource.PopOnSelection = PopOnSelection; NavigationSource.NibName = NibName; NavigationSource.TableViewStyle = TableViewStyle; NavigationSource.IsSearchbarHidden = IsSearchbarHidden; NavigationSource.EnableSearch = EnableSearch; NavigationSource.IncrementalSearch = IncrementalSearch; NavigationSource.SearchPlaceholder = SearchPlaceholder; NavigationSource.SearchCommand = SearchCommand; NavigationSource.SelectedAccessoryViewType = SelectedAccessoryViewType; NavigationSource.UnselectedAccessoryViewType = UnselectedAccessoryViewType; NavigationSource.MemberData = new MemberData(MemberData.Source, MemberData.Member); if (NavigationSource.NavigationViewType != null) { var rowHeightAttribute = NavigationSource.NavigationViewType.GetCustomAttribute<RowHeightAttribute>(); if (rowHeightAttribute != null) { NavigationSource.MemberData.RowHeight = rowHeightAttribute.RowHeight; } } NavigationSource.Controller = dvc; dvc.TableView.Source = NavigationSource; Controller.NavigationController.PushViewController(dvc, true); }
public ComposableViewListCell(UITableViewCellStyle style, NSString reuseIdentifier, NSIndexPath indexPath, IList<Type> viewTypes, ListSource listSource) : base(style, reuseIdentifier) { Style = style; IndexPath = indexPath; ListSource = listSource; if (!ListSource.RowHeights.ContainsKey(ListSource.BaseIndexPath)) { ListSource.RowHeights.Add(ListSource.BaseIndexPath, ListSource.Controller.TableView.RowHeight); } _CompositeView = new UIView(Bounds); Theme = Theme.CreateTheme(listSource.Controller.Theme); if (ViewList == null) CreateViewList(viewTypes); AddSubview(_CompositeView); }
public override void Draw(RectangleF rect) { if (ListSource != null) { Theme.Cell = this; TextLabel.BackgroundColor = UIColor.Clear; if (DetailTextLabel != null) { DetailTextLabel.BackgroundColor = UIColor.Clear; } if (ListSource.IsRootCell) { Accessory = UITableViewCellAccessory.DisclosureIndicator; TextLabel.Text = ListSource.Caption; if (ListSource.IsMultiselect && DetailTextLabel != null) { DetailTextLabel.Text = ListSource.SelectedItems.Count.ToString(); } else { if (ListSource.SelectedItem != null) { if (ListSource.ReplaceCaptionWithSelection) { TextLabel.Text = ListSource.SelectedItem.ToString(); } else if (DetailTextLabel != null) { DetailTextLabel.Text = ListSource.SelectedItem.ToString(); } } } } else { var sectionData = ListSource.GetSectionData(0); if (sectionData.Count > 0 && IndexPath.Row < sectionData.Count) { TextLabel.Text = sectionData[IndexPath.Row].ToString(); } } } var resizedRows = false; if (ViewList != null) { foreach (var view in ViewList) { var sectionData = ListSource.GetSectionData(0); if (sectionData != null && sectionData.Count > 0) { var data = sectionData[IndexPath.Row]; var dc = view as IDataContext <object>; if (dc != null) { dc.DataContext = data; } if (dc == null) { var valueMember = view.GetType().GetProperty("Value"); if (valueMember != null && data.GetType().IsAssignableFrom(valueMember.PropertyType)) { valueMember.SetValue(view, data); } else { var dataContextMember = view.GetType().GetProperty("DataContext"); if (dataContextMember != null && data.GetType().IsAssignableFrom(dataContextMember.PropertyType)) { dataContextMember.SetValue(view, data); } } } var updateable = view as IUpdateable; if (updateable != null) { updateable.UpdateCell(this, IndexPath); } var rowHeight = 0f; var themeable = view as IThemeable; if (themeable != null) { themeable.ApplyTheme(this); if (themeable.Theme != null && themeable.Theme.CellHeight > 0) { rowHeight = themeable.Theme.CellHeight; } } var sizeable = view as ISizeable; if (sizeable != null) { rowHeight = sizeable.GetRowHeight(); } if (rowHeight > 0 && ListSource.RowHeights[ListSource.BaseIndexPath] != rowHeight) { if (ListSource.RowHeights.ContainsKey(IndexPath)) { if (ListSource.RowHeights[IndexPath] != rowHeight) { ListSource.RowHeights[IndexPath] = rowHeight; resizedRows = true; } } else { ListSource.RowHeights.Add(IndexPath, rowHeight); resizedRows = true; } } var customDraw = view as ICustomDraw; if (customDraw != null) { customDraw.Draw(rect); } } } if (resizedRows) { new Wait(TimeSpan.FromMilliseconds(0), () => { ListSource.Controller.TableView.BeginUpdates(); ListSource.Controller.TableView.EndUpdates(); }); } } }
protected void CreateViewList(IList <Type> viewTypes) { var frame = new RectangleF(0, 0, ContentView.Bounds.Width, ContentView.Bounds.Height); if (ViewList != null) { foreach (var view in ViewList) { view.Dispose(); } ViewList.Clear(); ViewList = null; } ViewList = new List <UIView>(); if (viewTypes != null) { foreach (var viewType in viewTypes) { if (viewType == null) { continue; } UIView view = null; var hasFrameCtor = viewType.GetConstructor(new Type[] { typeof(RectangleF) }) != null; if (hasFrameCtor) { view = Activator.CreateInstance(viewType, new object[] { frame }) as UIView; if (ListSource.RowHeights[ListSource.BaseIndexPath] != view.Frame.Height) { if (ListSource.RowHeights.ContainsKey(IndexPath)) { ListSource.RowHeights[IndexPath] = view.Frame.Height; } else { ListSource.RowHeights.Add(IndexPath, view.Frame.Height); } } } else { view = Activator.CreateInstance(viewType) as UIView; } var dc = view as IDataContext <object>; if (dc != null) { var item = ListSource.GetSectionData(0)[IndexPath.Row]; dc.DataContext = item; } var initializeCell = view as IInitializeCell; if (initializeCell != null) { initializeCell.Cell = this; initializeCell.Controller = ListSource.Controller; var newCellStyle = initializeCell.CellStyle; if (newCellStyle != Style) { Style = newCellStyle; break; } } var themeable = view as IThemeable; if (themeable != null) { if (themeable.Theme == null) { var theme = view.GetType().GetCustomAttribute <ThemeAttribute>(); if (theme != null) { var cellViewTheme = Theme.CreateTheme(theme.ThemeType); if (cellViewTheme != null) { if (Theme != null) { Theme.MergeTheme(cellViewTheme); } else { Theme = cellViewTheme; } themeable.Theme = Theme; } } } themeable.InitializeTheme(this); } var cellContent = view as ICellContent; if (cellContent != null) { if (cellContent.CellContentView != null) { _CompositeView.AddSubview(cellContent.CellContentView); } } ViewList.Add(view); } } }
public void NavigateToList() { var section = Sections[0]; var data = GetSectionData(0); if (string.IsNullOrEmpty(Caption)) { Caption = data.ToString(); } var dvc = new DialogViewController(Caption, null, Controller.Theme, true) { ToolbarButtons = null, NavbarButtons = null }; if (NavigationSource == null) { NavigationSource = new ListSource(dvc, data, section.ViewTypes[CellId]); } NavigationSource.SelectionAction = SelectionAction; NavigationSource.IsSelectable = (SelectionAction == SelectionAction.PopOnSelection || SelectionAction == SelectionAction.Selection || SelectionAction == SelectionAction.Multiselection); NavigationSource.NavigationViewType = null; var viewType = NavigationViewType; if (viewType == null && SelectionAction == SelectionAction.NavigateToView) { var genericType = data.GetType().GetGenericArguments().FirstOrDefault(); viewType = ViewContainer.GetView(genericType); } if (viewType != null) { NavigationSource.IsNavigable = viewType == typeof(ObjectCellView <object>); NavigationSource.NavigationViewType = viewType; } NavigationSource.IsNavigable = !PopOnSelection && NavigationSource.IsNavigable && SelectionAction != SelectionAction.Custom; NavigationSource.CellFactory = CellFactory; NavigationSource.SelectedItem = SelectedItem; NavigationSource.SelectedItems = SelectedItems; NavigationSource.UnselectionBehavior = UnselectionBehavior; NavigationSource.IsMultiselect = IsMultiselect; // NavigationSource.IsSelectable = IsSelectable; if (data.Count > 0 && (data[0].GetType().IsPrimitive || data[0].GetType().IsEnum)) { NavigationSource.IsSelectable = true; } NavigationSource.PopOnSelection = PopOnSelection; NavigationSource.NibName = NibName; NavigationSource.TableViewStyle = TableViewStyle; NavigationSource.IsSearchbarHidden = IsSearchbarHidden; NavigationSource.EnableSearch = EnableSearch; NavigationSource.IncrementalSearch = IncrementalSearch; NavigationSource.SearchPlaceholder = SearchPlaceholder; NavigationSource.SearchCommand = SearchCommand; NavigationSource.SelectedAccessoryViewType = SelectedAccessoryViewType; NavigationSource.UnselectedAccessoryViewType = UnselectedAccessoryViewType; NavigationSource.MemberData = new MemberData(MemberData.Source, MemberData.Member); if (NavigationSource.NavigationViewType != null) { var rowHeightAttribute = NavigationSource.NavigationViewType.GetCustomAttribute <RowHeightAttribute>(); if (rowHeightAttribute != null) { NavigationSource.MemberData.RowHeight = rowHeightAttribute.RowHeight; } } NavigationSource.Controller = dvc; dvc.TableView.Source = NavigationSource; Controller.NavigationController.PushViewController(dvc, true); }