Beispiel #1
0
        public void TestVisibility()
        {
            View child1, child2;
            var  stack = new StackLayout
            {
                IsPlatformEnabled = true,
                Children          =
                {
                    (child1               = new View {
                        IsPlatformEnabled = true
                    }),
                    (child2               = new View {
                        IsPlatformEnabled = true
                    })
                }
            };

            stack.Layout(new Rectangle(0, 0, 100, 100));

            var size = stack.Measure(double.PositiveInfinity, double.PositiveInfinity).Request;

            Assert.AreEqual(new Rectangle(0, 0, 100, 20), child1.Bounds);
            Assert.AreEqual(new Rectangle(0, 26, 100, 20), child2.Bounds);
            Assert.AreEqual(new Size(100, 46), size);

            child1.IsVisible = false;
            Assert.False(child1.IsVisible);
            Assert.AreEqual(new Rectangle(0, 0, 100, 20), child2.Bounds);
            size = stack.Measure(double.PositiveInfinity, double.PositiveInfinity).Request;
            Assert.AreEqual(new Size(100, 20), size);
        }
Beispiel #2
0
        void UpdateContent()
        {
            if (!XForms.IsInitialized)
            {
                Log.Debug(FormsCircularUI.Tag, "Tizen Forms is not initialized");
                return;
            }

            _contentView.Children.Clear();
            if (Content != null)
            {
                _contentView.Children.Add(Content);

                var renderer = Xamarin.Forms.Platform.Tizen.Platform.GetOrCreateRenderer(_contentView);
                (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();
                var sizeRequest = _contentView.Measure(XForms.NativeParent.Geometry.Width, XForms.NativeParent.Geometry.Height).Request.ToPixel();

                _nativeContent = renderer.NativeView;
                _nativeContent.MinimumHeight = sizeRequest.Height;

                _layout.SetPartContent("elm.swallow.content", _nativeContent, true);
            }
            else
            {
                _layout.SetPartContent("elm.swallow.content", null, true);
            }
        }
        void UpdateContent()
        {
            if (Application.Current.Platform == null)
            {
                return;
            }

            _contentView.Children.Clear();

            if (Content != null)
            {
                _contentView.Children.Add(Content);

                _contentView.Platform = Application.Current.Platform;

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

                var sizeRequest = _contentView.Measure(TForms.NativeParent.Geometry.Width, TForms.NativeParent.Geometry.Height).Request.ToPixel();

                _nativeContent = renderer.NativeView;
                _nativeContent.MinimumHeight = sizeRequest.Height;

                _control.SetPartContent("default", _nativeContent, true);
            }
            else
            {
                _control.SetPartContent("default", null, true);
            }
        }
        public void ReinflatesViewsCorrectly()
        {
            var child1 = new BoxView
            {
                IsPlatformEnabled    = true,
                VerticalOptions      = LayoutOptions.FillAndExpand,
                HeightRequest        = 400,
                MinimumHeightRequest = 10
            };

            var child2 = new BoxView
            {
                IsPlatformEnabled    = true,
                HeightRequest        = 40,
                MinimumHeightRequest = 40
            };

            var stack = new StackLayout
            {
                Spacing           = 0,
                IsPlatformEnabled = true,
                Children          = { child1, child2 }
            };

            stack.Layout(new Rectangle(0, 0, 100, 100));

            Assert.AreEqual(new Rectangle(0, 0, 100, 60), child1.Bounds);
            Assert.AreEqual(new Rectangle(0, 60, 100, 40), child2.Bounds);

            stack.Measure(100, 100);
            stack.Layout(new Rectangle(0, 0, 100, 500));

            Assert.AreEqual(new Rectangle(0, 0, 100, 460), child1.Bounds);
            Assert.AreEqual(new Rectangle(0, 460, 100, 40), child2.Bounds);
        }
        public void GetMinimumSizeHorizontal()
        {
            var stack = new StackLayout
            {
                IsPlatformEnabled = true,
                Spacing           = 10,
                Orientation       = StackOrientation.Horizontal,
                Children          =
                {
                    new View {
                        WidthRequest = 100, HeightRequest = 100, IsPlatformEnabled = true
                    },
                    new View {
                        WidthRequest = 100, HeightRequest = 100, IsPlatformEnabled = true
                    },
                    new View {
                        WidthRequest = 100, HeightRequest = 100, MinimumWidthRequest = 10, IsPlatformEnabled = true
                    }
                }
            };

            var result = stack.Measure(double.PositiveInfinity, double.PositiveInfinity);

            Assert.That(result.Minimum, Is.EqualTo(new Size(230, 100)));
        }
        public void TestVisibility()
        {
            View child1, child2;
            var  stack = new StackLayout
            {
                IsPlatformEnabled = true,
                Children          =
                {
                    (child1               = new View {
                        IsPlatformEnabled = true
                    }),
                    (child2               = new View {
                        IsPlatformEnabled = true
                    })
                }
            };

            var handler = Substitute.For <IViewHandler>();

            stack.Handler = handler;

            stack.Layout(new Rectangle(0, 0, 100, 100));

            var size = stack.Measure(double.PositiveInfinity, double.PositiveInfinity).Request;

            Assert.AreEqual(new Rectangle(0, 0, 100, 20), child1.Bounds);
            Assert.AreEqual(new Rectangle(0, 26, 100, 20), child2.Bounds);
            Assert.AreEqual(new Size(100, 46), size);

            child1.IsVisible = false;

            // Verify that the visibility change invalidated the layout, and simulate a native layout update
            AssertInvalidated(handler);
            stack.ForceLayout();

            Assert.False(child1.IsVisible);
            Assert.AreEqual(new Rectangle(0, 0, 100, 20), child2.Bounds);
            size = stack.Measure(double.PositiveInfinity, double.PositiveInfinity).Request;
            Assert.AreEqual(new Size(100, 20), size);
        }
        public void TestSizeRequestVertical()
        {
            var stack = new StackLayout
            {
                IsPlatformEnabled = true,
                Children          =
                {
                    new View {
                        WidthRequest = 20, HeightRequest = 20, IsPlatformEnabled = true
                    },
                    new View {
                        WidthRequest = 30, HeightRequest = 30, IsPlatformEnabled = true
                    }
                }
            };

            var size = stack.Measure(double.PositiveInfinity, double.PositiveInfinity).Request;

            Assert.AreEqual(new Size(30, 56), size);
        }
        public void OffOrientationMinimumSize()
        {
            var stack = new StackLayout
            {
                IsPlatformEnabled = true,
                Spacing           = 0
            };

            stack.Children.Add(new View
            {
                IsPlatformEnabled    = true,
                WidthRequest         = 100,
                HeightRequest        = 100,
                MinimumWidthRequest  = 10,
                MinimumHeightRequest = 10
            });

            var result = stack.Measure(double.PositiveInfinity, double.PositiveInfinity);

            Assert.AreEqual(new Size(10, 10), result.Minimum);
        }
        public void TestLastChildNotVisible()
        {
            View child1, child2;
            var  stack = new StackLayout
            {
                IsPlatformEnabled = true,
                Children          =
                {
                    (child1          = new View {
                        WidthRequest =          20, HeightRequest = 20, IsPlatformEnabled = true
                    }),
                    (child2          = new View {
                        WidthRequest = 30, HeightRequest = 30, IsPlatformEnabled = true, IsVisible = false
                    })
                }
            };

            var r = stack.Measure(100, 100);

            Assert.AreEqual(new SizeRequest(new Size(20, 20)), r);
        }
        public void TestSizeRequestHorizontal()
        {
            var stack = new StackLayout
            {
                Orientation       = StackOrientation.Horizontal,
                IsPlatformEnabled = true,
                Children          =
                {
                    new View {
                        WidthRequest = 20, HeightRequest = 20, IsPlatformEnabled = true
                    },
                    new View {
                        WidthRequest = 30, HeightRequest = 30, IsPlatformEnabled = true
                    }
                }
            };

            var size = stack.Measure(double.PositiveInfinity, double.PositiveInfinity).Request;

            Assert.AreEqual(new Size(56, 30), size);
        }
Beispiel #11
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;
        }
