protected void UpdateSubview(object view, DataTemplate viewTemplate, ref UIView uiView, ref VisualElement formsElement) { if (uiView != null) { CollectionView.Subviews.Remove(uiView); } if (formsElement != null) { ItemsView.RemoveLogicalChild(formsElement); formsElement.MeasureInvalidated -= OnFormsElementMeasureInvalidated; } UpdateView(view, viewTemplate, ref uiView, ref formsElement); if (uiView != null) { CollectionView.AddSubview(uiView); } if (formsElement != null) { ItemsView.AddLogicalChild(formsElement); } if (formsElement != null) { RemeasureLayout(formsElement); formsElement.MeasureInvalidated += OnFormsElementMeasureInvalidated; } else if (uiView != null) { uiView.SizeToFit(); } }
internal void UpdateSubview(object view, DataTemplate viewTemplate, nint viewTag, ref UIView uiView, ref VisualElement formsElement) { uiView?.RemoveFromSuperview(); if (formsElement != null) { ItemsView.RemoveLogicalChild(formsElement); formsElement.MeasureInvalidated -= OnFormsElementMeasureInvalidated; } UpdateView(view, viewTemplate, ref uiView, ref formsElement); if (uiView != null) { uiView.Tag = viewTag; CollectionView.AddSubview(uiView); } if (formsElement != null) { ItemsView.AddLogicalChild(formsElement); } if (formsElement != null) { RemeasureLayout(formsElement); formsElement.MeasureInvalidated += OnFormsElementMeasureInvalidated; } else if (uiView != null) { uiView.SizeToFit(); } }
public void Recycle(ItemsView itemsView) { if (_itemView is SizedItemContentView _sizedItemContentView) { _sizedItemContentView.Recycle(); } itemsView.RemoveLogicalChild(View); }
public override void OnViewRecycled(Object holder) { if (holder is TemplatedItemViewHolder templatedItemViewHolder) { ItemsView.RemoveLogicalChild(templatedItemViewHolder.View); } base.OnViewRecycled(holder); }
void ResetBindedView(View view) { if (view.BindingContext != null && _dataBindedViewTable.ContainsKey(view.BindingContext)) { _dataBindedViewTable[view.BindingContext] = null; _itemsView.RemoveLogicalChild(view); view.BindingContext = null; } }
public void Bind(DataTemplate template, object bindingContext, ItemsView itemsView) { var oldElement = VisualElementRenderer?.Element; // Run this through the extension method in case it's really a DataTemplateSelector var itemTemplate = template.SelectDataTemplate(bindingContext, itemsView); if (itemTemplate != _currentTemplate) { // Remove the old view, if it exists if (oldElement != null) { oldElement.MeasureInvalidated -= MeasureInvalidated; itemsView.RemoveLogicalChild(oldElement); ClearSubviews(); _size = Size.Zero; } // Create the content and renderer for the view var view = itemTemplate.CreateContent() as View; // Prevents the use of default color when there are VisualStateManager with Selected state setting the background color // First we check whether the cell has the default selected background color; if it does, then we should check // to see if the cell content is the VSM to set a selected color if (SelectedBackgroundView.BackgroundColor == ColorExtensions.Gray && IsUsingVSMForSelectionColor(view)) { SelectedBackgroundView = new UIView { BackgroundColor = UIColor.Clear }; } // Set the binding context _before_ we create the renderer; that way, it's available during OnElementChanged view.BindingContext = bindingContext; var renderer = TemplateHelpers.CreateRenderer(view); SetRenderer(renderer); // And make the new Element a "child" of the ItemsView // We deliberately do this _after_ setting the binding context for the new element; // if we do it before, the element briefly inherits the ItemsView's bindingcontext and we // emit a bunch of needless binding errors itemsView.AddLogicalChild(view); } else { // Same template, different data var currentElement = VisualElementRenderer?.Element; if (currentElement != null) { currentElement.BindingContext = bindingContext; } } _currentTemplate = itemTemplate; }
void TearDownEmptyView() { HideEmptyView(); // RemoveLogicalChild will trigger a disposal of the native view and its content ItemsView.RemoveLogicalChild(_emptyViewFormsElement); _emptyUIView = null; _emptyViewFormsElement = null; }
public void Recycle(ItemsView itemsView) { if (View == null) { return; } itemsView.RemoveLogicalChild(View); View.BindingContext = null; }
internal void RemoveLogicalChild(UICollectionViewCell cell) { if (cell is TemplatedCell templatedCell) { var oldView = templatedCell.VisualElementRenderer?.Element; if (oldView != null) { _itemsView.RemoveLogicalChild(oldView); } } }
internal void PrepareCellForRemoval(UICollectionViewCell cell) { if (cell is TemplatedCell templatedCell) { templatedCell.ContentSizeChanged -= CellContentSizeChanged; var oldView = templatedCell.VisualElementRenderer?.Element; if (oldView != null) { oldView.BindingContext = null; ItemsView.RemoveLogicalChild(oldView); } templatedCell.PrepareForRemoval(); } }
protected virtual void UpdateEmptyViewVisibility() { bool isEmpty = (CollectionViewSource?.View?.Count ?? 0) == 0; if (isEmpty) { if (_formsEmptyView != null) { if (_emptyViewDisplayed) { ItemsView.RemoveLogicalChild(_formsEmptyView); } if (ItemsView.EmptyViewTemplate == null) { ItemsView.AddLogicalChild(_formsEmptyView); } } if (_emptyView != null && ListViewBase is IEmptyView emptyView) { emptyView.EmptyViewVisibility = WVisibility.Visible; if (ActualWidth >= 0 && ActualHeight >= 0) { _formsEmptyView?.Layout(new Rect(0, 0, ActualWidth, ActualHeight)); } } _emptyViewDisplayed = true; } else { if (_emptyViewDisplayed) { if (_emptyView != null && ListViewBase is IEmptyView emptyView) { emptyView.EmptyViewVisibility = WVisibility.Collapsed; } ItemsView.RemoveLogicalChild(_formsEmptyView); } _emptyViewDisplayed = false; } }
public void Bind(DataTemplate template, object bindingContext, ItemsView itemsView) { var oldElement = VisualElementRenderer?.Element; // Run this through the extension method in case it's really a DataTemplateSelector var itemTemplate = template.SelectDataTemplate(bindingContext, itemsView); if (itemTemplate != _currentTemplate) { // Remove the old view, if it exists if (oldElement != null) { oldElement.MeasureInvalidated -= MeasureInvalidated; itemsView.RemoveLogicalChild(oldElement); ClearSubviews(); _size = Size.Zero; } // Create the content and renderer for the view var view = itemTemplate.CreateContent() as View; // Set the binding context _before_ we create the renderer; that way, it's available during OnElementChanged view.BindingContext = bindingContext; var renderer = TemplateHelpers.CreateRenderer(view); SetRenderer(renderer); // And make the new Element a "child" of the ItemsView // We deliberately do this _after_ setting the binding context for the new element; // if we do it before, the element briefly inherits the ItemsView's bindingcontext and we // emit a bunch of needless binding errors itemsView.AddLogicalChild(view); } else { // Same template, different data var currentElement = VisualElementRenderer?.Element; if (currentElement != null) { currentElement.BindingContext = bindingContext; } } _currentTemplate = itemTemplate; }
void UpdateEmptyViewVisibility(bool isEmpty) { if (isEmpty && _emptyUIView != null) { var emptyView = CollectionView.ViewWithTag(EmptyTag); if (emptyView != null) { emptyView.RemoveFromSuperview(); ItemsView.RemoveLogicalChild(_emptyViewFormsElement); } _emptyUIView.Tag = EmptyTag; CollectionView.AddSubview(_emptyUIView); LayoutEmptyView(); if (_emptyViewFormsElement != null) { if (ItemsView.EmptyViewTemplate == null) { ItemsView.AddLogicalChild(_emptyViewFormsElement); } // Now that the native empty view's frame is sized to the UICollectionView, we need to handle // the Forms layout for its content _emptyViewFormsElement.Layout(_emptyUIView.Frame.ToRectangle()); } _emptyViewDisplayed = true; } else { // Is the empty view currently in the background? Swap back to the default. if (_emptyViewDisplayed) { _emptyUIView.RemoveFromSuperview(); _emptyUIView.Dispose(); _emptyUIView = null; ItemsView.RemoveLogicalChild(_emptyViewFormsElement); } _emptyViewDisplayed = false; } }
void UpdateEmptyViewVisibility(bool isEmpty) { if (isEmpty && _emptyUIView != null) { if (!_currentBackgroundIsEmptyView) { // Cache any existing background view so we can restore it later _backgroundUIView = CollectionView.BackgroundView; } // Replace any current background with the EmptyView. This will also set the native empty view's frame // to match the UICollectionView's frame CollectionView.BackgroundView = _emptyUIView; if (_emptyViewFormsElement != null) { if (ItemsView.EmptyViewTemplate == null) { ItemsView.AddLogicalChild(_emptyViewFormsElement); } // Now that the native empty view's frame is sized to the UICollectionView, we need to handle // the Forms layout for its content _emptyViewFormsElement.Layout(_emptyUIView.Frame.ToRectangle()); } _currentBackgroundIsEmptyView = true; } else { // Is the empty view currently in the background? Swap back to the default. if (_currentBackgroundIsEmptyView) { CollectionView.BackgroundView = _backgroundUIView; ItemsView.RemoveLogicalChild(_emptyViewFormsElement); } _currentBackgroundIsEmptyView = false; } }
public void Bind(DataTemplate template, object bindingContext, ItemsView itemsView) { var oldElement = VisualElementRenderer?.Element; if (template != _currentTemplate) { // Remove the old view, if it exists if (oldElement != null) { oldElement.MeasureInvalidated -= MeasureInvalidated; itemsView.RemoveLogicalChild(oldElement); ClearSubviews(); _size = Size.Zero; } // Create the content and renderer for the view var view = template.CreateContent() as View; var renderer = TemplateHelpers.CreateRenderer(view); SetRenderer(renderer); } var currentElement = VisualElementRenderer?.Element; // Bind the view to the data item if (currentElement != null) { currentElement.BindingContext = bindingContext; } if (template != _currentTemplate) { // And make the Element a "child" of the ItemsView // We deliberately do this _after_ setting the binding context for the new element; // if we do it before, the element briefly inherits the ItemsView's bindingcontext and we // emit a bunch of needless binding errors itemsView.AddLogicalChild(currentElement); } _currentTemplate = template; }
internal void UpdateSubview(object view, DataTemplate viewTemplate, ref UIView uiView, ref VisualElement formsElement) { if (uiView != null) { CollectionView.Subviews.Remove(uiView); } if (formsElement != null) { ItemsView.RemoveLogicalChild(formsElement); formsElement.MeasureInvalidated -= OnFormsElementMeasureInvalidated; } UpdateView(view, viewTemplate, ref uiView, ref formsElement); if (uiView != null) { CollectionView.AddSubview(uiView); } if (formsElement != null) { ItemsView.AddLogicalChild(formsElement); } if (formsElement != null) { var request = formsElement.Measure(CollectionView.Frame.Width, double.PositiveInfinity, MeasureFlags.IncludeMargins); Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion(formsElement, new Rectangle(0, -request.Request.Height, CollectionView.Frame.Width, request.Request.Height)); formsElement.MeasureInvalidated += OnFormsElementMeasureInvalidated; } else if (uiView != null) { uiView.SizeToFit(); } }
public void Recycle(ItemsView itemsView) { itemsView.RemoveLogicalChild(View); }
public void Recycle(ItemsView itemsView) { View.BindingContext = null; itemsView.RemoveLogicalChild(View); _itemContentView.Recycle(); }