void SetupToolbarCustomization(Page lastPage)
        {
            if (lastPage != null && _titleViewLayout != null)
            {
                UpdateTitleViewLayout(lastPage, _titleViewLayout, _titleTextView, _subTitleTextView, _originalDrawable);

                UpdateTitleViewLayoutBackground(_titleViewLayout, CustomNavigationPage.GetTitleBackground(lastPage), _originalToolbarBackground);


                UpdateToolbarTitle(lastPage, _titleTextView, _subTitleTextView, _originalFont, _originalColorStateList);

                UpdateToolbarStyle(_toolbar, lastPage, Context as Activity, _originalToolbarBackground, _originalWindowContent);
            }
        }
Beispiel #2
0
        void UpdateTitleViewLayout(Page lastPage, Android.Widget.LinearLayout titleViewLayout, AppCompatTextView titleTextView, AppCompatTextView subTitleTextView, Android.Graphics.Drawables.Drawable defaultBackground)
        {
            UpdateTitleViewLayoutAlignment(titleViewLayout, titleTextView, subTitleTextView, CustomNavigationPage.GetTitlePosition(lastPage));

            if (!string.IsNullOrEmpty(CustomNavigationPage.GetTitleBackground(lastPage)))
            {
                UpdateTitleViewLayoutBackground(titleViewLayout, CustomNavigationPage.GetTitleBackground(lastPage), defaultBackground);
            }
            else
            {
                _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage)));
            }

            UpdateTitleViewLayoutMargin(titleViewLayout, CustomNavigationPage.GetTitleMargin(lastPage));

            UpdateTitleViewLayoutPadding(titleViewLayout, CustomNavigationPage.GetTitlePadding(lastPage));
        }
Beispiel #3
0
        void SetupNavBar(CGSize size)
        {
            if (NavigationController != null && titleView != null)
            {
                var page = Element as Page;
                containerView.Frame = new CGRect(0, 0, size.Width, size.Height);


                titleView.Layer.BorderWidth = CustomNavigationPage.GetTitleBorderWidth(Element);

                titleView.Layer.CornerRadius = CustomNavigationPage.GetTitleBorderCornerRadius(Element);

                titleView.Layer.BorderColor = CustomNavigationPage.GetTitleBorderColor(Element)?.ToCGColor() ?? UIColor.Clear.CGColor;



                SetupTextFont(titleLabel, CustomNavigationPage.GetTitleFont(page), CustomNavigationPage.GetTitleColor(page));

                SetupBackground();

                if (!string.IsNullOrEmpty(CustomNavigationPage.GetTitleBackground(Element)))
                {
                    try
                    {
                        var image = UIImage.FromBundle(CustomNavigationPage.GetTitleBackground(Element));
                        titleView.Frame = new CGRect(titleView.Frame.X, titleView.Frame.Y, titleView.Frame.Width == 0 ? Math.Min(size.Width, image.Size.Width) : Math.Min(titleView.Frame.Width, image.Size.Width), titleView.Frame.Height == 0 ? Math.Min(size.Height, image.Size.Height) : Math.Min(titleView.Frame.Height, image.Size.Height));

                        titleView.BackgroundColor = UIColor.FromPatternImage(image);
                    }
                    catch (Exception ex)
                    {
                        titleView.BackgroundColor = CustomNavigationPage.GetTitleFillColor(Element)?.ToUIColor() ?? UIColor.Clear;
                    }
                }
                else
                {
                    titleView.BackgroundColor = CustomNavigationPage.GetTitleFillColor(Element)?.ToUIColor() ?? UIColor.Clear;
                }


                ParentViewController.NavigationItem.TitleView = containerView;
                ParentViewController.NavigationItem.TitleView.SetNeedsDisplay();
            }
        }
