public void DetachAndCacheView(View view, RecyclerView.Recycler recycler)
        {
            var holder = _owner.GetChildViewHolder(view) as UnoViewHolder;

            if (!holder.IsRecyclable)
            {
                //Item is probably animating, we throw it back to the recycler rather than just detaching it to prevent the following error: "java.lang.IllegalArgumentException: Tmp detached view should be removed from RecyclerView before it can be recycled"
                Layout.RemoveAndRecycleView(view, recycler);
                return;
            }

            Layout.DetachView(view);

            NotifyViewRecycled(holder);

            var views = _cachedViews.FindOrCreate(holder.ItemViewType, () => new List <UnoViewHolder>());

            if (views.Count == MaxCacheSize)
            {
                if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Debug))
                {
                    this.Log().Debug($"Cache already contains {MaxCacheSize} views, sending {view} to recycler.");
                }
                RecycleView(recycler, holder);
                return;
            }
            views.Add(holder);

            if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Debug))
            {
                this.Log().Debug($"Caching view of type {view.GetType().Name}. {views.Count} views cached in total.");
            }
        }
Example #2
0
        /// <summary>
        /// Detach view that was visible and send it to the cache.
        /// </summary>
        public void DetachAndCacheView(View view, RecyclerView.Recycler recycler)
        {
            var holder = _owner.GetChildViewHolder(view) as UnoViewHolder;
            var record = new ElementViewRecord(holder.LayoutPosition, holder);

            Layout.TryDetachView(view);
            SendToIntermediateCache(recycler, record);
        }