Beispiel #12
0
        public GateGridView(string pageNumber, int numberOfPages)
        {
            _contentTitle = pageNumber;

            var lanesLabel = new Label
            {
                Text  = "Lanes",
                Style = StylesConstants.LabelStyle
            };

            _lanesButton = new Button
            {
                Image = "Road",
                Style = StylesConstants.ButtonStyle
            };
            _lanesButton.Clicked += OnLanesButtonClicked;

            var aboutLabel = new Label
            {
                Text  = "About",
                Style = StylesConstants.LabelStyle,
            };

            _aboutButton = new Button
            {
                Image = "About",
                Style = StylesConstants.ButtonStyle,
            };
            _aboutButton.Clicked += OnAboutButtonClicked;

            var titleLabel = new Label
            {
                Text  = $"{pageNumber} of {numberOfPages}",
                Style = StylesConstants.LabelStyle
            };

            var enableSwitchText = new Label
            {
                Text  = "Disable Buttons",
                Style = StylesConstants.LabelStyle
            };
            var enableSwitchButton = new Switch
            {
                Style = StylesConstants.ButtonStyle
            };

            enableSwitchButton.Toggled += ToggleAllButtons;

            var switchStackHorizontal = new StackLayout
            {
                Style       = StylesConstants.StackLayoutStyle,
                Orientation = StackOrientation.Horizontal,
                Children    =
                {
                    enableSwitchText,
                    enableSwitchButton
                }
            };

            var mainRelativeLayout = new RelativeLayout();

            Func <RelativeLayout, double> getswitchStackHorizonalWidth = (p) => switchStackHorizontal.Measure(p.Width, p.Height).Request.Width;
            Func <RelativeLayout, double> getTitleLabelWidth           = (p) => titleLabel.Measure(p.Width, p.Height).Request.Width;

            mainRelativeLayout.Children.Add(lanesLabel,
                                            Constraint.RelativeToParent((parent) => parent.Width / 8),
                                            Constraint.RelativeToParent((parent) => parent.Y + relativeLayoutPadding),
                                            Constraint.RelativeToParent((parent) => parent.Width / 4));
            mainRelativeLayout.Children.Add(_lanesButton,
                                            Constraint.RelativeToParent((parent) => parent.Width / 8),
                                            Constraint.RelativeToView(lanesLabel, (parent, view) => view.Y + view.Height + relativeLayoutPadding),
                                            Constraint.RelativeToParent((parent) => parent.Width / 4),
                                            Constraint.Constant(100));
            mainRelativeLayout.Children.Add(aboutLabel,
                                            Constraint.RelativeToParent((parent) => parent.Width * 5 / 8),
                                            Constraint.RelativeToParent((parent) => parent.Y + relativeLayoutPadding),
                                            Constraint.RelativeToParent((parent) => parent.Width / 4));
            mainRelativeLayout.Children.Add(_aboutButton,
                                            Constraint.RelativeToParent((parent) => parent.Width * 5 / 8),
                                            Constraint.RelativeToView(lanesLabel, (parent, view) => view.Y + view.Height + relativeLayoutPadding),
                                            Constraint.RelativeToParent((parent) => parent.Width / 4),
                                            Constraint.Constant(100));
            mainRelativeLayout.Children.Add(switchStackHorizontal,
                                            Constraint.RelativeToParent((parent) => parent.Width / 2 - getswitchStackHorizonalWidth(parent) / 2),
                                            Constraint.RelativeToView(_lanesButton, (parent, view) => view.Y + view.Height + relativeLayoutPadding * 4));
            mainRelativeLayout.Children.Add(titleLabel,
                                            Constraint.RelativeToParent((parent) => parent.Width / 2 - getTitleLabelWidth(parent) / 2),
                                            Constraint.RelativeToView(switchStackHorizontal, (parent, view) => view.Y + view.Height + relativeLayoutPadding * 4));

            Content = mainRelativeLayout;
        }
