Beispiel #1
0
        public override ESize MeasureItem(int index, int widthConstraint, int heightConstraint)
        {
            if (_dataBindedViewTable.TryGetValue(this[index], out View createdView) && createdView != null)
            {
                return(createdView.Measure(Forms.ConvertToScaledDP(widthConstraint), Forms.ConvertToScaledDP(heightConstraint), MeasureFlags.IncludeMargins).Request.ToPixel());
            }

            View view = null;

            if (ItemTemplate is DataTemplateSelector selector)
            {
                view = selector.SelectTemplate(this[index], _itemsView).CreateContent() as View;
            }
            else
            {
                view = ItemTemplate.CreateContent() as View;
            }
            using (var renderer = Platform.GetOrCreateRenderer(view))
            {
                view.Parent = _itemsView;
                if (Count > index)
                {
                    view.BindingContext = this[index];
                }
                var request = view.Measure(Forms.ConvertToScaledDP(widthConstraint), Forms.ConvertToScaledDP(heightConstraint), MeasureFlags.IncludeMargins).Request;
                return(request.ToPixel());
            }
        }
Beispiel #2
0
 protected override void OnCompleted(View sender, object data)
 {
     if (Recognizer is SwipeGestureRecognizer swipeGesture)
     {
         var lineData = (GestureLayer.LineData)data;
         (swipeGesture as ISwipeGestureController)?.SendSwipe(sender, Forms.ConvertToScaledDP(lineData.X2 - lineData.X1), Forms.ConvertToScaledDP(lineData.Y2 - lineData.Y1));
         (swipeGesture as ISwipeGestureController)?.DetectSwipe(sender, swipeGesture.Direction);
     }
 }
Beispiel #3
0
        public override ESize MeasureItem(int widthConstraint, int heightConstraint)
        {
            var view = (View)ItemTemplate.CreateContent();

            if (Count > 0)
            {
                ((view as StackLayout).Children[0] as XLabel).Text = this[0].ToString();
            }
            var renderer = Platform.GetOrCreateRenderer(view);
            var request  = view.Measure(Forms.ConvertToScaledDP(widthConstraint), Forms.ConvertToScaledDP(heightConstraint), MeasureFlags.IncludeMargins).Request;

            renderer.Dispose();
            return(request.ToPixel());
        }
Beispiel #4
0
        public override ESize MeasureItem(int widthConstraint, int heightConstraint)
        {
            var view     = ItemTemplate.CreateContent() as View;
            var renderer = Platform.GetOrCreateRenderer(view);

            view.Parent = _itemsView;
            if (Count > 0)
            {
                view.BindingContext = this[0];
            }
            var request = view.Measure(Forms.ConvertToScaledDP(widthConstraint), Forms.ConvertToScaledDP(heightConstraint), MeasureFlags.IncludeMargins).Request;

            renderer.Dispose();

            return(request.ToPixel());
        }
Beispiel #5
0
        static double ComputeAbsoluteY(VisualElement e)
        {
            var parentY = 0.0;

            if (e.RealParent is VisualElement ve)
            {
                if (CompressedLayout.GetIsHeadless(e.RealParent))
                {
                    parentY = ComputeAbsoluteY(ve);
                }
                else
                {
                    parentY = Forms.ConvertToScaledDP(Platform.GetRenderer(e.RealParent).GetNativeContentGeometry().Y);
                }
            }
            return(e.Y + parentY);
        }
Beispiel #6
0
        void UpdatPageLayout(object sender, LayoutEventArgs e)
        {
            double dHeight = _titleView.Measure(Forms.ConvertToScaledDP(e.Geometry.Width), Forms.ConvertToScaledDP(e.Geometry.Height)).Request.Height;
            int    height  = 0;

            if (_hasNavigationBar)
            {
                height = Forms.ConvertToScaledPixel(dHeight);
            }

            var renderer = Platform.GetOrCreateRenderer(_titleView);

            renderer.NativeView.Move(e.Geometry.X, e.Geometry.Y);
            renderer.NativeView.Resize(e.Geometry.Width, height);

            _page.Move(e.Geometry.X, e.Geometry.Y + height);
            _page.Resize(e.Geometry.Width, e.Geometry.Height - height);
        }
Beispiel #7
0
        static double ComputeAbsoluteY(VisualElement e)
        {
            var parentY = 0.0;

            if (e.RealParent is VisualElement parent)
            {
                if (CompressedLayout.GetIsHeadless(e.RealParent))
                {
                    parentY = ComputeAbsoluteY(parent);
                }
                else
                {
                    if (parent.Handler is IPlatformViewHandler nativeHandler)
                    {
                        parentY = nativeHandler.GetPlatformContentGeometry().Y.ToScaledDP();
                    }
                    else
                    {
                        parentY = Forms.ConvertToScaledDP(Platform.GetRenderer(e.RealParent).GetNativeContentGeometry().Y);
                    }
                }
            }
            return(e.Y + parentY);
        }
