Example #1
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == nameof(Element.Position) && _position != Element.Position && !Controller.IgnorePositionUpdates)
            {
                _physicalLayout.ScrollToPosition(Element.Position);
            }

            if (e.PropertyName == nameof(Element.ItemsSource))
            {
                InitializeAdapter();
            }

            base.OnElementPropertyChanged(sender, e);
        }
Example #2
0
        void Initialize()
        {
            // cache hit? Check if the view page is already created
            RecyclerView recyclerView = Control;

            if (recyclerView != null)
            {
                return;
            }

            // cache miss
            recyclerView = new RecyclerView(Context);
            SetNativeControl(recyclerView);

            // layoutManager
            recyclerView.SetLayoutManager(
                layout: _physicalLayout = new PhysicalLayoutManager(
                    context: Context,
                    virtualLayout: new VirtualLayoutManager()
                    )
                );

            // swiping
            recyclerView.AddOnScrollListener(
                new OnScrollListener(
                    onDragStart: () => { },
                    onDragEnd: () => {
                var velocity = _physicalLayout.Velocity;

                var target = velocity.X > 0 ?
                             _physicalLayout.VisiblePositions().Max() :
                             _physicalLayout.VisiblePositions().Min();
                _physicalLayout.ScrollToPosition(target);
            },
                    onScrollSettled: () => {
                var visiblePositions = _physicalLayout.VisiblePositions().ToArray();
                _position            = visiblePositions.Single();

                OnPositionChanged();
                OnItemChanged();
            },
                    visibleViewCount: () => _physicalLayout.VisiblePositions().Count()
                    )
                );

            // adapter
            InitializeAdapter();
        }