Beispiel #13
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               = DeviceInfo.Idiom == DeviceIdiom.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(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);
        }
        //Button icons provided by www.flaticon.com
        public GateGridView(string pageNumber, int numberOfPages)
        {
            //Initialie the ContentTitle field
            ContentTitle = pageNumber;
            #region Create the Lanes Controls
            var lanesLabel = new Label
            {
                Text  = "Lanes",
                Style = StylesConstants.LabelStyle
            };

            LanesButton = new Button
            {
                Image = "Road",
                Style = StylesConstants.ButtonStyle
            };

            LanesButton.Clicked += OnLanesButtonClick;
            #endregion

            #region Create the About Controls
            var aboutLabel = new Label
            {
                Text  = "About",
                Style = StylesConstants.LabelStyle,
            };

            AboutButton = new Button
            {
                Image = "About",
                Style = StylesConstants.ButtonStyle,
            };
            AboutButton.Clicked += OnAboutButtonClick;

            #endregion

            var titleLabel = new Label
            {
                Text  = $"{pageNumber} of {numberOfPages}",
                Style = StylesConstants.LabelStyle
            };

            #region Create Enable Button
            var enableSwitchText = new Label
            {
                Text  = "Disable Buttons",
                Style = StylesConstants.LabelStyle
            };
            var enableSwitchButton = new Switch
            {
                Style = StylesConstants.ButtonStyle
            };
            enableSwitchButton.Toggled += ToggleAllButtons;

            var switchStackHorizontal = new StackLayout
            {
                Style       = StylesConstants.StackLayoutStyle,
                Orientation = StackOrientation.Horizontal,
                Children    =
                {
                    enableSwitchText,
                    enableSwitchButton
                }
            };
            #endregion

            #region Create the Relative Layout
            var mainRelativeLayout = new RelativeLayout();

            Func <RelativeLayout, double> getswitchStackHorizonalWidth = (p) => switchStackHorizontal.Measure(mainRelativeLayout.Width, mainRelativeLayout.Height).Request.Width;
            Func <RelativeLayout, double> getTitleLabelWidth           = (p) => titleLabel.Measure(mainRelativeLayout.Width, mainRelativeLayout.Height).Request.Width;

            mainRelativeLayout.Children.Add(lanesLabel,
                                            Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width / 8);
            }),
                                            Constraint.RelativeToParent((parent) =>
            {
                return(parent.Y + relativeLayoutPadding);
            }),
                                            Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width / 4);
            })
                                            );
            mainRelativeLayout.Children.Add(LanesButton,
                                            Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width / 8);
            }),
                                            Constraint.RelativeToView(lanesLabel, (parent, view) =>
            {
                return(view.Y + view.Height + relativeLayoutPadding);
            }),
                                            Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width / 4);
            }),
                                            Constraint.Constant(100)
                                            );
            mainRelativeLayout.Children.Add(aboutLabel,
                                            Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width * 5 / 8);
            }),
                                            Constraint.RelativeToParent((parent) =>
            {
                return(parent.Y + relativeLayoutPadding);
            }),
                                            Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width / 4);
            })
                                            );
            mainRelativeLayout.Children.Add(AboutButton,
                                            Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width * 5 / 8);
            }),
                                            Constraint.RelativeToView(lanesLabel, (parent, view) =>
            {
                return(view.Y + view.Height + relativeLayoutPadding);
            }),
                                            Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width / 4);
            }),
                                            Constraint.Constant(100)
                                            );
            mainRelativeLayout.Children.Add(switchStackHorizontal,
                                            Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width / 2 - getswitchStackHorizonalWidth(parent) / 2);
            }),
                                            Constraint.RelativeToView(LanesButton, (parent, view) =>
            {
                return(view.Y + view.Height + relativeLayoutPadding * 4);
            })
                                            );

            mainRelativeLayout.Children.Add(titleLabel,
                                            Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width / 2 - getTitleLabelWidth(parent) / 2);
            }),
                                            Constraint.RelativeToView(switchStackHorizontal, (parent, view) =>
            {
                return(view.Y + view.Height + relativeLayoutPadding * 4);
            })
                                            );
            #endregion

            Content = mainRelativeLayout;
        }
