Beispiel #1
0
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();

            double height = Bounds.Height;
            double width  = Bounds.Width;

            if (_headerRenderer != null)
            {
                var e       = _headerRenderer.Element;
                var request = e.Measure(width, double.PositiveInfinity, MeasureFlags.IncludeMargins);

                // Time for another story with Jason. Gather round children because the following Math.Ceiling will look like it's completely useless.
                // You will remove it and test and find everything is fiiiiiine, but it is not fine, no it is far from fine. See iOS, or at least iOS 8
                // has an issue where-by if the TableHeaderView happens to NOT be an integer height, it will add padding to the space between the content
                // of the UITableView and the TableHeaderView to the tune of the difference between Math.Ceiling (height) - height. Now this seems fine
                // and when you test it will be, EXCEPT that it does this every time you toggle the visibility of the UITableView causing the spacing to
                // grow a little each time, which you weren't testing at all were you? So there you have it, the stupid reason we integer align here.
                //
                // The same technically applies to the footer, though that could hardly matter less. We just do it for fun.
                Layout.LayoutChildIntoBoundingRegion(e, new Rectangle(0, 0, width, Math.Ceiling(request.Request.Height)));

                Device.BeginInvokeOnMainThread(() =>
                {
                    if (_headerRenderer != null)
                    {
                        Control.TableHeaderView = _headerRenderer.NativeView;
                    }
                });
            }

            if (_footerRenderer != null)
            {
                var e       = _footerRenderer.Element;
                var request = e.Measure(width, height, MeasureFlags.IncludeMargins);
                Layout.LayoutChildIntoBoundingRegion(e, new Rectangle(0, 0, width, Math.Ceiling(request.Request.Height)));

                Device.BeginInvokeOnMainThread(() =>
                {
                    if (_footerRenderer != null)
                    {
                        Control.TableFooterView = _footerRenderer.NativeView;
                    }
                });
            }

            if (_requestedScroll != null && Superview != null)
            {
                var request = _requestedScroll;
                _requestedScroll = null;
                OnScrollToRequested(this, request);
            }

            if (_previousFrame != Frame)
            {
                _previousFrame = Frame;
                _insetTracker?.UpdateInsets();
            }
        }
 void LayoutSubviews()
 {
     if (_requestedScroll != null && Superview != null)
     {
         var request = _requestedScroll;
         _requestedScroll = null;
         OnScrollToRequested(this, request);
     }
 }
        private void Element_ScrollToRequested(object sender, ScrollToRequestedEventArgs e)
        {
            //TODO: Animate Support
            //TODO: Support Position

            var scrollArgs = (ITemplatedItemsListScrollToRequestedEventArgs)e;

            Control.ScrollIntoView(scrollArgs.Item);
        }
Beispiel #4
0
        public void SetElement(VisualElement element)
        {
            _requestedScroll = null;
            var oldElement = Element;

            Element = element;

            if (oldElement != null)
            {
                oldElement.PropertyChanged -= HandlePropertyChanged;
                ((ScrollView)oldElement).ScrollToRequested -= OnScrollToRequested;
            }

            if (element != null)
            {
                element.PropertyChanged += HandlePropertyChanged;
                ((ScrollView)element).ScrollToRequested += OnScrollToRequested;
                if (_packager == null)
                {
                    _packager = new VisualElementPackager(this);
                    _packager.Load();

                    _tracker = new VisualElementTracker(this);
                    _tracker.NativeControlUpdated += OnNativeControlUpdated;
                    _events = new EventTracker(this);
                    _events.LoadEvents(this);

                    _insetTracker = new KeyboardInsetTracker(this, () => Window, insets => ContentInset = ScrollIndicatorInsets = insets, point =>
                    {
                        var offset = ContentOffset;
                        offset.Y  += point.Y;
                        SetContentOffset(offset, true);
                    });
                }

                UpdateDelaysContentTouches();
                UpdateContentSize();
                UpdateBackgroundColor();
                UpdateIsEnabled();
                UpdateVerticalScrollBarVisibility();
                UpdateHorizontalScrollBarVisibility();

                OnElementChanged(new VisualElementChangedEventArgs(oldElement, element));

                EffectUtilities.RegisterEffectControlProvider(this, oldElement, element);

                if (element != null)
                {
                    element.SendViewInitialized(this);
                }

                if (!string.IsNullOrEmpty(element.AutomationId))
                {
                    AccessibilityIdentifier = element.AutomationId;
                }
            }
        }
