Example #1
0
 public OnControlScrollChangedListener(
     CollectionViewRenderer nativeView,
     CollectionView.RenderedViews.CollectionView element)
 {
     _weakNativeView = new WeakReference <CollectionViewRenderer>(nativeView);
     _element        = element;
 }
Example #2
0
            private void UpdateCurrentIndex(
                CollectionViewRenderer nativeView,
                CancellationToken token)
            {
                if (token.IsCancellationRequested)
                {
                    return;
                }

                if (nativeView?.LinearLayoutManager == null || _element == null)
                {
                    return;
                }

                nativeView._isCurrentIndexUpdateBackfire = true;
                try
                {
                    int newIndex = -1;
                    if (_element.SnapStyle != SnapStyle.None)
                    {
                        newIndex = nativeView.CurrentSnapIndex;
                    }
                    else
                    {
                        newIndex = nativeView.LinearLayoutManager.FindFirstCompletelyVisibleItemPosition();
                        if (newIndex == -1)
                        {
                            newIndex = nativeView.LinearLayoutManager.FindFirstVisibleItemPosition();
                        }
                    }

                    if (newIndex == -1)
                    {
                        InternalLogger.Warn(
                            "Failed to find the current index: UpdateCurrentIndex returns nothing");
                        return;
                    }

                    _element.CurrentIndex = newIndex;
                    InternalLogger.Info($"CurrentIndex: {_element.CurrentIndex}");
                }
                finally
                {
                    nativeView._isCurrentIndexUpdateBackfire = false;
                }
            }
 public StartSnapHelper(CollectionViewRenderer nativeView)
     : base(nativeView)
 {
 }
 public CenterSnapHelper(CollectionViewRenderer nativeView)
 {
     WeakNativeView = new WeakReference <CollectionViewRenderer>(nativeView);
 }
Example #5
0
            public RecycleViewAdapter(CollectionView.RenderedViews.CollectionView element, CollectionViewRenderer nativeView, RecyclerView parentView, Context context)
            {
                _element        = element;
                _weakNativeView = new WeakReference <CollectionViewRenderer>(nativeView);
                _weakParentView = new WeakReference <RecyclerView>(parentView);
                _context        = context;

                _elementItemsSource = element.ItemsSource;

                _dataSource = _elementItemsSource?.Cast <object>().ToList() ?? new List <object>();

                _formsViews = new List <WeakReference <ViewCell> >();

                if (_element.ItemTemplate is not DataTemplateSelector)
                {
                    // Cache only support single DataTemplate
                    _viewHolderQueue = new ViewHolderQueue(element.ViewCacheSize, () => CreateViewHolder());
                    _viewHolderQueue.Build();
                }

                _notifyCollectionChanged = _elementItemsSource as INotifyCollectionChanged;
                if (_notifyCollectionChanged != null)
                {
                    _notifyCollectionChanged.CollectionChanged += OnCollectionChanged;
                }
            }