Beispiel #4
0
        private void LastPage_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            var lastPage = sender as Page;

            if (e.PropertyName == CustomNavigationPage.HasShadowProperty.PropertyName)
            {
                UpdateToolbarShadow(_toolbar, CustomNavigationPage.GetHasShadow(lastPage), Context as Activity, _originalWindowContent);
            }
            else if (e.PropertyName == CustomNavigationPage.TitleBackgroundProperty.PropertyName)
            {
                UpdateTitleViewLayoutBackground(_titleViewLayout, CustomNavigationPage.GetTitleBackground(lastPage), _originalDrawable);
            }
            else if (e.PropertyName == CustomNavigationPage.BarBackgroundProperty.PropertyName)
            {
                UpdateToolbarBackground(_toolbar, lastPage, Context as Activity, _originalToolbarBackground);
            }
            else if (e.PropertyName == CustomNavigationPage.GradientColorsProperty.PropertyName)
            {
                UpdateToolbarBackground(_toolbar, lastPage, Context as Activity, _originalToolbarBackground);
            }
            else if (e.PropertyName == CustomNavigationPage.GradientDirectionProperty.PropertyName)
            {
                UpdateToolbarBackground(_toolbar, lastPage, Context as Activity, _originalToolbarBackground);
            }
            else if (e.PropertyName == CustomNavigationPage.BarBackgroundOpacityProperty.PropertyName)
            {
                UpdateToolbarBackground(_toolbar, lastPage, Context as Activity, _originalToolbarBackground);
            }
            else if (e.PropertyName == CustomNavigationPage.TitleBorderCornerRadiusProperty.PropertyName)
            {
                _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage)));
            }
            else if (e.PropertyName == CustomNavigationPage.TitleBorderWidthProperty.PropertyName)
            {
                _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage)));
            }
            else if (e.PropertyName == CustomNavigationPage.TitleBorderColorProperty.PropertyName)
            {
                _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage)));
            }
            else if (e.PropertyName == CustomNavigationPage.TitleFillColorProperty.PropertyName)
            {
                _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage)));
            }
            else if (e.PropertyName == CustomNavigationPage.TitlePositionProperty.PropertyName)
            {
                UpdateTitleViewLayoutAlignment(_titleViewLayout, _titleTextView, _subTitleTextView, CustomNavigationPage.GetTitlePosition(lastPage));
                //UpdateTitleViewLayout(lastPage, _titleViewLayout, _titleTextView, _subTitleTextView, _originalDrawable);
            }
            else if (e.PropertyName == CustomNavigationPage.TitlePaddingProperty.PropertyName)
            {
                UpdateTitleViewLayoutPadding(_titleViewLayout, CustomNavigationPage.GetTitlePadding(lastPage));
            }
            else if (e.PropertyName == CustomNavigationPage.TitleMarginProperty.PropertyName)
            {
                UpdateTitleViewLayoutMargin(_titleViewLayout, CustomNavigationPage.GetTitleMargin(lastPage));
            }
            else if (e.PropertyName == CustomNavigationPage.TitleColorProperty.PropertyName)
            {
                UpdateToolbarTextColor(_titleTextView, CustomNavigationPage.GetTitleColor(lastPage), _originalColorStateList);
            }
            else if (e.PropertyName == CustomNavigationPage.TitleFontProperty.PropertyName)
            {
                UpdateToolbarTextFont(_titleTextView, CustomNavigationPage.GetTitleFont(lastPage), _originalFont);
            }
            else if (e.PropertyName == Page.TitleProperty.PropertyName)
            {
                UpdateTitleText(_titleTextView, lastPage.Title);
            }
            else if (e.PropertyName == CustomPage.FormattedTitleProperty.PropertyName && (lastPage is CustomPage))
            {
                var cPage = lastPage as CustomPage;
                UpdateFormattedTitleText(_titleTextView, cPage.FormattedTitle, cPage.Title);
            }
            else if (e.PropertyName == CustomNavigationPage.SubtitleColorProperty.PropertyName)
            {
                UpdateToolbarTextColor(_subTitleTextView, CustomNavigationPage.GetSubtitleColor(lastPage), _originalColorStateList);
            }
            else if (e.PropertyName == CustomNavigationPage.SubtitleFontProperty.PropertyName)
            {
                UpdateToolbarTextFont(_subTitleTextView, CustomNavigationPage.GetSubtitleFont(lastPage), _originalFont);
            }
            else if (e.PropertyName == CustomPage.SubtitleProperty.PropertyName && (lastPage is CustomPage))
            {
                var cPage = lastPage as CustomPage;
                if (!string.IsNullOrEmpty(cPage.Subtitle))
                {
                    _subTitleTextView.Text       = cPage.Subtitle;
                    _subTitleTextView.Visibility = ViewStates.Visible;
                }
                else
                {
                    ClearTextView(_subTitleTextView, true);
                }
            }
            else if (e.PropertyName == CustomPage.FormattedTitleProperty.PropertyName && (lastPage is CustomPage))
            {
                var cPage = lastPage as CustomPage;

                if (cPage.FormattedSubtitle != null && cPage.FormattedSubtitle.Spans.Count > 0)
                {
                    _subTitleTextView.TextFormatted = cPage.FormattedSubtitle.ToAttributed(Font.Default, Xamarin.Forms.Color.Default, _subTitleTextView);

                    _subTitleTextView.Visibility = ViewStates.Visible;
                }
                else
                {
                    ClearTextView(_subTitleTextView, true);
                }
            }
        }