Beispiel #5
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);

            if (_pendingScrollTo != null)
            {
                OnScrollToRequested(this, _pendingScrollTo);
                _pendingScrollTo = null;
            }
        }
        protected virtual void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e)
        {
            if (!IsAttached)
            {
                _pendingScrollTo = e;
                return;
            }

            Cell cell; // TODO: this is not used at current version. If used individual size, this must be used.
            int  position;
            var  scrollArgs = (ITemplatedItemsListScrollToRequestedEventArgs)e;

            if (scrollArgs.Item == null)
            {
                if (e.Position == ScrollToPosition.Start)
                {
                    ExecuteScroll(0, e);
                }
                else
                {
                    ExecuteScroll(Adapter.ItemCount - 1, e);
                }
                return;
            }

            var templatedItems = TemplatedItemsView.TemplatedItems;

            if (Element.IsGroupingEnabled)
            {
                var results = templatedItems.GetGroupAndIndexOfItem(scrollArgs.Group, scrollArgs.Item);
                if (results.Item1 == -1 || results.Item2 == -1)
                {
                    return;
                }

                var group = templatedItems.GetGroup(results.Item1);
                cell = group[results.Item2];

                position = templatedItems.GetGlobalIndexForGroup(group) + results.Item2 + 1;
            }
            else
            {
                position = templatedItems.GetGlobalIndexOfItem(scrollArgs.Item);
                if (position == -1)
                {
                    return;
                }

                cell = templatedItems[position];
            }


            ExecuteScroll(position, e);
        }
Beispiel #7
0
        public void SetElement(VisualElement element)
        {
            this.requestedScroll = null;
            VisualElement visualElement = this.Element;

            this.Element = element;
            if (visualElement != null)
            {
                visualElement.PropertyChanged -= new PropertyChangedEventHandler(this.HandlePropertyChanged);
                ((IScrollViewController)visualElement).ScrollToRequested -= new EventHandler <ScrollToRequestedEventArgs>(this.OnScrollToRequested);
            }
            if (element != null)
            {
                element.PropertyChanged += new PropertyChangedEventHandler(this.HandlePropertyChanged);
                ((IScrollViewController)element).ScrollToRequested += new EventHandler <ScrollToRequestedEventArgs>(this.OnScrollToRequested);
                if (this.packager == null)
                {
                    //this.DelaysContentTouches = true;

                    this.packager = new VisualElementPackager(this);
                    this.packager.Load();
                    this.tracker = new VisualElementTracker(this);
                    this.tracker.NativeControlUpdated += new EventHandler(this.OnNativeControlUpdated);
                    this.events = new EventTracker(this);
                    this.events.LoadEvents(this);

                    // TODO: WT.?

                    /*
                     * this.insetTracker = new KeyboardInsetTracker(this, () => this.Window, (UIEdgeInsets insets) => {
                     *      UIEdgeInsets uIEdgeInset = insets;
                     *      UIEdgeInsets uIEdgeInset1 = uIEdgeInset;
                     *      this.ScrollIndicatorInsets = uIEdgeInset;
                     *      this.ContentInset = uIEdgeInset1;
                     * }, (CGPoint point) => {
                     *      CGPoint contentOffset = this.ContentOffset;
                     *      contentOffset.Y = contentOffset.Y + point.Y;
                     *      this.SetContentOffset(contentOffset, true);
                     * });
                     */
                }
                this.UpdateContentSize();
                this.UpdateBackgroundColor();
                this.OnElementChanged(new VisualElementChangedEventArgs(visualElement, element));
                if (element != null)
                {
                    element.SendViewInitialized(this);
                }
            }
        }