Beispiel #8
0
        protected override EvasObject OnGetContent(Cell cell, string part)
        {
            if (part == MainContentPart)
            {
                var entryCell   = cell as EntryCell;
                int pixelHeight = Forms.ConvertToScaledPixel(entryCell.RenderHeight);
                pixelHeight = pixelHeight > 0 ? pixelHeight : this.GetDefaultHeightPixel();

                var label = new Label()
                {
                    HorizontalOptions     = LayoutOptions.Start,
                    VerticalOptions       = LayoutOptions.Center,
                    VerticalTextAlignment = TextAlignment.Center,
                    FontSize = -1
                };
                label.SetBinding(Label.TextProperty, new Binding(EntryCell.LabelProperty.PropertyName));
                label.SetBinding(Label.TextColorProperty, new Binding(EntryCell.LabelColorProperty.PropertyName, converter: new DefaultColorConverter()));

                var entry = new Entry()
                {
                    HorizontalOptions = LayoutOptions.Fill,
                    VerticalOptions   = LayoutOptions.Center,
                    FontSize          = -1,
                };
                entry.SetBinding(Entry.TextProperty, new Binding(EntryCell.TextProperty.PropertyName, BindingMode.TwoWay));
                entry.SetBinding(Entry.PlaceholderProperty, new Binding(EntryCell.PlaceholderProperty.PropertyName));
                entry.SetBinding(InputView.KeyboardProperty, new Binding(EntryCell.KeyboardProperty.PropertyName));
                entry.SetBinding(Entry.HorizontalTextAlignmentProperty, new Binding(EntryCell.HorizontalTextAlignmentProperty.PropertyName));

                var layout = new XStackLayout()
                {
                    Orientation = StackOrientation.Horizontal,
                    Children    =
                    {
                        label,
                        entry
                    }
                };
                layout.Parent               = cell;
                layout.BindingContext       = entryCell;
                layout.MinimumHeightRequest = Forms.ConvertToScaledDP(pixelHeight);

                var renderer = Platform.GetOrCreateRenderer(layout);
                (renderer as ILayoutRenderer)?.RegisterOnLayoutUpdated();

                var nativeEntry = Platform.GetRenderer(entry)?.NativeView ?? null;
                if (nativeEntry != null)
                {
                    nativeEntry.PropagateEvents = false;
                }

                var nativeView = renderer.NativeView;
                nativeView.MinimumHeight    = pixelHeight;
                _cacheCandidate[nativeView] = layout;
                nativeView.Deleted         += (sender, e) =>
                {
                    _cacheCandidate.Remove(sender as EvasObject);
                };

                return(nativeView);
            }
            return(null);
        }
Beispiel #9
0
 public static Size ToDP(this ESize size)
 {
     return(new Size(Forms.ConvertToScaledDP(size.Width), Forms.ConvertToScaledDP(size.Height)));
 }
Beispiel #10
0
 public static Rectangle ToDP(this ERect rect)
 {
     return(new Rectangle(Forms.ConvertToScaledDP(rect.X), Forms.ConvertToScaledDP(rect.Y), Forms.ConvertToScaledDP(rect.Width), Forms.ConvertToScaledDP(rect.Height)));
 }
Beispiel #11
0
        void OnMoved(GestureLayer.MomentumData moment)
        {
            if (SwipeDirection == 0)
            {
                var direction = SwipeDirectionHelper.GetSwipeDirection(new Graphics.Point(moment.X1, moment.Y1), new Graphics.Point(moment.X2, moment.Y2));

                if (HasRightItems && direction == SwipeDirection.Left)
                {
                    SwipeDirection = SwipeDirection.Left;
                }
                else if (HasLeftItems && direction == SwipeDirection.Right)
                {
                    SwipeDirection = SwipeDirection.Right;
                }
                else if (HasTopItems && direction == SwipeDirection.Down)
                {
                    SwipeDirection = SwipeDirection.Down;
                }
                else if (HasBottomItems && direction == SwipeDirection.Up)
                {
                    SwipeDirection = SwipeDirection.Up;
                }
                else
                {
                    return;
                }

                UpdateItems();
                ((ISwipeViewController)Element).SendSwipeStarted(new SwipeStartedEventArgs(SwipeDirection));
            }

            var offset = GetSwipeOffset(moment);

            if (IsNegativeDirection)
            {
                if (offset > 0)
                {
                    offset = 0;
                }
            }
            else
            {
                if (offset < 0)
                {
                    offset = 0;
                }
            }

            if (Math.Abs(offset) > MaximumSwipeSize)
            {
                offset = MaximumSwipeSize * (offset < 0 ? -1 : 1);
            }

            var toDragBound = NativeView.Geometry;

            if (IsHorizontalSwipe)
            {
                toDragBound.X += offset;
            }
            else
            {
                toDragBound.Y += offset;
            }
            Platform.GetRenderer(SwipeView.Content).NativeView.Geometry = toDragBound;
            ((ISwipeViewController)Element).SendSwipeChanging(new SwipeChangingEventArgs(SwipeDirection, Forms.ConvertToScaledDP(offset)));
        }
Beispiel #12
0
 public override ESize MeasureFooter(int widthConstraint, int heightConstraint)
 {
     return(_footerCache?.Measure(Forms.ConvertToScaledDP(widthConstraint), Forms.ConvertToScaledDP(heightConstraint)).Request.ToPixel() ?? new ESize(0, 0));
 }
Beispiel #13
0
 private void OnMouseMove(object sender, EvasMouseEventArgs e)
 {
     Element?.OnTouchMove(new Point(Forms.ConvertToScaledDP(e.Point.X), Forms.ConvertToScaledDP(e.Point.Y)));
 }
Beispiel #14
0
        protected override void OnMoved(View sender, object data)
        {
            var lineData = (GestureLayer.MomentumData)data;

            (Recognizer as IPanGestureController)?.SendPan(sender, Forms.ConvertToScaledDP(lineData.X2 - lineData.X1), Forms.ConvertToScaledDP(lineData.Y2 - lineData.Y1), _currentPanGestureId);
        }