Exemplo n.º 1
0
        public override EvasObject CreateNativeView(int index, EvasObject parent)
        {
            View emptyView = null;

            if (ItemTemplate is DataTemplateSelector selector)
            {
                emptyView = selector.SelectTemplate(this[index], Element).CreateContent() as View;
            }
            else
            {
                emptyView = ItemTemplate.CreateContent() as View;
            }

            var header = CreateHeaderView();
            var footer = CreateFooterView();
            var layout = new XStackLayout();

            if (header != null)
            {
                layout.Children.Add(header);
            }
            layout.Children.Add(emptyView);
            if (footer != null)
            {
                layout.Children.Add(footer);
            }

            layout.Parent = Element;
            var renderer = Platform.GetOrCreateRenderer(layout);

            (renderer as ILayoutRenderer)?.RegisterOnLayoutUpdated();
            return(renderer.NativeView);
        }
Exemplo n.º 2
0
        static View CreateItemView(SwipeItem item, bool horizontal)
        {
            var image = new Image
            {
                Source = item.IconImageSource
            };
            var label = new Label
            {
                Text = item.Text,
                HorizontalTextAlignment = TextAlignment.Center,
#pragma warning disable CS0612 // Type or member is obsolete
                FontSize = Device.GetNamedSize(NamedSize.Default, typeof(Label)),
#pragma warning disable CS0612 // Type or member is obsolete
            };

            if (horizontal)
            {
                image.VerticalOptions   = LayoutOptions.Fill;
                image.HorizontalOptions = LayoutOptions.Start;

                label.VerticalOptions       = LayoutOptions.Center;
                label.HorizontalOptions     = LayoutOptions.Center;
                label.VerticalTextAlignment = TextAlignment.Center;
#pragma warning disable CS0612 // Type or member is obsolete
                label.FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label));
#pragma warning disable CS0612 // Type or member is obsolete
            }
            else
            {
                image.VerticalOptions   = LayoutOptions.Fill;
                image.HorizontalOptions = LayoutOptions.Fill;

                label.VerticalOptions       = LayoutOptions.End;
                label.HorizontalOptions     = LayoutOptions.Center;
                label.VerticalTextAlignment = TextAlignment.End;
            }

            var layout = new XStackLayout
            {
                Padding         = 5,
                BackgroundColor = item.BackgroundColor,
                VerticalOptions = LayoutOptions.Fill,
                Orientation     = horizontal ? StackOrientation.Horizontal : StackOrientation.Vertical,
                Children        =
                {
                    image,
                    label
                }
            };
            if (horizontal)
            {
                layout.HeightRequest = SwipeItemHeight;
            }
            else
            {
                layout.WidthRequest = SwipeItemWidth;
            }
            return(layout);
        }
Exemplo n.º 3
0
        protected override void Init()
        {
            var span = new Span
            {
                Text =
                    " Mi augue molestie ligula lobortis enim Velit, in. \n Imperdiet eu dignissim odio. Massa erat Hac inceptos facilisis nibh " +
                    " Interdum massa Consectetuer risus sociis molestie facilisi enim. Class gravida. \n Gravida sociosqu cras Quam velit, suspendisse" +
                    "  leo auctor odio integer primis dui potenti dolor faucibus augue justo morbi ornare sem. "
            };

            var formattedString = new FormattedString();

            formattedString.Spans.Add(span);

            var label = new Microsoft.Maui.Controls.Label
            {
                LineBreakMode   = LineBreakMode.TailTruncation,
                VerticalOptions = LayoutOptions.Start,
                FormattedText   = formattedString,
                MaxLines        = 3
                                  //max line is less than the text reproduce and textViewExtensions couldn't identify when
                                  //it's already pass the MaxLines range because of the paragraph('\n' character).
            };

            var labelDescription = new Label
            {
                Text            = "If you opened this page, the app didn't crash and you can read three lines in the label above, this test has passed",
                VerticalOptions = LayoutOptions.StartAndExpand
            };

            var layout = new Microsoft.Maui.Controls.StackLayout();

            layout.Children.Add(label);
            layout.Children.Add(labelDescription);

            Content = layout;
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        void UpdateItems()
        {
            CurrentItems = GetSwipedItems();
            var itemsLayout = new XStackLayout
            {
                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 ISwipeItem swipeItem)
                    {
                        swipeItem.OnInvoked();
                    }

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

                    if (CurrentItems.SwipeBehaviorOnInvoked != SwipeBehaviorOnInvoked.RemainOpen)
                    {
                        Application.Current.Dispatcher.Dispatch(() =>
                        {
                            _ = SwipeCloseAsync();
                        });
                    }
                };
                itemView.GestureRecognizers.Add(tap);

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

            var itemsRenderer = Platform.GetOrCreateRenderer(itemsLayout);

            (itemsRenderer as ILayoutRenderer)?.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;
        }
Exemplo n.º 6
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.Fill,
                BackgroundColor     = Color.FromRgb(250, 250, 250),
                TextColor           = Color.FromRgb(0, 0, 0),
                Keyboard            = args.Keyboard,
            };

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

            var layout = new XStackLayout
            {
                Spacing  = 10,
                Children =
                {
                    new Label
                    {
                        LineBreakMode           = LineBreakMode.CharacterWrap,
                        TextColor               = DeviceInfo.Idiom == DeviceIdiom.Watch ? Color.FromRgb(255, 255, 255) : Application.AccentColor,
                        Text                    = args.Message,
                        HorizontalOptions       = LayoutOptions.Fill,
                        HorizontalTextAlignment = TextAlignment.Center,
#pragma warning disable CS0612 // Type or member is obsolete
                        FontSize = Device.GetNamedSize(NamedSize.Subtitle, typeof(Label)),
#pragma warning disable CS0612 // Type or member is obsolete
                    },
                    entry,
                }
            };

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

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

            (layoutrenderer as ILayoutRenderer).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);
        }