Beispiel #8
0
        private void OnScrollRequested(object sender, ScrollToRequestedEventArgs args)
        {
            float toX = Context.ToPixels(args.ScrollX);
            float toY = Context.ToPixels(args.ScrollY);

            if (args.Mode == ScrollToMode.Element)
            {
                Point itemPosition = Element.GetScrollPositionForElement(args.Element as VisualElement, args.Position);

                toX = Context.ToPixels(itemPosition.X);
                toY = Context.ToPixels(itemPosition.Y);
            }

            _zoomLayout.PanTo(toX, toY, args.ShouldAnimate);
        }
        void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e)
        {
            if (Superview == null)
            {
                _requestedScroll = e;
                return;
            }

            Point scrollPoint = (e.Mode == ScrollToMode.Position)
                                ? new Point(e.ScrollX, Element.Height - e.ScrollY)
                                : ScrollView.GetScrollPositionForElement(e.Element as VisualElement, e.Position);

            ContentView.ScrollToPoint(scrollPoint.ToPointF());
            ScrollView.SendScrollFinished();
        }
        void OnScrollRequested(object sender, ScrollToRequestedEventArgs e)
        {
            var x = e.ScrollX;
            var y = e.ScrollY;

            if (e.Mode == ScrollToMode.Element)
            {
                Point itemPosition = (Element as IScrollViewController).GetScrollPositionForElement(e.Element as VisualElement, e.Position);
                x = itemPosition.X;
                y = itemPosition.Y;
            }

            Rect region = new Rectangle(x, y, Element.Width, Element.Height).ToPixel();

            Control.ScrollTo(region, e.ShouldAnimate);
        }
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();

            if (_requestedScroll != null && Superview != null)
            {
                var request = _requestedScroll;
                _requestedScroll = null;
                OnScrollToRequested(this, request);
            }

            if (_previousFrame != Frame)
            {
                _previousFrame = Frame;
            }
        }
        void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e)
        {
            _checkedForRtlScroll = true;

            if (Superview == null)
            {
                _requestedScroll = e;
                return;
            }

            PointF newOffset = PointF.Empty;

            if (e.Mode == ScrollToMode.Position)
            {
                newOffset = new PointF((nfloat)e.ScrollX, (nfloat)e.ScrollY);
            }
            else
            {
                var positionOnScroll = ScrollView.GetScrollPositionForElement(e.Element as VisualElement, e.Position);

                positionOnScroll.X = positionOnScroll.X.Clamp(0, ContentSize.Width - Bounds.Size.Width);
                positionOnScroll.Y = positionOnScroll.Y.Clamp(0, ContentSize.Height - Bounds.Size.Height);

                switch (ScrollView.Orientation)
                {
                case ScrollOrientation.Horizontal:
                    newOffset = new PointF((nfloat)positionOnScroll.X, ContentOffset.Y);
                    break;

                case ScrollOrientation.Vertical:
                    newOffset = new PointF(ContentOffset.X, (nfloat)positionOnScroll.Y);
                    break;

                case ScrollOrientation.Both:
                    newOffset = new PointF((nfloat)positionOnScroll.X, (nfloat)positionOnScroll.Y);
                    break;
                }
            }
            var sameOffset = newOffset == ContentOffset;

            SetContentOffset(newOffset, e.ShouldAnimate);

            if (!e.ShouldAnimate || sameOffset)
            {
                ScrollView.SendScrollFinished();
            }
        }
Beispiel #13
0
        async void OnScrollRequestedAsync(object sender, ScrollToRequestedEventArgs e)
        {
            var x = e.ScrollX;
            var y = e.ScrollY;

            if (e.Mode == ScrollToMode.Element)
            {
                var itemPosition = (Element as IScrollViewController).GetScrollPositionForElement(e.Element as VisualElement, e.Position);
                x = itemPosition.X;
                y = itemPosition.Y;
            }
            var region = new Xamarin.Forms.Rectangle(x, y, Element.Width, Element.Height).ToPixel();

            await ScrollToAsync(region, e.ShouldAnimate).ConfigureAwait(false);

            Element.SendScrollFinished();
        }