Beispiel #15
0
        public AddInspectionView()
        {
            const string titleText        = "New Inspection";
            const string bodyText         = "Title of Inspection";
            const string submitButtonText = "Submit";

            _backgroundOverlayBoxView = new BoxView
            {
                BackgroundColor = _whiteWith75Opacity
            };
            _backgroundOverlayBoxView.Opacity = 0;

            _overlayFrame = new Frame
            {
                HasShadow       = true,
                BackgroundColor = Color.White
            };
            _overlayFrame.Scale = 0;

            var titleLabel = new Label
            {
                FontAttributes          = FontAttributes.Bold,
                Text                    = titleText,
                HorizontalTextAlignment = TextAlignment.Center,
            };

            _titleEntry = new Entry
            {
                Placeholder = "Title"
            };
            _titleEntry.SetBinding(Entry.TextProperty, nameof(ViewModel.TitleEntryText));

            var submitButton = new Button
            {
                BackgroundColor = _blackWith75PercentOpacity,
                TextColor       = Color.White,
                BorderWidth     = 1,
                BorderColor     = _blackWith75PercentOpacity,
                FontAttributes  = FontAttributes.Bold,
                Margin          = new Thickness(5),
                Text            = submitButtonText
            };

            submitButton.SetBinding(Button.CommandProperty, nameof(ViewModel.SubmitButtonCommand));
            submitButton.Clicked += (sender, e) => DismissView();

            _textEntryButtonStack = new StackLayout
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Spacing           = 20,
                Children          =
                {
                    titleLabel,
                    _titleEntry,
                    submitButton
                }
            };
            _textEntryButtonStack.Scale = 0;

            _relativeLayout = new RelativeLayout();
            Func <RelativeLayout, double> gettextAndButtonStackHeight = (p) => _textEntryButtonStack.Measure(_relativeLayout.Width, _relativeLayout.Height).Request.Height;
            Func <RelativeLayout, double> gettextAndButtonStackWidth  = (p) => _textEntryButtonStack.Measure(_relativeLayout.Width, _relativeLayout.Height).Request.Width;


            _relativeLayout.Children.Add(_backgroundOverlayBoxView,
                                         Constraint.Constant(-10),
                                         Constraint.Constant(0),
                                         Constraint.RelativeToParent(parent => parent.Width + 20),
                                         Constraint.RelativeToParent(parent => parent.Height)
                                         );
            _relativeLayout.Children.Add(_overlayFrame,
                                         Constraint.RelativeToParent(parent => parent.Width / 2 - gettextAndButtonStackWidth(parent) / 2 - 20),
                                         Constraint.RelativeToParent(parent => parent.Y + 20),
                                         Constraint.RelativeToParent(parent => gettextAndButtonStackWidth(parent) + 30),
                                         Constraint.RelativeToParent(parent => gettextAndButtonStackHeight(parent) + 30)
                                         );

            _relativeLayout.Children.Add(_textEntryButtonStack,
                                         Constraint.RelativeToView(_overlayFrame, (parent, view) => view.X + 15),
                                         Constraint.RelativeToView(_overlayFrame, (parent, view) => view.Y + 15)
                                         );

            if (Device.RuntimePlatform == Device.Android)
            {
                _overlayFrame.IsVisible = false;
                _textEntryButtonStack.BackgroundColor = _whiteWith75Opacity;
            }

            Content = _relativeLayout;
        }
