internal void UpdateSnapBehavior(IItemsLayout iitemsLayout) { if (iitemsLayout is not ItemsLayout itemsLayout) { return; } var snapPointsType = itemsLayout.SnapPointsType; // Clear our the existing snap helper (if any) DetachSnapHelper(); if (snapPointsType == SnapPointsType.None) { return; } var alignment = itemsLayout.SnapPointsAlignment; // Create a new snap helper _snapHelper = CreateSnapHelper(snapPointsType, alignment); // And attach it to this RecyclerView _snapHelper.AttachToRecyclerView(_recyclerView); }
void SetUpNewElement(ItemsView newElement) { if (newElement == null) { return; } newElement.PropertyChanged += OnElementPropertyChanged; // TODO hartez 2018/06/06 20:49:14 Review whether we can just do this in the constructor if (Tracker == null) { Tracker = new VisualElementTracker(this); } this.EnsureId(); UpdateItemsSource(); _layout = newElement.ItemsLayout; SetLayoutManager(SelectLayoutManager(_layout)); UpdateSnapBehavior(); // Keep track of the ItemsLayout's property changes _layout.PropertyChanged += LayoutOnPropertyChanged; // TODO hartez 2018/09/17 13:16:12 This propertychanged handler needs to be torn down in Dispose and TearDownElement // Listen for ScrollTo requests newElement.ScrollToRequested += ScrollToRequested; }
public static T ItemsLayout <T>(this T structuredElement, IItemsLayout itemsLayout) where T : StructuredItemsView { structuredElement.ItemsLayout = itemsLayout; return(structuredElement); }
public CarouselSpacingItemDecoration(IItemsLayout itemsLayout) { var layout = itemsLayout ?? throw new ArgumentNullException(nameof(itemsLayout)); switch (layout) { case GridItemsLayout gridItemsLayout: _orientation = gridItemsLayout.Orientation; _horizontalSpacing = gridItemsLayout.HorizontalItemSpacing; _verticalSpacing = gridItemsLayout.VerticalItemSpacing; break; case ListItemsLayout listItemsLayout: _orientation = listItemsLayout.Orientation; if (_orientation == ItemsLayoutOrientation.Horizontal) { _horizontalSpacing = listItemsLayout.ItemSpacing; } else { _verticalSpacing = listItemsLayout.ItemSpacing; } break; } }
public TemplateCodeCollectionViewGallery(IItemsLayout itemsLayout) { var layout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Star } } }; var itemTemplate = ExampleTemplates.PhotoTemplate(); var collectionView = new CollectionView { ItemsLayout = itemsLayout, ItemTemplate = itemTemplate }; var generator = new ItemsSourceGenerator(collectionView, initialItems: 20); layout.Children.Add(generator); layout.Children.Add(collectionView); Grid.SetRow(collectionView, 1); Content = layout; generator.GenerateItems(); }
void SetUpNewElement(ItemsView newElement) { if (newElement == null) { return; } if (ListViewBase == null) { ListViewBase = SelectLayout(newElement.ItemsLayout); _layout = newElement.ItemsLayout; _layout.PropertyChanged += LayoutOnPropertyChanged; SetNativeControl(ListViewBase); } UpdateItemTemplate(); UpdateItemsSource(); UpdateVerticalScrollBarVisibility(); UpdateHorizontalScrollBarVisibility(); // Listen for ScrollTo requests newElement.ScrollToRequested += ScrollToRequested; }
protected virtual void SetUpNewElement(ItemsView newElement) { if (newElement == null) { return; } if (ListViewBase == null) { ListViewBase = SelectLayout(newElement.ItemsLayout); ListViewBase.IsSynchronizedWithCurrentItem = false; _layout = newElement.ItemsLayout; _layout.PropertyChanged += LayoutPropertyChanged; SetNativeControl(ListViewBase); } UpdateItemTemplate(); UpdateItemsSource(); UpdateHeader(); UpdateFooter(); UpdateVerticalScrollBarVisibility(); UpdateHorizontalScrollBarVisibility(); // Listen for ScrollTo requests newElement.ScrollToRequested += ScrollToRequested; }
public SpacingModifier(IItemsLayout itemsLayout, string buttonText) { ItemsLayout = itemsLayout; var layout = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.Fill }; var button = new Button { Text = buttonText, AutomationId = $"btn{buttonText}" }; var label = new Label { Text = LabelText, VerticalTextAlignment = TextAlignment.Center }; Entry = new Entry { Text = InitialEntryText, WidthRequest = 100, AutomationId = $"entry{buttonText}" }; layout.Children.Add(label); layout.Children.Add(Entry); layout.Children.Add(button); button.Clicked += ButtonOnClicked; Content = layout; }
public TextCodeCollectionViewGallery(IItemsLayout itemsLayout) { var layout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Star } } }; var collectionView = new CollectionView { ItemsLayout = itemsLayout, SelectionMode = SelectionMode.Single, AutomationId = "collectionview" }; var generator = new ItemsSourceGenerator(collectionView); layout.Children.Add(generator); layout.Children.Add(collectionView); Grid.SetRow(collectionView, 1); Content = layout; generator.GenerateItems(); }
public SpacingItemDecoration(IItemsLayout itemsLayout) { if (itemsLayout == null) { throw new ArgumentNullException(nameof(itemsLayout)); } switch (itemsLayout) { case GridItemsLayout gridItemsLayout: _orientation = gridItemsLayout.Orientation; _horizontalSpacing = gridItemsLayout.HorizontalItemSpacing; _verticalSpacing = gridItemsLayout.VerticalItemSpacing; _span = gridItemsLayout.Span; break; case ListItemsLayout listItemsLayout: _orientation = listItemsLayout.Orientation; if (_orientation == ItemsLayoutOrientation.Horizontal) { _horizontalSpacing = listItemsLayout.ItemSpacing; } else { _verticalSpacing = listItemsLayout.ItemSpacing; } break; } }
public SpacingGallery(IItemsLayout itemsLayout) { var layout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Star } } }; var instructions = new Label { Text = "Use the control below to update the spacing between items." }; if (itemsLayout is GridItemsLayout) { instructions.Text += " Format is '[vertical], [horizontal]'"; } var itemTemplate = ExampleTemplates.SpacingTemplate(); var collectionView = new CollectionView { ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, AutomationId = "collectionview", Margin = 10 }; var generator = new ItemsSourceGenerator(collectionView, initialItems: 20); var spacingModifier = new SpacingModifier(collectionView.ItemsLayout, "Update_Spacing"); layout.Children.Add(generator); layout.Children.Add(instructions); layout.Children.Add(spacingModifier); layout.Children.Add(collectionView); Grid.SetRow(instructions, 1); Grid.SetRow(spacingModifier, 2); Grid.SetRow(collectionView, 3); Content = layout; generator.GenerateItems(); }
protected override ItemsViewLayout SelectLayout(IItemsLayout layoutSpecification, ItemSizingStrategy itemSizingStrategy) { if (layoutSpecification is ListItemsLayout listItemsLayout) { return(new CarouselViewLayout(listItemsLayout, itemSizingStrategy, CarouselView)); } // Fall back to horizontal carousel return(new CarouselViewLayout(new ListItemsLayout(ItemsLayoutOrientation.Horizontal), itemSizingStrategy, CarouselView)); }
public ScrollToCodeGallery(IItemsLayout itemsLayout, ScrollToMode mode = ScrollToMode.Position, Func <DataTemplate> dataTemplate = null, Func <CollectionView> createCollectionView = null) { createCollectionView = createCollectionView ?? (() => new CollectionView()); Title = $"ScrollTo (Code, {itemsLayout})"; var layout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Star } } }; var itemTemplate = dataTemplate == null?ExampleTemplates.ScrollToIndexTemplate() : dataTemplate(); var collectionView = createCollectionView(); collectionView.ItemsLayout = itemsLayout; collectionView.ItemTemplate = itemTemplate; var generator = new ItemsSourceGenerator(collectionView, initialItems: 50); layout.Children.Add(generator); if (mode == ScrollToMode.Position) { var scrollToControl = new ScrollToIndexControl(collectionView); layout.Children.Add(scrollToControl); Grid.SetRow(scrollToControl, 1); } else { var scrollToControl = new ScrollToItemControl(collectionView); layout.Children.Add(scrollToControl); Grid.SetRow(scrollToControl, 1); } layout.Children.Add(collectionView); Grid.SetRow(collectionView, 2); Content = layout; generator.GenerateItems(); }
void SetupColletionViewLayout() { disableUpdates = true; var resetCV = cv; if (linearLayout == null && cv.ItemsLayout is LinearItemsLayout linear) { linearLayout = cv.ItemsLayout; linear.SnapPointsType = SnapPointsType.None; linear.SnapPointsAlignment = SnapPointsAlignment.Start; } if (gridLayout == null && cv.ItemsLayout is GridItemsLayout) { gridLayout = cv.ItemsLayout; } if (FormsWindow.IsLandscape) { if (cv.ItemsLayout != linearLayout) { resetCV.ItemsSource = null; resetCV.ItemsLayout = linearLayout; Content = null; } } else { if (cv.ItemsLayout != gridLayout) { resetCV.ItemsSource = null; resetCV.ItemsLayout = gridLayout; Content = null; } } if (Content == null) { Device.BeginInvokeOnMainThread(() => { Content = resetCV; resetCV.ItemsSource = Enumerable.Range(0, 1000) .Select(i => $"Page {i}") .ToList(); disableUpdates = false; }); } else { disableUpdates = false; } }
protected override void OnElementChanged(ElementChangedEventArgs <TItemsView> e) { if (Control == null) { SetNativeControl(CreateNativeControl(Forms.NativeParent)); } if (e.NewElement != null) { e.NewElement.ScrollToRequested += OnScrollToRequest; } base.OnElementChanged(e); ItemsLayout = GetItemsLayout(); UpdateAdaptor(false); }
protected void UpdateItemsLayout() { if (ItemsLayout != null) { ItemsLayout.PropertyChanged -= OnLayoutPropertyChanged; } ItemsLayout = GetItemsLayout(); if (ItemsLayout != null) { Control.LayoutManager = ItemsLayout.ToLayoutManager((Element as CollectionView)?.ItemSizingStrategy ?? ItemSizingStrategy.MeasureFirstItem); Control.SnapPointsType = ((ItemsLayout)ItemsLayout)?.SnapPointsType ?? SnapPointsType.None; ItemsLayout.PropertyChanged += OnLayoutPropertyChanged; } }
protected virtual ItemsViewLayout SelectLayout(IItemsLayout layoutSpecification) { if (layoutSpecification is GridItemsLayout gridItemsLayout) { return(new GridViewLayout(gridItemsLayout)); } if (layoutSpecification is ListItemsLayout listItemsLayout) { return(new ListViewLayout(listItemsLayout)); } // Fall back to vertical list return(new ListViewLayout(new ListItemsLayout(ItemsLayoutOrientation.Vertical))); }
protected virtual ListViewBase SelectLayout(IItemsLayout layoutSpecification) { switch (layoutSpecification) { case GridItemsLayout gridItemsLayout: return(CreateGridView(gridItemsLayout)); case ListItemsLayout listItemsLayout when listItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal: return(CreateHorizontalListView()); } // Default to a plain old vertical ListView return(new Windows.UI.Xaml.Controls.ListView()); }
protected override void Dispose(bool disposing) { if (disposing) { if (_itemDecoration != null) { _itemDecoration.Dispose(); _itemDecoration = null; } _layout = null; } base.Dispose(disposing); }
public static ICollectionViewLayoutManager ToLayoutManager(this IItemsLayout layout) { switch (layout) { case ListItemsLayout listItemsLayout: return(new LinearLayoutManager(listItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)); case GridItemsLayout gridItemsLayout: return(new GridLayoutManager(gridItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal, gridItemsLayout.Span)); default: break; } return(new LinearLayoutManager(false)); }
public static ICollectionViewLayoutManager ToLayoutManager(this IItemsLayout layout, ItemSizingStrategy sizing = ItemSizingStrategy.MeasureFirstItem) { switch (layout) { case LinearItemsLayout listItemsLayout: return(new LinearLayoutManager(listItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal, sizing)); case GridItemsLayout gridItemsLayout: return(new GridLayoutManager(gridItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal, gridItemsLayout.Span, sizing)); default: break; } return(new LinearLayoutManager(false)); }
protected override LayoutManager SelectLayoutManager(IItemsLayout layoutSpecification) { if (layoutSpecification is StaggeredGridItemsLayout staggeredGridLayout) { var manager = new StaggeredGridLayoutManager(staggeredGridLayout.Span, staggeredGridLayout.Orientation == ItemsLayoutOrientation.Horizontal ? LinearLayoutManager.Horizontal : LinearLayoutManager.Vertical); manager.GapStrategy = StaggeredGridLayoutManager.GapHandlingNone; return(manager); } return(base.SelectLayoutManager(layoutSpecification)); }
public SpacingItemDecoration(Context context, IItemsLayout itemsLayout) { // The original "SpacingItemDecoration" applied spacing based on an item's current span index. // It did not apply any spacing to items currently at span index 0 which can create an issue for us with grid layouts. // If one of those items at span index 0 were to move to another column, it would result in misaligned items. // It's better to just apply equal spacing to all items so we can avoid that issue (even the ones at span index 0). // The reason they didn't do this originally, I suspect, is that they didn't want spacing around the edge of the RecyclerView. // That however can be corrected by adjusting the padding on the RecyclerView which we are now doing. if (itemsLayout == null) { throw new ArgumentNullException(nameof(itemsLayout)); } double horizontalOffset; double verticalOffset; switch (itemsLayout) { case GridItemsLayout gridItemsLayout: horizontalOffset = gridItemsLayout.HorizontalItemSpacing / 2.0; verticalOffset = gridItemsLayout.VerticalItemSpacing / 2.0; break; case LinearItemsLayout listItemsLayout: if (listItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal) { horizontalOffset = listItemsLayout.ItemSpacing / 2.0; verticalOffset = 0; } else { horizontalOffset = 0; verticalOffset = listItemsLayout.ItemSpacing / 2.0; } break; default: horizontalOffset = 0; verticalOffset = 0; break; } HorizontalOffset = (int)context.ToPixels(horizontalOffset); VerticalOffset = (int)context.ToPixels(verticalOffset); }
protected override void SetUpNewElement(ItemsView newElement) { base.SetUpNewElement(newElement); if (newElement == null) { Carousel = null; return; } Carousel = newElement as CarouselView; _layout = ItemsView.ItemsLayout; UpdateIsSwipeEnabled(); UpdateInitialPosition(); UpdateItemSpacing(); }
void TearDownOldElement(ItemsView oldElement) { if (oldElement == null) { return; } if (_layout != null) { // Stop tracking the old layout _layout.PropertyChanged -= LayoutOnPropertyChanged; _layout = null; } // Stop listening for ScrollTo requests oldElement.ScrollToRequested -= ScrollToRequested; }
public DynamicItemSizeGallery(IItemsLayout itemsLayout) { var layout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Star } } }; var instructions = new Label { Text = "Tap the buttons in each item to increase/decrease the amount of text. The items should expand and contract to accommodate the text." }; var itemTemplate = ExampleTemplates.DynamicTextTemplate(); var collectionView = new CollectionView { ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, AutomationId = "collectionview" }; var generator = new ItemsSourceGenerator(collectionView, initialItems: 20); layout.Children.Add(generator); layout.Children.Add(instructions); layout.Children.Add(collectionView); Grid.SetRow(instructions, 1); Grid.SetRow(collectionView, 2); Content = layout; generator.GenerateItems(); }
protected virtual void SetUpNewElement(TItemsView newElement) { if (newElement == null) { ItemsView = null; return; } ItemsView = newElement; ItemsView.PropertyChanged += OnElementPropertyChanged; // TODO hartez 2018/06/06 20:49:14 Review whether we can just do this in the constructor if (Tracker == null) { Tracker = new VisualElementTracker(this); } this.EnsureId(); UpdateItemsSource(); _layout = GetItemsLayout(); SetLayoutManager(SelectLayoutManager(_layout)); UpdateSnapBehavior(); UpdateBackgroundColor(); UpdateFlowDirection(); UpdateItemSpacing(); UpdateHorizontalScrollBarVisibility(); UpdateVerticalScrollBarVisibility(); // Keep track of the ItemsLayout's property changes if (_layout != null) { _layout.PropertyChanged += LayoutPropertyChanged; } // Listen for ScrollTo requests ItemsView.ScrollToRequested += ScrollToRequested; _recyclerViewScrollListener = new RecyclerViewScrollListener <TItemsView, TItemsViewSource>(ItemsView, ItemsViewAdapter); AddOnScrollListener(_recyclerViewScrollListener); }
void SetUpNewElement(CollectionView newElement) { if (newElement == null) { return; } _layout = newElement.ItemsLayout; _flowLayout = SelectLayout(_layout); _collectionViewController = new CollectionViewController(newElement, _flowLayout); SetNativeControl(_collectionViewController.View); _collectionViewController.CollectionView.BackgroundColor = UIColor.Clear; _collectionViewController.CollectionView.WeakDelegate = _flowLayout; _collectionViewController.UpdateEmptyView(); // Listen for ScrollTo requests newElement.ScrollToRequested += ScrollToRequested; }
protected virtual LayoutManager SelectLayoutManager(IItemsLayout layoutSpecification) { switch (layoutSpecification) { case GridItemsLayout gridItemsLayout: return CreateGridLayout(gridItemsLayout); case LinearItemsLayout listItemsLayout: var orientation = listItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal ? LinearLayoutManager.Horizontal : LinearLayoutManager.Vertical; return new LinearLayoutManager(Context, orientation, false); } // Fall back to plain old vertical list // TODO hartez 2018/08/30 19:34:36 Log a warning when we have to fall back because of an unknown layout return new LinearLayoutManager(Context); }
public virtual void UpdateLayoutManager() { if (ItemsLayout != null) { ItemsLayout.PropertyChanged -= LayoutPropertyChanged; } ItemsLayout = GetItemsLayout(); // Keep track of the ItemsLayout's property changes if (ItemsLayout != null) { ItemsLayout.PropertyChanged += LayoutPropertyChanged; } SetLayoutManager(SelectLayoutManager(ItemsLayout)); UpdateFlowDirection(); UpdateItemSpacing(); }