Beispiel #14
0
        async void OnScrollRequested(object sender, ScrollToRequestedEventArgs e)
        {
            var x = e.ScrollX;
            var y = e.ScrollY;

            if (e.Mode == ScrollToMode.Element)
            {
                Graphics.Point itemPosition = (Element as IScrollViewController).GetScrollPositionForElement(e.Element as VisualElement, e.Position);
                x = itemPosition.X;
                y = itemPosition.Y;
            }

            ERect region = new Graphics.Rect(x, y, Element.Width, Element.Height).ToEFLPixel();
            await Control.ScrollToAsync(region, e.ShouldAnimate);

            Element.SendScrollFinished();
        }
        async void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e)
        {
            ClearRtlScrollCheck();

            // Adding items into the view while scrolling to the end can cause it to fail, as
            // the items have not actually been laid out and return incorrect scroll position
            // values. The ScrollViewRenderer for Android does something similar by waiting up
            // to 10ms for layout to occur.
            int cycle = 0;

            while (Element != null && !Element.IsInNativeLayout)
            {
                await Task.Delay(TimeSpan.FromMilliseconds(1));

                cycle++;

                if (cycle >= 10)
                {
                    break;
                }
            }

            if (Element == null)
            {
                return;
            }

            double x = e.ScrollX, y = e.ScrollY;

            ScrollToMode mode = e.Mode;

            if (mode == ScrollToMode.Element)
            {
                Point pos = Element.GetScrollPositionForElement((VisualElement)e.Element, e.Position);
                x    = pos.X;
                y    = pos.Y;
                mode = ScrollToMode.Position;
            }

            if (mode == ScrollToMode.Position)
            {
                Control.ChangeView(x, y, null, !e.ShouldAnimate);
            }
            Element.SendScrollFinished();
        }
 protected override void ExecuteScroll(int targetPosition, ScrollToRequestedEventArgs eventArgs)
 {
     if (_hCollectionView.IsInfinite)
     {
         int fixPosition = _hAdapter.GetInitialPosition();
         if (targetPosition == Adapter.ItemCount - 1)
         {
             fixPosition += Adapter.RealItemCount - 1;
         }
         else
         {
             fixPosition += targetPosition;
         }
         base.ExecuteScroll(fixPosition, eventArgs);
         return;
     }
     base.ExecuteScroll(targetPosition, eventArgs);
 }
        void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e)
        {
            double x = e.ScrollX, y = e.ScrollY;

            ScrollToMode mode = e.Mode;

            if (mode == ScrollToMode.Element)
            {
                Point pos = Controller.GetScrollPositionForElement((VisualElement)e.Element, e.Position);
                x    = pos.X;
                y    = pos.Y;
                mode = ScrollToMode.Position;
            }

            if (mode == ScrollToMode.Position)
            {
                Control.ChangeView(x, y, null, !e.ShouldAnimate);
            }
        }
        public void SetElement(VisualElement element)
        {
            _requestedScroll = null;
            var oldElement = Element;

            Element = element;

            if (oldElement != null)
            {
                oldElement.PropertyChanged -= HandlePropertyChanged;
                ((IScrollViewController)oldElement).ScrollToRequested -= OnScrollToRequested;
            }

            if (element != null)
            {
                element.PropertyChanged += HandlePropertyChanged;
                ((IScrollViewController)element).ScrollToRequested += OnScrollToRequested;
                if (_packager == null)
                {
                    DelaysContentTouches = true;

                    _packager = new VisualElementPackager(this);
                    _packager.Load();

                    _tracker = new VisualElementTracker(this);
                    _events  = new EventTracker(this);
                    _events.LoadEvents(this);
                }

                UpdateContentSize();
                UpdateBackgroundColor();

                OnElementChanged(new VisualElementChangedEventArgs(oldElement, element));

                Custom.Helpers.RegisterEffectControlProvider(this, oldElement, element);

                if (!string.IsNullOrEmpty(element.AutomationId))
                {
                    AccessibilityIdentifier = element.AutomationId;
                }
            }
        }
        void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e)
        {
            UpdatePropertyHelper((element, control) =>
            {
                //if (_animatable == null && e.ShouldAnimate)
                //	_animatable = new Animatable();

                var position = e.Position;
                int x        = (int)e.ScrollX;
                int y        = (int)e.ScrollY;

                if (e.Mode == ScrollToMode.Element)
                {
                    var itemPosition = element.GetScrollPositionForElement(e.Element as VisualElement, e.Position);
                    x = (int)itemPosition.X;
                    y = (int)itemPosition.Y;
                }

                if (control.VerticalScroll.Value == y && control.HorizontalScroll.Value == x)
                {
                    return;
                }

                /*if (e.ShouldAnimate)
                 * {
                 *      var animation = new Animation(v => { UpdateScrollOffset(GetDistance(Control.ViewportWidth, x, v), GetDistance(Control.ViewportHeight, y, v)); });
                 *
                 *      animation.Commit(_animatable, "ScrollTo", length: 500, easing: Easing.CubicInOut, finished: (v, d) =>
                 *      {
                 *              UpdateScrollOffset(x, y);
                 *              element.SendScrollFinished();
                 *      });
                 * }
                 * else*/
                {
                    UpdateScrollOffset(x, y);
                    element.SendScrollFinished();
                }
            });
        }
