public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); if (model.RowsInSection(0) > PlaybackManager.Shared.CurrentSongIndex) { TableView.ScrollToRow(NSIndexPath.FromItemSection(PlaybackManager.Shared.CurrentSongIndex, 0), UITableViewScrollPosition.Top, true); } }
private NSIndexPath[] GetIndexesWithSection(NSIndexSet indexes, nint section) { var indexPaths = new List <NSIndexPath>(); indexes.EnumerateIndexes((nuint idx, ref bool stop) => { indexPaths.Add(NSIndexPath.FromItemSection((nint)idx, section)); }); return(indexPaths.ToArray()); }
void HandleCurrentSongChanged(object sender, EventArgs <Song> e) { TableView.ReloadData(); if (model.RowsInSection(0) > PlaybackManager.Shared.CurrentSongIndex) { TableView.ScrollToRow(NSIndexPath.FromItemSection(PlaybackManager.Shared.CurrentSongIndex, 0), UITableViewScrollPosition.Top, true); } }
internal NSIndexPath GetScrollToIndexPath(int position) { if (Carousel?.Loop == true && _carouselViewLoopManager != null) { return(_carouselViewLoopManager.GetGoToIndex(CollectionView, position)); } return(NSIndexPath.FromItemSection(position, 0)); }
private NSIndexPath[] GetPaths(int section, int index, int count) { NSIndexPath[] nsIndexPathArray = new NSIndexPath[count]; for (int index1 = 0; index1 < nsIndexPathArray.Length; ++index1) { nsIndexPathArray [index1] = NSIndexPath.FromItemSection(index + index1, section); } return(nsIndexPathArray); }
public virtual void ScrollCollectionViewToInitialPosition() { if (IsFirstAppearance) { var indexPath = NSIndexPath.FromItemSection(this.PhotoKitAssetList.Count - 1, 0); this.ScrollCollectionView(indexPath); IsFirstAppearance = false; } }
public void MoveFromIndex(int fromIndex, int toIndex, nfloat progressPercentage, PagerScroll pagerScroll) { selectedIndex = progressPercentage > 0.5 ? toIndex : fromIndex; CGRect fromFrame = GetLayoutAttributesForItem(NSIndexPath.FromItemSection(fromIndex, 0)).Frame; var numberOfItems = DataSource.GetItemsCount(this, 0); CGRect toFrame; if (toIndex < 0 || toIndex > numberOfItems - 1) { if (toIndex < 0) { var cellAtts = GetLayoutAttributesForItem(NSIndexPath.FromItemSection(0, 0)); toFrame = CGRect.Inflate(cellAtts.Frame, -cellAtts.Frame.Size.Width, 0); } else { var cellAtts = GetLayoutAttributesForItem(NSIndexPath.FromItemSection((numberOfItems - 1), 0)); toFrame = CGRect.Inflate(cellAtts.Frame, cellAtts.Frame.Size.Width, 0); } } else { toFrame = GetLayoutAttributesForItem(NSIndexPath.FromItemSection(toIndex, 0)).Frame; } CGRect targetFrame = fromFrame; if (this.SelectedBarWidth.HasValue) { targetFrame.Size = new CGSize(this.SelectedBarWidth.Value, SelectedBar.Frame.Size.Height); targetFrame.X = fromFrame.X + (fromFrame.Width - this.SelectedBarWidth.Value) / 2; targetFrame.X += (toFrame.X + (toFrame.Width - this.SelectedBarWidth.Value) / 2 - targetFrame.X) * progressPercentage; } else { var targetWidth = targetFrame.Size.Width + (toFrame.Size.Width - fromFrame.Size.Width) * progressPercentage; targetFrame.Size = new CGSize(targetWidth, SelectedBar.Frame.Size.Height); targetFrame.X += (toFrame.X - fromFrame.X) * progressPercentage; } SelectedBar.Frame = new CGRect(targetFrame.X, SelectedBar.Frame.Y, targetFrame.Size.Width, SelectedBar.Frame.Size.Height); nfloat targetContentOffset = 0.0f; if (ContentSize.Width > Frame.Size.Width) { var toContentOffset = ContentOffsetForCell(toFrame, toIndex); var fromContentOffset = ContentOffsetForCell(fromFrame, fromIndex); targetContentOffset = fromContentOffset + ((toContentOffset - fromContentOffset) * progressPercentage); } SetContentOffset(new CGPoint(targetContentOffset, 0), animated: false); }
private NSIndexPath IndexPathForItem(object item) { var index = IndexFromItem(item); if (index < 0) { return(null); } return(NSIndexPath.FromItemSection(index, 0)); }
protected static NSIndexPath[] CreateNSIndexPathArray(int startingPosition, int count) { var newIndexPaths = new NSIndexPath[count]; for (var i = 0; i < count; i++) { newIndexPaths[i] = NSIndexPath.FromItemSection(i + startingPosition, 0); } return(newIndexPaths); }
void AddTouched(object sender, EventArgs e) { this.AddItem(); // >> listview-insert-item-cs this.listView.InsertItems(new NSIndexPath[] { NSIndexPath.FromItemSection((nint)(this.items.Count - 1), 0) }); // << listview-insert-item-cs this.listView.SelectItem(NSIndexPath.FromItemSection(this.dataSource.Items.Length - 1, 0), false, UICollectionViewScrollPosition.CenteredVertically); }
private static void performChangesetUpdates <TSection, THeader, TModel, TKey>( this UITableView tableView, Diffing <TSection, THeader, TModel, TKey> .Changeset changes) where TKey : IEquatable <TKey> where TSection : IAnimatableSectionModel <THeader, TModel, TKey>, new() where TModel : IDiffable <TKey>, IEquatable <TModel> where THeader : IDiffable <TKey> { NSIndexSet newIndexSet(List <int> indexes) { var indexSet = new NSMutableIndexSet(); foreach (var i in indexes) { indexSet.Add((nuint)i); } return(indexSet as NSIndexSet); } tableView.DeleteSections(newIndexSet(changes.DeletedSections), UITableViewRowAnimation.Fade); // Updated sections doesn't mean reload entire section, somebody needs to update the section view manually // otherwise all cells will be reloaded for nothing. tableView.InsertSections(newIndexSet(changes.InsertedSections), UITableViewRowAnimation.Fade); foreach (var(from, to) in changes.MovedSections) { tableView.MoveSection(from, to); } tableView.DeleteRows( changes.DeletedItems.Select(item => NSIndexPath.FromRowSection(item.itemIndex, item.sectionIndex)).ToArray(), UITableViewRowAnimation.Top ); tableView.InsertRows( changes.InsertedItems.Select(item => NSIndexPath.FromItemSection(item.itemIndex, item.sectionIndex)).ToArray(), UITableViewRowAnimation.Automatic ); tableView.ReloadRows( changes.UpdatedItems.Select(item => NSIndexPath.FromRowSection(item.itemIndex, item.sectionIndex)) .ToArray(), // No animation so it doesn't fade showing the cells behind it UITableViewRowAnimation.None ); foreach (var(from, to) in changes.MovedItems) { tableView.MoveRow( NSIndexPath.FromRowSection(from.itemIndex, from.sectionIndex), NSIndexPath.FromRowSection(to.itemIndex, to.sectionIndex) ); } }
private void onCollectionChanges() { calendarItems = collection.IsEmpty ? new List <CalendarItem>() : collection[0].ToList(); layoutAttributes = calculateLayoutAttributes(); var index = calendarItems.IndexOf(item => item.Duration == null); runningTimeEntryIndexPath = index >= 0 ? NSIndexPath.FromItemSection(index, 0) : null; CollectionView.ReloadData(); }
public override void ViewDidLayoutSubviews() { base.ViewDidLayoutSubviews(); this.View.LayoutIfNeeded(); var mostRecentCompetition = competitions.Where(c => c.Date <= DateTime.Now).LastOrDefault(); int mostRecentCompetationIndex = competitions.IndexOf(mostRecentCompetition); competitionCollectionView.ScrollToItem(NSIndexPath.FromItemSection(mostRecentCompetationIndex, 0), UICollectionViewScrollPosition.Top, false); }
public override UICollectionViewLayoutAttributes LayoutAttributesForItem(NSIndexPath indexPath) { var currentItemAttributes = base.LayoutAttributesForItem(indexPath); var collectionViewFlowLayout = CollectionView.CollectionViewLayout as UICollectionViewFlowLayout; if (collectionViewFlowLayout != null) { var sectionInset = collectionViewFlowLayout.SectionInset; if (indexPath.Item == 0) { // first item of section var frame = currentItemAttributes.Frame; frame.X = sectionInset.Left; // first item of the section should always be left aligned currentItemAttributes.Frame = frame; return(currentItemAttributes); } var previousIndexPath = NSIndexPath.FromItemSection(indexPath.Item - 1, indexPath.Section); var previousFrame = base.LayoutAttributesForItem(previousIndexPath).Frame; previousFrame.X = base.LayoutAttributesForItem(previousIndexPath).Frame.Left; if (previousFrame.X != base.LayoutAttributesForItem(previousIndexPath).Frame.Left) { var n = base.LayoutAttributesForItem(previousIndexPath).Frame.Left; previousFrame.X = n; maxCellSpacing = 0; } var previousFrameRightPoint = (previousFrame.X) + (previousFrame.Size.Width) + maxCellSpacing; var currentFrame = currentItemAttributes.Frame; var width = 0.0; var collectionViewWidth = CollectionView == null ? 0 : CollectionView.Frame.Size.Width; width = collectionViewWidth; var strecthedCurrentFrame = new CGRect(0, currentFrame.Y, width, currentFrame.Size.Height); if (CGRect.Intersect(previousFrame, strecthedCurrentFrame) == CGRect.Empty) { // if current item is the first item on the line // the approach here is to take the current frame, left align it to the edge of the view // then stretch it the width of the collection view, if it intersects with the previous frame then that means it // is on the same line, otherwise it is on it's own new line var frame = currentItemAttributes.Frame; frame.X = sectionInset.Left; // first item on the line should always be left aligned currentItemAttributes.Frame = frame; return(currentItemAttributes); } var frame2 = currentItemAttributes.Frame; frame2.X = previousFrameRightPoint; currentItemAttributes.Frame = frame2; } return(currentItemAttributes); }
public void addItem(ModelItem item) { NSIndexPath lastCellIndexPath = NSIndexPath.FromItemSection(this.boundCollectionView.NumberOfItemsInSection(0), 0); this.items.Add(item); if (this.boundCollectionView.DataSource != null) { this.boundCollectionView.InsertItems(new NSIndexPath[] { lastCellIndexPath }); } }
public static NSIndexPath[] GetIndexPaths(this NSIndexSet indexSet, int section) { var indexPaths = new NSIndexPath [indexSet.Count]; for (int i = 0; i < indexPaths.Length; i++) { indexPaths [i] = NSIndexPath.FromItemSection(i, section); } return(indexPaths); }
void ScrollChatToBottom(bool animated = true) { try { chatCollectionView.ScrollToItem(NSIndexPath.FromItemSection(ViewModel.ChatMessages.Count - 1, 0), UICollectionViewScrollPosition.Bottom, animated); } catch (Exception e) { Console.WriteLine(e); } }
public void UpdateIndicator(PagerTabStripViewController viewController, nint fromIndex, nint toIndex, nfloat progressPercentage, bool indexWasChanged) { if (!ShouldUpdateButtonBarView) return; ButtonBarView.Move(fromIndex, toIndex, progressPercentage, PagerScroll.Yes); if (ChangeCurrentIndexProgressive != null) { var oldCell = ButtonBarView.CellForItem(NSIndexPath.FromItemSection(CurrentIndex != fromIndex ? fromIndex : toIndex, 0)) as ButtonBarViewCell; var newCell = ButtonBarView.CellForItem(NSIndexPath.FromItemSection(CurrentIndex, 0)) as ButtonBarViewCell; ChangeCurrentIndexProgressive(oldCell, newCell, progressPercentage, indexWasChanged, true); } }
public override void RowSelected(UITableView tableView, NSIndexPath indexPath) { tableView.DeselectRow(indexPath, true); for (int i = 0; i < tableView.NumberOfRowsInSection(0); i++) { UITableViewCell cell = tableView.CellAt(NSIndexPath.FromItemSection(i, 0)); var field = StringsResources.MenuFields().Find((obj) => obj.Row == i); if (field.Type == FieldType.MenuItemSocial || field.Type == FieldType.Header) { continue; } if (cell != null) { if (cell?.TextLabel?.TextColor != Colors.White) { SetCellColor(cell, Colors.White); } } } var cellAtIndex = tableView.CellAt(indexPath); SetCellColor(cellAtIndex, Colors.Color4); var item = StringsResources.MenuFields().Find((obj) => obj.Row == indexPath.Row); var type = (MenuType)Enum.ToObject(typeof(MenuType), item.ActionType); switch (type) { case MenuType.Home: _viewModel.ShowHomeCommand.Execute(); break; case MenuType.HelpAndFeedback: _viewModel.ShowHelpCommand.Execute(); break; case MenuType.Button: break; case MenuType.Settings: _viewModel.ShowSettingCommand.Execute(); break; case MenuType.Logout: _viewModel.ShowLoginCommand.Execute(); break; } _selectedIndex = indexPath; }
NSIndexPath GetFirstVisibleItemIndexPath() { for (int i = 0; i < toolboxWidget.CategoryVisibilities.Count; i++) { if (toolboxWidget.CategoryVisibilities [i].Items.Count > 0) { return(NSIndexPath.FromItemSection(0, i)); } } return(null); }
internal CGSize GetReferenceSizeForFooter(UICollectionView collectionView, UICollectionViewLayout layout, nint section) { if (!_isGrouped) { return(CGSize.Empty); } var cell = GetViewForSupplementaryElement(collectionView, UICollectionElementKindSectionKey.Footer, NSIndexPath.FromItemSection(0, section)) as ItemsViewCell; return(cell.Measure()); }
public void SetMovies(List <MovieViewModel> Movies) { InvokeOnMainThread(() => { var paths = Movies.Select(s => NSIndexPath.FromItemSection(Movies.IndexOf(s) + this.Movies.Count, 0)).ToArray(); this.Movies.AddRange(Movies); collectionView.PerformBatchUpdates(delegate { collectionView.InsertItems(paths); }, null); IsLoading = false; }); }
void SetCurrentItem(int carouselPosition) { if (ItemsSource.ItemCount == 0) { return; } var item = GetItemAtIndex(NSIndexPath.FromItemSection(carouselPosition, 0)); Carousel.SetValueFromRenderer(CarouselView.CurrentItemProperty, item); UpdateVisualStates(); }
public NSIndexPath IndexOfTag(string tag) { var index = _presenter != null ? _presenter.FindIndex(t => t.Name == tag) : _tagPickerFacade.IndexOf(tag); if (index == -1) { return(null); } return(NSIndexPath.FromItemSection(index, 0)); }
private void AddTag(string txt) { if (!_collectionviewSource.LocalTags.Contains(txt)) { localTagsHeight.Constant = 50; localTagsTopSpace.Constant = 15; _collectionviewSource.LocalTags.Add(txt); _collectionViewDelegate.GenerateVariables(); tagsCollectionView.ReloadData(); tagsCollectionView.ScrollToItem(NSIndexPath.FromItemSection(_collectionviewSource.LocalTags.Count - 1, 0), UICollectionViewScrollPosition.Right, true); } }
private void RemoveAllAccessories(UITableView tableView, int section) { for (var i = 0; i < tableView.NumberOfRowsInSection(section); i++) { var rowPath = NSIndexPath.FromItemSection(i, section); var cell = tableView.CellAt(rowPath); if (cell != null) { cell.Accessory = UITableViewCellAccessory.None; } } }
// return layout attributes for all the items in a given rectangle public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(RectangleF rect) { UICollectionViewLayoutAttributes[] attributes = new UICollectionViewLayoutAttributes [count]; for (int i = 0; i < count; i++) { NSIndexPath indexPath = NSIndexPath.FromItemSection(i, 0); attributes [i] = LayoutAttributesForItem(indexPath); } return(attributes); }
public void PhotoLibraryDidChange(PHChange changeInstance) { var changes = changeInstance.GetFetchResultChangeDetails(FetchResult); if (changes == null) { return; } DispatchQueue.MainQueue.DispatchSync(() => { // Hang on to the new fetch result. FetchResult = changes.FetchResultAfterChanges; if (changes.HasIncrementalChanges) { // If we have incremental diffs, animate them in the collection view. CollectionView.PerformBatchUpdates(() => { // For indexes to make sense, updates must be in this order: // delete, insert, reload, move var removed = changes.RemovedIndexes; if (removed != null && removed.Count > 0) { CollectionView.DeleteItems(ToNSIndexPaths(removed)); } var inserted = changes.InsertedIndexes; if (inserted != null && inserted.Count > 0) { CollectionView.InsertItems(ToNSIndexPaths(inserted)); } var changed = changes.ChangedIndexes; if (changed != null && changed.Count > 0) { CollectionView.ReloadItems(ToNSIndexPaths(changed)); } changes.EnumerateMoves((fromIndex, toIndex) => { var start = NSIndexPath.FromItemSection((nint)fromIndex, 0); var end = NSIndexPath.FromItemSection((nint)toIndex, 0); CollectionView.MoveItem(start, end); }); }, null); } else { // Reload the collection view if incremental diffs are not available. CollectionView.ReloadData(); } ResetCachedAssets(); }); }
internal CGSize GetReferenceSizeForheaderOrFooter(UICollectionView collectionView, DataTemplate template, NSString elementKind, nint section) { if (!_isGrouped || template == null) { return(CGSize.Empty); } var cell = GetViewForSupplementaryElement(collectionView, elementKind, NSIndexPath.FromItemSection(0, section)) as ItemsViewCell; return(cell.Measure()); }
static NSIndexPath [] ToNSIndexPaths(NSIndexSet indexSet) { var cnt = indexSet.Count; var result = new NSIndexPath [(int)cnt]; int i = 0; indexSet.EnumerateIndexes((nuint idx, ref bool stop) => { stop = false; result [i++] = NSIndexPath.FromItemSection((nint)idx, 0); }); return(result); }