コード例 #1
0
        void ApplyTranslation(EvasMap map, ERect geometry, ref bool changed)
        {
            var shiftX = Forms.ConvertToScaledPixel(Element.TranslationX);
            var shiftY = Forms.ConvertToScaledPixel(Element.TranslationY);

            // apply translation, i.e. move/shift the object a little
            if (shiftX != 0 || shiftY != 0)
            {
                if (changed)
                {
                    // special care is taken to apply the translation last
                    Point3D p;
                    for (int i = 0; i < 4; i++)
                    {
                        p    = map.GetPointCoordinate(i);
                        p.X += shiftX;
                        p.Y += shiftY;
                        map.SetPointCoordinate(i, p);
                    }
                }
                else
                {
                    // in case when we only need translation, then construct the map in a simpler way
                    geometry.X += shiftX;
                    geometry.Y += shiftY;
                    map.PopulatePoints(geometry, 0);

                    changed = true;
                }
            }
        }
コード例 #2
0
        protected override EvasObject OnGetContent(Cell cell, string part)
        {
            if (part == MainContentPart)
            {
                var viewCell = (ViewCell)cell;

                var listView = viewCell?.RealParent as ListView;

                // It is a condition for reusable the cell
                if (listView != null &&
                    listView.HasUnevenRows == false &&
                    !(listView.ItemTemplate is DataTemplateSelector) && !GetCurrentItem().IsGroupItem)
                {
                    return(CreateReusableContent(viewCell));
                }

                Platform.GetRenderer(viewCell.View)?.Dispose();
                var    renderer = Platform.GetOrCreateRenderer(viewCell.View);
                double height   = viewCell.RenderHeight;
                height = height > 0 ? height : FindCellContentHeight(viewCell);

                renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(height);
                (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();

                UpdatePropagateEvent(viewCell.View);

                return(renderer.NativeView);
            }
            return(null);
        }
コード例 #3
0
        public SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
        {
            if (null == NativeView)
            {
                return(new SizeRequest(new Size(0, 0)));
            }
            else
            {
                int availableWidth  = Forms.ConvertToScaledPixel(widthConstraint);
                int availableHeight = Forms.ConvertToScaledPixel(heightConstraint);

                if (availableWidth < 0)
                {
                    availableWidth = int.MaxValue;
                }
                if (availableHeight < 0)
                {
                    availableHeight = int.MaxValue;
                }

                Size measured;
                var  nativeViewMeasurable = NativeView as Native.IMeasurable;
                if (nativeViewMeasurable != null)
                {
                    measured = nativeViewMeasurable.Measure(availableWidth, availableHeight).ToDP();
                }
                else
                {
                    measured = Measure(availableWidth, availableHeight).ToDP();
                }

                return(new SizeRequest(measured, MinimumSize()));
            }
        }
コード例 #4
0
        void OnLayout()
        {
            if (Geometry.Width == 0 || Geometry.Height == 0)
            {
                return;
            }

            var bound = Geometry;
            int navBarHeight;

            if (_navBarIsVisible)
            {
                var navBound = bound;
                navBarHeight    = Forms.ConvertToScaledPixel(_navBar.GetDefaultHeight());
                navBound.Height = navBarHeight;

                _navBar.Show();
                _navBar.Geometry = navBound;
                _navBar.RaiseTop();
            }
            else
            {
                navBarHeight = 0;
                _navBar.Hide();
            }

            bound.Y            += navBarHeight;
            bound.Height       -= navBarHeight;
            _viewStack.Geometry = bound;
        }
コード例 #5
0
ファイル: TransformExtensions.cs プロジェクト: redjaguar/maui
        public static SKMatrix ToSkia(this Transform transform)
        {
            SKMatrix skMatrix = SKMatrix.CreateIdentity();

            if (transform == null)
            {
                return(skMatrix);
            }

            Matrix matrix = transform.Value;

            skMatrix.Values = new float[] {
                (float)matrix.M11,
                (float)matrix.M21,
                Forms.ConvertToScaledPixel(matrix.OffsetX),
                (float)matrix.M12,
                (float)matrix.M22,
                Forms.ConvertToScaledPixel(matrix.OffsetY),
                0,
                0,
                1
            };

            return(skMatrix);
        }
コード例 #6
0
        protected override EvasObject OnGetContent(Cell cell, string part)
        {
            if (part == ImagePart)
            {
                var imgCell   = cell as ImageCell;
                int pixelSize = Forms.ConvertToScaledPixel(imgCell.RenderHeight);
                if (pixelSize <= 0)
                {
                    pixelSize = this.GetDefaultHeightPixel();
                }

                var image = new Native.Image(Forms.NativeParent)
                {
                    MinimumWidth  = pixelSize,
                    MinimumHeight = pixelSize
                };
                image.SetAlignment(-1.0, -1.0);            // fill
                image.SetWeight(1.0, 1.0);                 // expand

                var task = image.LoadFromImageSourceAsync(imgCell.ImageSource);
                return(image);
            }
            else
            {
                return(null);
            }
        }
コード例 #7
0
        protected override ElmSharp.Size Measure(int availableWidth, int availableHeight)
        {
            var size = _image.Measure(availableHeight, availableHeight);

            size.Width  += Forms.ConvertToScaledPixel(Element.Padding.HorizontalThickness);
            size.Height += Forms.ConvertToScaledPixel(Element.Padding.VerticalThickness);
            return(size);
        }
        void Initialize(EvasObject parent)
        {
            _menu = new GenList(parent)
            {
                BackgroundColor = EColor.Transparent,
                Style           = "solid/default",
            };

            _menu.ItemSelected += (s, e) =>
            {
                _flyoutMenu.TryGetValue(e.Item.Data as Item, out Element element);

                SelectedItemChanged?.Invoke(this, new SelectedItemChangedEventArgs(element, -1));
            };

            _menu.Show();
            PackEnd(_menu);

            _defaultClass = new GenItemClass("double_label")
            {
                GetTextHandler = (obj, part) =>
                {
                    if (part == "elm.text")
                    {
                        return(((Item)obj).Title);
                    }
                    else
                    {
                        return(null);
                    }
                },
                GetContentHandler = (obj, part) =>
                {
                    if (part == "elm.swallow.icon")
                    {
                        var icon = ((Item)obj).Icon;
                        if (icon != null)
                        {
                            var image = new Native.Image(parent)
                            {
                                MinimumWidth  = Forms.ConvertToScaledPixel(24),
                                MinimumHeight = Forms.ConvertToScaledPixel(24)
                            };
                            var result = image.LoadFromImageSourceAsync(icon);
                            return(image);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
            };
        }
コード例 #9
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 : Forms.ConvertToPixel(s_defaultHeight);

                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.FillAndExpand,
                    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 StackLayout()
                {
                    Orientation = StackOrientation.Horizontal,
                    Children    =
                    {
                        label,
                        entry
                    }
                };
                layout.Parent               = cell;
                layout.BindingContext       = entryCell;
                layout.MinimumHeightRequest = Forms.ConvertToScaledDP(pixelHeight);

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

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

                return(nativeView);
            }
            return(null);
        }
コード例 #10
0
        void Initialize(EvasObject parent)
        {
            _menu = new GenList(parent)
            {
                BackgroundColor = EColor.Transparent,
                Style           = "solid/default",
            };

            _menu.ItemSelected += (s, e) =>
            {
                MenuItemSelected?.Invoke(this, e);
            };

            _menu.Show();
            PackEnd(_menu);

            _defaultClass = new GenItemClass("double_label")
            {
                GetTextHandler = (obj, part) =>
                {
                    if (part == "elm.text")
                    {
                        return(((Item)obj).Title);
                    }
                    else
                    {
                        return(null);
                    }
                },
                GetContentHandler = (obj, part) =>
                {
                    if (part == "elm.swallow.icon")
                    {
                        var icon = ((Item)obj).Icon;

                        if (icon != null)
                        {
                            var image = new ElmSharp.Image(parent)
                            {
                                MinimumWidth  = Forms.ConvertToScaledPixel(24),
                                MinimumHeight = Forms.ConvertToScaledPixel(24)
                            };
                            var result = image.Load(ResourcePath.GetPath(icon));
                            return(image);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
            };
        }
コード例 #11
0
        EvasObject GetContent(object data, string part)
        {
            ShellSection section = data as ShellSection;

            var box = new EBox(Forms.NativeParent);

            box.Show();

            EImage icon = null;

            if (section.Icon != null)
            {
                icon = new EImage(Forms.NativeParent);
                icon.Show();
                box.PackEnd(icon);
                _ = icon.LoadFromImageSourceAsync(section.Icon);
            }

            var title = new Native.Label(Forms.NativeParent)
            {
                Text     = section.Title,
                FontSize = Forms.ConvertToEflFontPoint(14),
                HorizontalTextAlignment = Native.TextAlignment.Start,
                VerticalTextAlignment   = Native.TextAlignment.Center,
            };

            title.Show();
            box.PackEnd(title);
            int iconPadding = Forms.ConvertToScaledPixel(this.GetIconPadding());
            int iconSize    = Forms.ConvertToScaledPixel(this.GetIconSize());
            int cellHeight  = iconPadding * 2 + iconSize;

            box.SetLayoutCallback(() =>
            {
                var bound      = box.Geometry;
                int leftMargin = iconPadding;

                if (icon != null)
                {
                    var iconBound    = bound;
                    iconBound.X     += iconPadding;
                    iconBound.Y     += iconPadding;
                    iconBound.Width  = iconSize;
                    iconBound.Height = iconSize;
                    icon.Geometry    = iconBound;
                    leftMargin       = (2 * iconPadding + iconSize);
                }

                bound.X       += leftMargin;
                bound.Width   -= leftMargin;
                title.Geometry = bound;
            });

            box.MinimumHeight = cellHeight;
            return(box);
        }
コード例 #12
0
        void UpdateHorizontalScrollStep(bool initialize)
        {
            var step = Specific.GetHorizontalScrollStep(Element);

            if (initialize && step == -1)
            {
                return;
            }

            Control.HorizontalStepSize = step != -1 ? Forms.ConvertToScaledPixel(step) : _defaultHorizontalStepSize;
        }
コード例 #13
0
ファイル: BoxViewRenderer.cs プロジェクト: terrajobst/maui
        void OnRadiusUpdate(bool init)
        {
            int topLeft     = Forms.ConvertToScaledPixel(Element.CornerRadius.TopLeft);
            int topRight    = Forms.ConvertToScaledPixel(Element.CornerRadius.TopRight);
            int bottomLeft  = Forms.ConvertToScaledPixel(Element.CornerRadius.BottomLeft);
            int bottomRight = Forms.ConvertToScaledPixel(Element.CornerRadius.BottomRight);

            Control.SetRadius(topLeft, topRight, bottomLeft, bottomRight);
            if (!init)
            {
                Control.Draw();
            }
        }
コード例 #14
0
        static SKPath MakePath(EllipseGeometry ellipseGeometry)
        {
            var path = new SKPath();

            path.AddOval(new SKRect(
                             Forms.ConvertToScaledPixel(ellipseGeometry.Center.X - ellipseGeometry.RadiusX),
                             Forms.ConvertToScaledPixel(ellipseGeometry.Center.Y - ellipseGeometry.RadiusY),
                             Forms.ConvertToScaledPixel(ellipseGeometry.Center.X + ellipseGeometry.RadiusX),
                             Forms.ConvertToScaledPixel(ellipseGeometry.Center.Y + ellipseGeometry.RadiusY)),
                         SKPathDirection.Clockwise);

            return(path);
        }
コード例 #15
0
        static SKPath MakePath(LineGeometry lineGeometry)
        {
            var path = new SKPath();

            path.MoveTo(
                Forms.ConvertToScaledPixel(lineGeometry.StartPoint.X),
                Forms.ConvertToScaledPixel(lineGeometry.StartPoint.Y));

            path.LineTo(
                Forms.ConvertToScaledPixel(lineGeometry.EndPoint.X),
                Forms.ConvertToScaledPixel(lineGeometry.EndPoint.Y));

            return(path);
        }
コード例 #16
0
        static SKPath MakePath(RectangleGeometry rectangleGeometry)
        {
            var            path = new SKPath();
            FormsRectangle rect = rectangleGeometry.Rect;

            path.AddRect(new SKRect(
                             Forms.ConvertToScaledPixel(rect.Left),
                             Forms.ConvertToScaledPixel(rect.Top),
                             Forms.ConvertToScaledPixel(rect.Right),
                             Forms.ConvertToScaledPixel(rect.Bottom)),
                         SKPathDirection.Clockwise);

            return(path);
        }
コード例 #17
0
        void OnLayout()
        {
            var outter     = Control.Geometry;
            var width      = outter.Width - Forms.ConvertToScaledPixel(Element.Padding.HorizontalThickness);
            var height     = outter.Height - Forms.ConvertToScaledPixel(Element.Padding.VerticalThickness);
            var left       = outter.Left + Forms.ConvertToScaledPixel(Element.Padding.Left);
            var top        = outter.Top + Forms.ConvertToScaledPixel(Element.Padding.Top);
            var imageBound = new Rect(left, top, width, height);

            _image.Geometry  = imageBound;
            _button.Geometry = outter;
            _round.Draw(outter);
            _border.Draw(outter);
        }
コード例 #18
0
        void UpdateContentSize()
        {
            _scrollCanvas.MinimumWidth  = Forms.ConvertToScaledPixel(Element.ContentSize.Width + Element.Padding.HorizontalThickness);
            _scrollCanvas.MinimumHeight = Forms.ConvertToScaledPixel(Element.ContentSize.Height + Element.Padding.VerticalThickness);

            // elm-scroller updates the CurrentRegion after render
            Device.BeginInvokeOnMainThread(() =>
            {
                if (Control != null)
                {
                    OnScrolled(Control, EventArgs.Empty);
                }
            });
        }
コード例 #19
0
 void UpdateBorderWidth(bool init)
 {
     if (Element.BorderWidth > 0)
     {
         _border.BorderWidth = Forms.ConvertToScaledPixel(Element.BorderWidth);
     }
     else
     {
         _border.BorderWidth = 0;
     }
     if (!init)
     {
         _border.Draw();
     }
 }
コード例 #20
0
        protected override EvasObject OnReusableContent(Cell cell, string part, EvasObject old)
        {
            if (!_cacheCandidate.ContainsKey(old))
            {
                return(null);
            }

            var layout = _cacheCandidate[old];

            layout.BindingContext = cell;
            int height = Forms.ConvertToScaledPixel(cell.RenderHeight);

            height            = height > 0 ? height : Forms.ConvertToPixel(s_defaultHeight);
            old.MinimumHeight = height;
            return(old);
        }
コード例 #21
0
 void UpdateRadius(bool init)
 {
     if (Element.CornerRadius > 0)
     {
         _round.SetRadius(Forms.ConvertToScaledPixel(Element.CornerRadius));
         _border.SetRadius(Forms.ConvertToScaledPixel(Element.CornerRadius));
     }
     else
     {
         _round.SetRadius(0);
         _border.SetRadius(0);
     }
     if (!init)
     {
         _round.Draw();
         _border.Draw();
     }
 }
コード例 #22
0
        void UpdateContentSize()
        {
            if (_content == null)
            {
                return;
            }

            _content.MinimumWidth  = Forms.ConvertToScaledPixel(Element.ContentSize.Width);
            _content.MinimumHeight = Forms.ConvertToScaledPixel(Element.ContentSize.Height);

            // elm-scroller updates the CurrentRegion after render
            Device.BeginInvokeOnMainThread(() =>
            {
                if (Control != null)
                {
                    OnScrolled(Control, EventArgs.Empty);
                }
            });
        }
コード例 #23
0
ファイル: ItemsViewRenderer.cs プロジェクト: terrajobst/maui
        public static ICollectionViewLayoutManager ToLayoutManager(this IItemsLayout layout, ItemSizingStrategy sizing = ItemSizingStrategy.MeasureFirstItem)
        {
            switch (layout)
            {
            case LinearItemsLayout listItemsLayout:
                return(new LinearLayoutManager(listItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal, sizing, Forms.ConvertToScaledPixel(listItemsLayout.ItemSpacing)));

            case GridItemsLayout gridItemsLayout:
                return(new GridLayoutManager(gridItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal,
                                             gridItemsLayout.Span,
                                             sizing,
                                             Forms.ConvertToScaledPixel(gridItemsLayout.VerticalItemSpacing),
                                             Forms.ConvertToScaledPixel(gridItemsLayout.HorizontalItemSpacing)));

            default:
                break;
            }

            return(new LinearLayoutManager(false));
        }
コード例 #24
0
        void InitializeFlyout()
        {
            ((IShellController)Element).StructureChanged += OnShellStructureChanged;

            View flyoutHeader = ((IShellController)Element).FlyoutHeader;

            if (flyoutHeader != null)
            {
                var headerView = Platform.GetOrCreateRenderer(flyoutHeader);
                (headerView as LayoutRenderer)?.RegisterOnLayoutUpdated();

                Size request = flyoutHeader.Measure(Forms.ConvertToScaledDP(_native.NavigationView.MinimumWidth), Forms.ConvertToScaledDP(_native.NavigationView.MinimumHeight)).Request;
                headerView.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(request.Height);

                _native.NavigationView.Header = headerView.NativeView;
            }

            BuildMenu();
            _native.NavigationView.MenuItemSelected += OnItemSelected;
        }
コード例 #25
0
        EvasObject GetContent(object data, string part)
        {
            ShellSection section = data as ShellSection;

            var box = new Native.Box(Forms.NativeParent);

            box.Show();

            var icon = new Native.Image(Forms.NativeParent)
            {
                MinimumWidth  = Forms.ConvertToScaledPixel(44),
                MinimumHeight = Forms.ConvertToScaledPixel(27)
            };
            var task = icon.LoadFromImageSourceAsync(section.Icon);

            icon.Show();

            var title = new Native.Label(Forms.NativeParent)
            {
                Text     = section.Title,
                FontSize = Forms.ConvertToEflFontPoint(14),
                HorizontalTextAlignment = Native.TextAlignment.Start,
                VerticalTextAlignment   = Native.TextAlignment.Center
            };

            title.Show();

            box.PackEnd(icon);
            box.PackEnd(title);
            box.LayoutUpdated += (object sender, LayoutEventArgs e) =>
            {
                icon.Move(e.Geometry.X + _iconPadding, e.Geometry.Y + _iconPadding);
                icon.Resize(_iconSize, _iconSize);

                title.Move(e.Geometry.X + 2 * _iconPadding + _iconSize, e.Geometry.Y);
                title.Resize(e.Geometry.Width - (2 * _iconPadding + _iconSize), e.Geometry.Height);
            };
            box.MinimumHeight = _cellHeight;
            return(box);
        }
コード例 #26
0
        EvasObject CreateReusableContent(ViewCell viewCell)
        {
            var      listView       = viewCell.RealParent as ListView;
            ViewCell duplicatedCell = (ViewCell)listView.ItemTemplate.CreateContent();

            duplicatedCell.BindingContext = viewCell.BindingContext;
            duplicatedCell.Parent         = listView;

            var    renderer = Platform.GetOrCreateRenderer(duplicatedCell.View);
            double height   = duplicatedCell.RenderHeight;

            height = height > 0 ? height : FindCellContentHeight(duplicatedCell);
            renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(height);

            _cacheCandidate[renderer.NativeView] = duplicatedCell;
            renderer.NativeView.Deleted         += (sender, e) =>
            {
                _cacheCandidate.Remove((EvasObject)sender);
            };
            (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();

            return(renderer.NativeView);
        }
コード例 #27
0
 public static ESize ToPixel(this Size size)
 {
     return(new ESize(Forms.ConvertToScaledPixel(size.Width), Forms.ConvertToScaledPixel(size.Height)));
 }
コード例 #28
0
 public static int GetDefaultHeightPixel(this ImageCellRenderer imageCell)
 {
     return(Forms.ConvertToScaledPixel(ThemeConstants.ImageCell.Resources.DefaultHeight));
 }
コード例 #29
0
        void OnPromptRequested(Page sender, PromptArguments args)
        {
            // Verify that the page making the request is child of this platform
            if (!_platform.PageIsChildOfPlatform(sender))
            {
                return;
            }

            var prompt = Native.Dialog.CreateDialog(Forms.NativeParent, (args.Accept != null));

            prompt.Title = args.Title;

            var entry = new Entry
            {
                MinimumWidthRequest = 200,
                HorizontalOptions   = LayoutOptions.FillAndExpand,
                BackgroundColor     = Color.FromRgb(250, 250, 250),
                TextColor           = Color.Black,
                Keyboard            = args.Keyboard,
            };

            if (!string.IsNullOrEmpty(args.Placeholder))
            {
                entry.Placeholder = args.Placeholder;
            }
            if (args.MaxLength > 0)
            {
                entry.MaxLength = args.MaxLength;
            }

            var layout = new StackLayout
            {
                Spacing  = 10,
                Children =
                {
                    new Label
                    {
                        LineBreakMode           = LineBreakMode.CharacterWrap,
                        TextColor               = Device.Idiom == TargetIdiom.Watch ? Color.White : Color.Accent,
                        Text                    = args.Message,
                        HorizontalOptions       = LayoutOptions.FillAndExpand,
                        HorizontalTextAlignment = TextAlignment.Center,
                        FontSize                = Device.GetNamedSize(NamedSize.Subtitle, typeof(Label)),
                    },
                    entry,
                }
            };

            layout.Parent = sender;
            var layoutrenderer = Platform.GetOrCreateRenderer(layout);

            var request = layout.Measure(Device.Idiom == TargetIdiom.Watch ? sender.Width * 0.7 : sender.Width, sender.Height);

            (layoutrenderer as LayoutRenderer).RegisterOnLayoutUpdated();
            layoutrenderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(request.Request.Height);
            layoutrenderer.NativeView.MinimumWidth  = Forms.ConvertToScaledPixel(request.Request.Width);

            prompt.Content = layoutrenderer.NativeView;

            var cancel = new EButton(prompt)
            {
                Text = args.Cancel
            };

            prompt.NegativeButton = cancel;
            cancel.Clicked       += (s, evt) =>
            {
                args.SetResult(null);
                prompt.Dismiss();
            };

            if (args.Accept != null)
            {
                var ok = new EButton(prompt)
                {
                    Text = args.Accept
                };
                prompt.NeutralButton = ok;
                ok.Clicked          += (s, evt) =>
                {
                    args.SetResult(entry.Text);
                    prompt.Dismiss();
                };
            }

            entry.Completed += (s, e) =>
            {
                args.SetResult(entry.Text);
                prompt.Dismiss();
            };

            prompt.BackButtonPressed += (s, evt) =>
            {
                prompt.Dismiss();
            };

            prompt.Show();

            _alerts.Add(prompt);
            prompt.Dismissed += (s, e) => _alerts.Remove(prompt);
        }
コード例 #30
0
        void UpdateItems()
        {
            CurrentItems = GetSwipedItems();
            var itemsLayout = new StackLayout
            {
                Spacing       = 0,
                Orientation   = IsHorizontalSwipe ? StackOrientation.Horizontal : StackOrientation.Vertical,
                FlowDirection = SwipeDirection == SwipeDirection.Left ? FlowDirection.RightToLeft : FlowDirection.LeftToRight
            };

            foreach (var item in CurrentItems)
            {
                View itemView = null;
                if (item is SwipeItem switem)
                {
                    itemView = CreateItemView(switem, !IsHorizontalSwipe);
                }
                else if (item is SwipeItemView customItem)
                {
                    itemView = CreateItemView(customItem);
                }
                else
                {
                    continue;
                }

                var tap = new TapGestureRecognizer();
                tap.Command          = item.Command;
                tap.CommandParameter = item.CommandParameter;
                tap.Tapped          += (s, e) =>
                {
                    if (item is SwipeItem swipeItem)
                    {
                        swipeItem.OnInvoked();
                    }

                    if (item is SwipeItemView customSwipeItem)
                    {
                        customSwipeItem.OnInvoked();
                    }

                    if (CurrentItems.SwipeBehaviorOnInvoked != SwipeBehaviorOnInvoked.RemainOpen)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            _ = SwipeCloseAsync();
                        });
                    }
                };
                itemView.GestureRecognizers.Add(tap);

                if (IsHorizontalSwipe)
                {
                    itemView.HorizontalOptions = LayoutOptions.Start;
                    itemView.VerticalOptions   = LayoutOptions.FillAndExpand;
                }
                else
                {
                    itemView.VerticalOptions   = LayoutOptions.Start;
                    itemView.HorizontalOptions = LayoutOptions.FillAndExpand;
                }
                itemsLayout.Children.Add(itemView);
            }

            var itemsRenderer = Platform.GetOrCreateRenderer(itemsLayout);

            (itemsRenderer as LayoutRenderer)?.RegisterOnLayoutUpdated();
            var measured = itemsLayout.Measure(Element.Width, Element.Height);

            MaximumSwipeSize = Forms.ConvertToScaledPixel(
                IsHorizontalSwipe ?
                Math.Min(measured.Request.Width, Element.Width) :
                Math.Min(measured.Request.Height, Element.Height));

            Control.Children.Add(itemsRenderer.NativeView);

            var itemsGeometry = NativeView.Geometry;

            if (SwipeDirection == SwipeDirection.Up)
            {
                itemsGeometry.Y += (itemsGeometry.Height - MaximumSwipeSize);
            }
            itemsRenderer.NativeView.Geometry = itemsGeometry;
            itemsRenderer.NativeView.StackBelow(Platform.GetRenderer(SwipeView.Content).NativeView);

            _itemsRenderer = itemsRenderer;
        }