Beispiel #20
0
        public void SetElement(VisualElement element)
        {
            _requestedScroll = null;
            var oldElement = Element;

            Element = element;

            if (oldElement != null)
            {
                oldElement.PropertyChanged -= OnElementPropertyChanged;
                ((ScrollView)oldElement).ScrollToRequested -= OnScrollToRequested;
            }

            if (element != null)
            {
                element.PropertyChanged += OnElementPropertyChanged;
                ((ScrollView)element).ScrollToRequested += OnScrollToRequested;
                if (_tracker == null)
                {
                    PackContent();

                    _events = new EventTracker(this);
                    _events.LoadEvents(this);

                    _tracker = new VisualElementTracker(this);
                    _tracker.NativeControlUpdated += OnNativeControlUpdated;
                }

                UpdateContentSize();
                UpdateBackgroundColor();
                UpdateBackground();
                UpdateVerticalScrollBarVisibility();
                UpdateHorizontalScrollBarVisibility();

                UpdateOrientation();
                RaiseElementChanged(new VisualElementChangedEventArgs(oldElement, element));
            }

            ResetNativeNonScroll();
        }
        void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e)
        {
            if (_animatable == null && e.ShouldAnimate)
            {
                _animatable = new Animatable();
            }

            ScrollToPosition position = e.Position;
            double           x        = e.ScrollX;
            double           y        = e.ScrollY;

            if (e.Mode == ScrollToMode.Element)
            {
                Point itemPosition = Controller.GetScrollPositionForElement(e.Element as VisualElement, e.Position);
                x = itemPosition.X;
                y = itemPosition.Y;
            }

            if (Control.VerticalOffset == y && Control.HorizontalOffset == x)
            {
                return;
            }

            if (e.ShouldAnimate)
            {
                var animation = new Animation(v => { UpdateScrollOffset(GetDistance(Control.ViewportWidth, x, v), GetDistance(Control.ViewportHeight, y, v)); });

                animation.Commit(_animatable, "ScrollTo", length: 500, easing: Easing.CubicInOut, finished: (v, d) =>
                {
                    UpdateScrollOffset(x, y);
                    Controller.SendScrollFinished();
                });
            }
            else
            {
                UpdateScrollOffset(x, y);
                Controller.SendScrollFinished();
            }
        }
Beispiel #22
0
        private void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e)
        {
            double x = e.ScrollX, y = e.ScrollY;

            ScrollToMode mode = e.Mode;

            if (mode == ScrollToMode.Element)
            {
                Point pos = Controller.GetScrollPositionForElement((VisualElement)e.Element, e.Position);
                x    = pos.X;
                y    = pos.Y;
                mode = ScrollToMode.Position;
            }

            if (mode == ScrollToMode.Position)
            {
                Control.Hadjustment.Value = x;
                Control.Vadjustment.Value = y;
            }

            Controller.SendScrollFinished();
        }
        void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e)
        {
            if (Superview == null)
            {
                _requestedScroll = e;
                return;
            }
            if (e.Mode == ScrollToMode.Position)
            {
                SetContentOffset(new PointF((nfloat)e.ScrollX, (nfloat)e.ScrollY), e.ShouldAnimate);
            }
            else
            {
                var positionOnScroll = Controller.GetScrollPositionForElement(e.Element as VisualElement, e.Position);

                positionOnScroll.X = positionOnScroll.X.Clamp(0, ContentSize.Width - Bounds.Size.Width);
                positionOnScroll.Y = positionOnScroll.Y.Clamp(0, ContentSize.Height - Bounds.Size.Height);

                switch (ScrollView.Orientation)
                {
                case ScrollOrientation.Horizontal:
                    SetContentOffset(new PointF((nfloat)positionOnScroll.X, ContentOffset.Y), e.ShouldAnimate);
                    break;

                case ScrollOrientation.Vertical:
                    SetContentOffset(new PointF(ContentOffset.X, (nfloat)positionOnScroll.Y), e.ShouldAnimate);
                    break;

                case ScrollOrientation.Both:
                    SetContentOffset(new PointF((nfloat)positionOnScroll.X, (nfloat)positionOnScroll.Y), e.ShouldAnimate);
                    break;
                }
            }
            if (!e.ShouldAnimate)
            {
                Controller.SendScrollFinished();
            }
        }