Beispiel #5
0
        private void Element_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            var page = sender as Page;

            System.Diagnostics.Debug.WriteLine(e.PropertyName);
            if (e.PropertyName == Page.TitleProperty.PropertyName || e.PropertyName == CustomNavigationPage.TitleFontProperty.PropertyName || e.PropertyName == CustomPage.SubtitleProperty.PropertyName || e.PropertyName == CustomNavigationPage.SubtitleFontProperty.PropertyName)
            {
                SetupTextFont(titleLabel, CustomNavigationPage.GetTitleFont(page), CustomNavigationPage.GetTitleColor(page));

                SetTitlePosition(CustomNavigationPage.GetTitlePosition(page), CustomNavigationPage.GetTitlePadding(Element), CustomNavigationPage.GetTitleMargin(Element), new CGRect(0, 0, Math.Max(subtitleLabel.IntrinsicContentSize.Width, titleLabel.IntrinsicContentSize.Width), (titleLabel.IntrinsicContentSize.Height + subtitleLabel.IntrinsicContentSize.Height + (subtitleLabel.IntrinsicContentSize.Height > 0.0f ? 3.0f : 0.0f))));
            }
            else if (e.PropertyName == CustomNavigationPage.TitleColorProperty.PropertyName)
            {
                var color = CustomNavigationPage.GetTitleColor(page);
                if (color != null)
                {
                    titleLabel.TextColor = color?.ToUIColor();
                }
            }
            else if (e.PropertyName == CustomNavigationPage.SubtitleColorProperty.PropertyName)
            {
                var color = CustomNavigationPage.GetSubtitleColor(page);
                if (color != null)
                {
                    subtitleLabel.TextColor = color?.ToUIColor();
                }
            }
            else if (e.PropertyName == CustomNavigationPage.TitlePositionProperty.PropertyName || e.PropertyName == CustomNavigationPage.TitlePaddingProperty.PropertyName || e.PropertyName == CustomNavigationPage.TitleMarginProperty.PropertyName)
            {
                SetTitlePosition(CustomNavigationPage.GetTitlePosition(Element), CustomNavigationPage.GetTitlePadding(Element), CustomNavigationPage.GetTitleMargin(Element), new CGRect(0, 0, Math.Max(subtitleLabel.IntrinsicContentSize.Width, titleLabel.IntrinsicContentSize.Width), (titleLabel.IntrinsicContentSize.Height + subtitleLabel.IntrinsicContentSize.Height + (subtitleLabel.IntrinsicContentSize.Height > 0.0f ? 3.0f : 0.0f))));
            }
            else if (e.PropertyName == CustomNavigationPage.GradientColorsProperty.PropertyName || e.PropertyName == CustomNavigationPage.GradientDirectionProperty.PropertyName || e.PropertyName == CustomNavigationPage.BarBackgroundProperty.PropertyName || e.PropertyName == CustomNavigationPage.BarBackgroundOpacityProperty.PropertyName)
            {
                SetupBackground();
            }
            else if (e.PropertyName == CustomNavigationPage.HasShadowProperty.PropertyName)
            {
                SetupShadow(CustomNavigationPage.GetHasShadow(page));
            }
            else if (e.PropertyName == CustomPage.FormattedTitleProperty.PropertyName && (page is CustomPage))
            {
                var cPage = page as CustomPage;
                SetupFormattedText(titleLabel, cPage.FormattedTitle, cPage.Title);
            }
            else if (e.PropertyName == CustomNavigationPage.TitleBackgroundProperty.PropertyName)
            {
                if (!string.IsNullOrEmpty(CustomNavigationPage.GetTitleBackground(Element)))
                {
                    titleView.BackgroundColor = UIColor.FromPatternImage(UIImage.FromBundle(CustomNavigationPage.GetTitleBackground(Element)));
                }
                else
                {
                    titleView.BackgroundColor = null;
                }
            }
            else if (e.PropertyName == CustomNavigationPage.TitleBorderWidthProperty.PropertyName)
            {
                titleView.Layer.BorderWidth = CustomNavigationPage.GetTitleBorderWidth(Element);
            }
            else if (e.PropertyName == CustomNavigationPage.TitleBorderCornerRadiusProperty.PropertyName)
            {
                titleView.Layer.CornerRadius = CustomNavigationPage.GetTitleBorderCornerRadius(Element);
            }
            else if (e.PropertyName == CustomNavigationPage.TitleBorderColorProperty.PropertyName)
            {
                titleView.Layer.BorderColor = CustomNavigationPage.GetTitleBorderColor(Element)?.ToCGColor() ?? UIColor.Clear.CGColor;
            }
            else if (e.PropertyName == CustomNavigationPage.TitleFillColorProperty.PropertyName)
            {
                titleView.BackgroundColor = CustomNavigationPage.GetTitleFillColor(Element)?.ToUIColor() ?? UIColor.Clear;
            }
        }