Beispiel #16
0
        public WelcomeView()
        {
            const string titleText    = "Welcome";
            const string bodyText     = "Enjoy InvestmentDataSampleApp";
            const string okButtonText = "Ok, thanks!";

            _backgroundOverlayBoxView = new BoxView
            {
                BackgroundColor = ColorConstants.WhiteWith75Opacity
            };
            _backgroundOverlayBoxView.Opacity = 0;

            _overlayFrame = new Frame
            {
                HasShadow       = true,
                BackgroundColor = Color.White
            };
            _overlayFrame.Scale = 0;

            var titleLabel = new Label
            {
                FontAttributes          = FontAttributes.Bold,
                Text                    = titleText,
                HorizontalTextAlignment = TextAlignment.Center,
                AutomationId            = AutomationIdConstants.WelcomeViewTitleLabel
            };

            var bodyLabel = new Label
            {
                Text = bodyText,
                HorizontalTextAlignment = TextAlignment.Center,
                AutomationId            = AutomationIdConstants.WelcomeViewBodyLabel
            };

            var okButton = new Button
            {
                Style          = StyleConstants.WelcomeViewButtonStyle,
                TextColor      = Color.White,
                FontAttributes = FontAttributes.Bold,
                Margin         = new Thickness(5),
                Text           = okButtonText,
                AutomationId   = AutomationIdConstants.WelcomeViewOkButton
            };

            okButton.SetBinding <OpportunitiesViewModel>(Button.CommandProperty, vm => vm.OkButtonTapped);

            _textAndButtonStack = new StackLayout
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Spacing           = 20,
                Children          =
                {
                    titleLabel,
                    bodyLabel,
                    okButton
                }
            };
            _textAndButtonStack.Scale = 0;

            _relativeLayout = new RelativeLayout();
            Func <RelativeLayout, double> gettextAndButtonStackHeight = (p) => _textAndButtonStack.Measure(_relativeLayout.Width, _relativeLayout.Height).Request.Height;
            Func <RelativeLayout, double> gettextAndButtonStackWidth  = (p) => _textAndButtonStack.Measure(_relativeLayout.Width, _relativeLayout.Height).Request.Width;


            _relativeLayout.Children.Add(_backgroundOverlayBoxView,
                                         Constraint.Constant(-10),
                                         Constraint.Constant(0),
                                         Constraint.RelativeToParent(parent => parent.Width + 20),
                                         Constraint.RelativeToParent(parent => parent.Height)
                                         );
            _relativeLayout.Children.Add(_overlayFrame,
                                         Constraint.RelativeToParent(parent => parent.Width / 2 - gettextAndButtonStackWidth(parent) / 2 - 20),
                                         Constraint.RelativeToParent(parent => parent.Height / 2 - gettextAndButtonStackHeight(parent) / 2 - 10),
                                         Constraint.RelativeToParent(parent => gettextAndButtonStackWidth(parent) + 30),
                                         Constraint.RelativeToParent(parent => gettextAndButtonStackHeight(parent) + 30)
                                         );

            _relativeLayout.Children.Add(_textAndButtonStack,
                                         Constraint.RelativeToView(_overlayFrame, (parent, view) => view.X + 15),
                                         Constraint.RelativeToView(_overlayFrame, (parent, view) => view.Y + 15)
                                         );

            if (Device.OS == TargetPlatform.Android)
            {
                _overlayFrame.IsVisible             = false;
                _textAndButtonStack.BackgroundColor = ColorConstants.WhiteWith90Opacity;
            }

            Content = _relativeLayout;
        }