Beispiel #24
0
        private void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e)
        {
            if (this.Superview == null)
            {
                this.requestedScroll = e;
                return;
            }
            if (e.Mode != ScrollToMode.Position)
            {
                Point scrollPositionForElement = this.Controller.GetScrollPositionForElement(e.Element as VisualElement, e.Position);
                if (scrollView.Orientation != ScrollOrientation.Horizontal)
                {
                    //TODO: Scroll to Position
                    //VerticalScroller.FloatValue = e.Position;

                    //SetContentOffset(new CGPoint(contentOffset.X, (nfloat)scrollPositionForElement.Y), e.ShouldAnimate);
                }
                else
                {
                    // TODO: Scroll to Position
                    //HorizontalScroller.FloatValue = e.Position;

                    //nfloat x = (nfloat)scrollPositionForElement.X;
                    //SetContentOffset(new CGPoint(x, contentOffset.Y), e.ShouldAnimate);
                }
            }
            else
            {
                VerticalScroller.FloatValue   = (float)e.ScrollY;
                HorizontalScroller.FloatValue = (float)e.ScrollX;
                //this.SetContentOffset(new CGPoint((nfloat)e.ScrollX, (nfloat)e.ScrollY), e.ShouldAnimate);
            }
            if (!e.ShouldAnimate)
            {
                this.Controller.SendScrollFinished();
            }
        }
Beispiel #25
0
        void ListView_ScrollToRequested(object sender, ScrollToRequestedEventArgs e)
        {
            if (Control == null)
            {
                return;
            }

            var oe    = (ITemplatedItemsListScrollToRequestedEventArgs)e;
            var item  = oe.Item;
            var group = oe.Group;

            switch (e.Position)
            {
            case ScrollToPosition.Start:
                Control.Send(Ooui.Message.Set(Control.Id, "scrollTop", 0));
                break;

            case ScrollToPosition.End:
                Control.Send(Ooui.Message.Set(Control.Id, "scrollTop", new Ooui.Message.PropertyReference {
                    TargetId = Control.Id, Key = "scrollHeight"
                }));
                break;
            }
        }
Beispiel #26
0
        void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e)
        {
            Cell cell;
            var  args = e as ITemplatedItemsListScrollToRequestedEventArgs;

            if (Element.IsGroupingEnabled)
            {
                var results = Element.TemplatedItems.GetGroupAndIndexOfItem(args.Group, args.Item);
                if (results.Item1 == -1 || results.Item2 == -1)
                {
                    return;
                }

                var group = (Element.TemplatedItems as ITemplatedItemsList <Cell>).GetGroup(results.Item1);
                cell = group[results.Item2];
            }
            else
            {
                int index = (Element.TemplatedItems as ITemplatedItemsList <Cell>).GetGlobalIndexOfItem(args.Item);
                cell = Element.TemplatedItems[index];
            }

            Control.ApplyScrollTo(cell, e.Position, e.ShouldAnimate);
        }