Beispiel #6
0
        void SetTitlePosition(CustomNavigationPage.TitleAlignment alignment, Thickness padding, Thickness margin, CGRect vFrame)
        {
            var marginX       = margin.Top;
            var marginY       = margin.Left;
            var marginWidth   = margin.Left + margin.Right;
            var marginHeight  = margin.Top + margin.Bottom;
            var paddingWidth  = padding.Left + padding.Right;
            var paddingHeight = padding.Top + padding.Bottom;
            var paddingX      = padding.Left;
            var paddingY      = padding.Top;

            if (CustomNavigationPage.GetTitleBackground(Element) != null && vFrame.Width == 0 && vFrame.Height == 0)
            {
                vFrame = titleView.Frame;
            }


            marginView.Frame = new CGRect(vFrame.X, vFrame.Y, vFrame.Width, vFrame.Height);



            double offset = 0;

            titleLabel.AutoresizingMask = UIViewAutoresizing.All;
            switch (alignment)
            {
            case CustomNavigationPage.TitleAlignment.Start:
                marginView.Frame = new CGRect(vFrame.X, marginView.Frame.Y, marginView.Bounds.Width + marginWidth + paddingWidth, marginView.Bounds.Height + marginHeight + paddingHeight);
                var startCenter = marginView.Center;
                startCenter.Y               = marginView.Superview.Center.Y;
                marginView.Center           = startCenter;
                titleLabel.TextAlignment    = UITextAlignment.Left;
                subtitleLabel.TextAlignment = UITextAlignment.Left;
                offset = marginX;
                break;

            case CustomNavigationPage.TitleAlignment.Center:
                offset                      = marginX;
                marginView.Frame            = new CGRect(marginView.Frame.X, marginView.Frame.Y, marginView.Bounds.Width + marginWidth + paddingWidth, marginView.Bounds.Height + marginHeight + paddingHeight);
                marginView.Center           = marginView.Superview.Center;
                titleLabel.TextAlignment    = UITextAlignment.Center;
                subtitleLabel.TextAlignment = UITextAlignment.Center;
                break;

            case CustomNavigationPage.TitleAlignment.End:

                var endCenter = marginView.Center;
                endCenter.Y       = marginView.Superview.Center.Y;
                marginView.Center = endCenter;

                titleLabel.TextAlignment    = UITextAlignment.Right;
                subtitleLabel.TextAlignment = UITextAlignment.Right;
                marginView.Frame            = new CGRect(marginView.Superview.Frame.Width - marginView.Frame.Width - offset - marginWidth - paddingWidth, marginView.Frame.Y, marginView.Bounds.Width + marginWidth + paddingWidth, marginView.Bounds.Height + marginHeight + paddingHeight);
                offset = marginView.Frame.Width - vFrame.Width - paddingWidth - marginX;
                break;
            }

            titleView.Frame = new CGRect(offset, vFrame.Y + marginY, vFrame.Width + paddingWidth, vFrame.Height + paddingHeight);

            var cPage = Element as CustomPage;



            if (cPage != null && (!string.IsNullOrEmpty(cPage.Subtitle) || (cPage.FormattedSubtitle != null && cPage.FormattedSubtitle.Spans.Count > 0)))
            {
                titleLabel.Frame = new CGRect(paddingX, paddingY, titleView.Frame.Width, titleLabel.IntrinsicContentSize.Height);


                subtitleLabel.Frame = new CGRect(titleLabel.Frame.X, titleLabel.Frame.Y + titleLabel.Frame.Height + 3, titleView.Frame.Width, subtitleLabel.Frame.Height);
            }
            else
            {
                titleLabel.Frame = new CGRect(paddingX, paddingY, titleLabel.IntrinsicContentSize.Width, titleLabel.IntrinsicContentSize.Height);
            }
        }
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            var lastPage = Element.CurrentPage;

            if (e.PropertyName == CustomNavigationPage.HasShadowProperty.PropertyName)
            {
                UpdateToolbarShadow(_toolbar, CustomNavigationPage.GetHasShadow(lastPage), Context as Activity, _originalWindowContent);
            }
            else if (e.PropertyName == CustomNavigationPage.TitleBackgroundProperty.PropertyName)
            {
                UpdateTitleViewLayoutBackground(_titleViewLayout, CustomNavigationPage.GetTitleBackground(lastPage), _originalDrawable);
            }
            else if (e.PropertyName == CustomNavigationPage.BarBackgroundProperty.PropertyName)
            {
                UpdateToolbarBackground(_toolbar, lastPage, Context as Activity, _originalToolbarBackground);
            }
            else if (e.PropertyName == CustomNavigationPage.GradientColorsProperty.PropertyName)
            {
                UpdateToolbarBackground(_toolbar, lastPage, Context as Activity, _originalToolbarBackground);
            }
            else if (e.PropertyName == CustomNavigationPage.GradientDirectionProperty.PropertyName)
            {
                UpdateToolbarBackground(_toolbar, lastPage, Context as Activity, _originalToolbarBackground);
            }
            else if (e.PropertyName == CustomNavigationPage.BarBackgroundOpacityProperty.PropertyName)
            {
                UpdateToolbarBackground(_toolbar, lastPage, Context as Activity, _originalToolbarBackground);
            }
            else if (e.PropertyName == CustomNavigationPage.TitleBorderCornerRadiusProperty.PropertyName)
            {
                _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage)));
            }
            else if (e.PropertyName == CustomNavigationPage.TitleBorderWidthProperty.PropertyName)
            {
                _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage)));
            }
            else if (e.PropertyName == CustomNavigationPage.TitleBorderColorProperty.PropertyName)
            {
                _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage)));
            }
            else if (e.PropertyName == CustomNavigationPage.TitleFillColorProperty.PropertyName)
            {
                _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage)));
            }
            else if (e.PropertyName == CustomNavigationPage.TitlePositionProperty.PropertyName)
            {
                UpdateTitleViewLayoutAlignment(_titleViewLayout, _titleTextView, _subTitleTextView, CustomNavigationPage.GetTitlePosition(lastPage));
            }
            else if (e.PropertyName == CustomNavigationPage.TitlePaddingProperty.PropertyName)
            {
                UpdateTitleViewLayoutPadding(_titleViewLayout, CustomNavigationPage.GetTitlePadding(lastPage));
            }
            else if (e.PropertyName == CustomNavigationPage.TitleMarginProperty.PropertyName)
            {
                UpdateTitleViewLayoutMargin(_titleViewLayout, CustomNavigationPage.GetTitleMargin(lastPage));
            }
            else if (e.PropertyName == CustomNavigationPage.TitleColorProperty.PropertyName)
            {
                UpdateToolbarTextColor(_titleTextView, CustomNavigationPage.GetTitleColor(lastPage), _originalColorStateList);
            }
            else if (e.PropertyName == CustomNavigationPage.TitleFontProperty.PropertyName)
            {
                UpdateToolbarTextFont(_titleTextView, CustomNavigationPage.GetTitleFont(lastPage), _originalFont);
            }
            else if (e.PropertyName == Page.TitleProperty.PropertyName)
            {
                UpdateTitleText(_titleTextView, lastPage.Title);
            }
            else if (e.PropertyName == CustomNavigationPage.SubtitleColorProperty.PropertyName)
            {
                UpdateToolbarTextColor(_subTitleTextView, CustomNavigationPage.GetSubtitleColor(lastPage), _originalColorStateList);
            }
            else if (e.PropertyName == CustomNavigationPage.SubtitleFontProperty.PropertyName)
            {
                UpdateToolbarTextFont(_subTitleTextView, CustomNavigationPage.GetSubtitleFont(lastPage), _originalFont);
            }
        }