Beispiel #27
0
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();

            if (Superview != null)
            {
                if (_requestedScroll != null)
                {
                    var request = _requestedScroll;
                    _requestedScroll = null;
                    OnScrollToRequested(this, request);
                }
                else
                {
                    UpdateFlowDirection();
                }
            }

            if (_previousFrame != Frame)
            {
                _previousFrame = Frame;
                _insetTracker?.UpdateInsets();
            }
        }
        async void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e)
        {
            if (!_isAttached)
            {
                return;
            }

            // 99.99% of the time simply queuing to the end of the execution queue should handle this case.
            // However it is possible to end a layout cycle and STILL be layout requested. We want to
            // back off until all are done, even if they trigger layout storms over and over. So we back off
            // for 10ms tops then move on.
            var cycle = 0;

            while (IsLayoutRequested)
            {
                await Task.Delay(TimeSpan.FromMilliseconds(1));

                cycle++;

                if (cycle >= 10)
                {
                    break;
                }
            }

            var x        = (int)Forms.Context.ToPixels(e.ScrollX);
            var y        = (int)Forms.Context.ToPixels(e.ScrollY);
            int currentX = _view.Orientation == ScrollOrientation.Horizontal ? _hScrollView.ScrollX : ScrollX;
            int currentY = _view.Orientation == ScrollOrientation.Horizontal ? _hScrollView.ScrollY : ScrollY;

            if (e.Mode == ScrollToMode.Element)
            {
                Point itemPosition = Controller.GetScrollPositionForElement(e.Element as VisualElement, e.Position);

                x = (int)Forms.Context.ToPixels(itemPosition.X);
                y = (int)Forms.Context.ToPixels(itemPosition.Y);
            }
            if (e.ShouldAnimate)
            {
                ValueAnimator animator = ValueAnimator.OfFloat(0f, 1f);
                animator.SetDuration(1000);
                animator.Update += (o, animatorUpdateEventArgs) =>
                {
                    var v     = (double)animatorUpdateEventArgs.Animation.AnimatedValue;
                    int distX = GetDistance(currentX, x, v);
                    int distY = GetDistance(currentY, y, v);

                    if (_view == null)
                    {
                        // This is probably happening because the page with this Scroll View
                        // was popped off the stack during animation
                        animator.Cancel();
                        return;
                    }

                    if (_view.Orientation == ScrollOrientation.Horizontal)
                    {
                        _hScrollView.ScrollTo(distX, distY);
                    }
                    else
                    {
                        ScrollTo(distX, distY);
                    }
                };
                animator.AnimationEnd += delegate
                {
                    if (Controller == null)
                    {
                        return;
                    }
                    Controller.SendScrollFinished();
                };

                animator.Start();
            }
            else
            {
                if (_view.Orientation == ScrollOrientation.Horizontal)
                {
                    _hScrollView.ScrollTo(x, y);
                }
                else
                {
                    ScrollTo(x, y);
                }
                Controller.SendScrollFinished();
            }
        }
		async void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e)
		{
			if (!_isAttached)
			{
				return;
			}

			// 99.99% of the time simply queuing to the end of the execution queue should handle this case.
			// However it is possible to end a layout cycle and STILL be layout requested. We want to
			// back off until all are done, even if they trigger layout storms over and over. So we back off
			// for 10ms tops then move on.
			var cycle = 0;
			while (IsLayoutRequested)
			{
				await Task.Delay(TimeSpan.FromMilliseconds(1));
				cycle++;

				if (cycle >= 10)
					break;
			}

			var x = (int)Forms.Context.ToPixels(e.ScrollX);
			var y = (int)Forms.Context.ToPixels(e.ScrollY);
			int currentX = _view.Orientation == ScrollOrientation.Horizontal ? _hScrollView.ScrollX : ScrollX;
			int currentY = _view.Orientation == ScrollOrientation.Horizontal ? _hScrollView.ScrollY : ScrollY;
			if (e.Mode == ScrollToMode.Element)
			{
				Point itemPosition = Controller.GetScrollPositionForElement(e.Element as VisualElement, e.Position);

				x = (int)Forms.Context.ToPixels(itemPosition.X);
				y = (int)Forms.Context.ToPixels(itemPosition.Y);
			}
			if (e.ShouldAnimate)
			{
				ValueAnimator animator = ValueAnimator.OfFloat(0f, 1f);
				animator.SetDuration(1000);
				animator.Update += (o, animatorUpdateEventArgs) =>
				{
					var v = (double)animatorUpdateEventArgs.Animation.AnimatedValue;
					int distX = GetDistance(currentX, x, v);
					int distY = GetDistance(currentY, y, v);

					if (_view == null)
					{
						// This is probably happening because the page with this Scroll View
						// was popped off the stack during animation
						animator.Cancel();
						return;
					}

					if (_view.Orientation == ScrollOrientation.Horizontal)
						_hScrollView.ScrollTo(distX, distY);
					else
						ScrollTo(distX, distY);
				};
				animator.AnimationEnd += delegate
				{
					if (Controller == null)
						return;
					Controller.SendScrollFinished();
				};

				animator.Start();
			}
			else
			{
				if (_view.Orientation == ScrollOrientation.Horizontal)
					_hScrollView.ScrollTo(x, y);
				else
					ScrollTo(x, y);
				Controller.SendScrollFinished();
			}
		}
Beispiel #30
0
        void OnElementScrollToRequested(object sender, ScrollToRequestedEventArgs e)
        {
            var scrollArgs = (ITemplatedItemsListScrollToRequestedEventArgs)e;

            ScrollTo(scrollArgs.Group, scrollArgs.Item, e.Position, e.ShouldAnimate);
        }
Beispiel #31
0
 private void ListViewControllerOnScrollToRequested(object sender, ScrollToRequestedEventArgs scrollToRequestedEventArgs)
 {
 }