Esempio n. 1
0
 public Popup()
 {
     _popupRootLayout = new PopupRootLayout();
     _popupRootLayout.HorizontalOptions = LayoutOptions.Center;
     _popupRootLayout.VerticalOptions   = LayoutOptions.Center;
     _popupRootLayout.Popup             = this;
 }
        public Animation Create(View target)
        {
            PopupRootLayout rootLayout = (PopupRootLayout)target;

            // If full screen popup which is closing
            if (rootLayout.Popup.IsOpen == false && rootLayout.Popup.ActualPlacement == PopupPlacements.FullScreen)
            {
                return(new Animation(d =>
                {
                    rootLayout.TranslationY = rootLayout.Height * d;
                }, 0, 1));
            }

            Animation animationGroup = new Animation();

            if (OpacityStartTime.Equals(OpacityEndTime) == false && OpacityStart != OpacityEnd && OpacityInit != OpacityEnd)
            {
                if (OpacityInit.HasValue)
                {
                    rootLayout.Opacity = OpacityInit.Value;
                }

                Animation fadeAnimation = new Animation(d =>
                {
                    rootLayout.Opacity = d;
                }, OpacityStart, OpacityEnd);

                animationGroup.Add(OpacityStartTime, OpacityEndTime, fadeAnimation);
            }

            double animatedValue = 0;

            if (SlideStartOffset != 0)
            {
                EventHandler sizeChanged = null;
                sizeChanged = (s, a) =>
                {
                    rootLayout.Content.TranslationY = CalculateTranslateY(animatedValue, rootLayout);
                };

                rootLayout.SizeChanged += sizeChanged;

                // Init TranslationY
                rootLayout.Content.TranslationY = CalculateTranslateY(0, rootLayout);

                Animation slideAnimation = new Animation(d =>
                {
                    animatedValue = d;
                    rootLayout.Content.TranslationY = CalculateTranslateY(d, rootLayout);
                }, 0, 1, AnimationUtils.EaseOutQuint, finished: () =>
                {
                    rootLayout.Content.SizeChanged -= sizeChanged;
                });

                animationGroup.Add(0, 1, slideAnimation);
            }

            return(animationGroup);
        }
        public Animation Create(View target)
        {
            PopupRootLayout rootLayout = (PopupRootLayout)target;
            Popup           popup      = rootLayout.Popup;

            rootLayout.Scale   = ScaleStart;
            rootLayout.Opacity = OpacityStart;

            Animation animationGroup = new Animation();

            animationGroup.Add(0, 1, new Animation(d =>
            {
                rootLayout.Scale   = ScaleStart + (ScaleEnd - ScaleStart) * d;
                rootLayout.Opacity = OpacityStart + (OpacityEnd - OpacityStart) * d;

                if (Popup.IsTopPlacement(popup.ActualPlacement) && Popup.IsRightPlacement(popup.ActualPlacement))
                {
                    rootLayout.TranslationX = ((rootLayout.Width * d) / 2) * (1 - d);
                    rootLayout.TranslationY = ((rootLayout.Height * d) / 2) * (1 - d);
                }
                else if (Popup.IsTopPlacement(popup.ActualPlacement) && Popup.IsRightPlacement(popup.ActualPlacement) == false)
                {
                    rootLayout.TranslationX = -((rootLayout.Width * d) / 2) * (1 - d);
                    rootLayout.TranslationY = ((rootLayout.Height * d) / 2) * (1 - d);
                }
                else if (Popup.IsTopPlacement(popup.ActualPlacement) == false && Popup.IsRightPlacement(popup.ActualPlacement))
                {
                    rootLayout.TranslationX = ((rootLayout.Width * d) / 2) * (1 - d);
                    rootLayout.TranslationY = -((rootLayout.Height * d) / 2) * (1 - d);
                }
                else if (Popup.IsTopPlacement(popup.ActualPlacement) == false && Popup.IsRightPlacement(popup.ActualPlacement) == false)
                {
                    rootLayout.TranslationX = -((rootLayout.Width * d) / 2) * (1 - d);
                    rootLayout.TranslationY = -((rootLayout.Height * d) / 2) * (1 - d);
                }
            }, 0, 1, Easing));

            animationGroup.Add(0, 1, new Animation(d =>
            {
                if (Popup.IsTopPlacement(popup.ActualPlacement) && Popup.IsRightPlacement(popup.ActualPlacement))
                {
                }
                else if (Popup.IsTopPlacement(popup.ActualPlacement) && Popup.IsRightPlacement(popup.ActualPlacement) == false)
                {
                }
                else if (Popup.IsTopPlacement(popup.ActualPlacement) == false && Popup.IsRightPlacement(popup.ActualPlacement))
                {
                }
                else if (Popup.IsTopPlacement(popup.ActualPlacement) == false && Popup.IsRightPlacement(popup.ActualPlacement) == false)
                {
                    rootLayout.Content.TranslationY = -ContentSlideDistance * (1 - d);
                }
            }, 0, 1, Easing.CubicOut));

            return(animationGroup);
        }
 private double CalculateTranslateY(double process, PopupRootLayout rootLayout)
 {
     if (Popup.IsTopPlacement(rootLayout.Popup.ActualPlacement))
     {
         return(rootLayout.Height - ((rootLayout.Height - SlideStartOffset) * process) - SlideStartOffset);
     }
     else
     {
         return(SlideStartOffset + ((rootLayout.Height - SlideStartOffset) * process) - rootLayout.Height);
     }
 }
        public Animation Create(View target)
        {
            PopupRootLayout rootLayout = (PopupRootLayout)target;
            Popup           popup      = rootLayout.Popup;

            if (rootLayout.Popup.IsOpen)
            {
                rootLayout.Opacity = 0;
            }

            Animation anim = new Animation(d =>
            {
                if (rootLayout.Popup.IsOpen)
                {
                    rootLayout.Opacity = 1;
                }
                else
                {
                    d = 1 - d;
                }

                Rectangle location = new Rectangle(rootLayout.X, rootLayout.Y, rootLayout.Width, rootLayout.Height);

                Rectangle clipRect = new Rectangle(0, 0, location.Width, location.Height);
                double contentY    = 0;
                double contentX    = 0;

                if (popup.ActualPlacement == PopupPlacements.RightTop)
                {
                    double width = IsHorizontalResizeEnabled ? location.Width * d : location.Width;
                    clipRect     = new Rectangle(0, 0, width, location.Height * d);
                    contentY     = -location.Height * (1 - d);
                }
                else if (popup.ActualPlacement == PopupPlacements.RightCenter)
                {
                    clipRect = new Rectangle(0, 0, location.Width * d, location.Height);
                    contentX = -location.Width * (1 - d);
                }
                else if (popup.ActualPlacement == PopupPlacements.RightBottom)
                {
                    double width = IsHorizontalResizeEnabled ? location.Width * d : location.Width;
                    clipRect     = new Rectangle(0, location.Height * (1 - d), width, location.Height * d);
                }
                else if (popup.ActualPlacement == PopupPlacements.BottomRight)
                {
                    double width = IsHorizontalResizeEnabled ? location.Width * d : location.Width;
                    double x     = IsHorizontalResizeEnabled ? location.Width * (1 - d) : 0;
                    clipRect     = new Rectangle(x, 0, width, location.Height * d);
                    contentY     = -location.Height * (1 - d);
                }
                else if (popup.ActualPlacement == PopupPlacements.BottomCenter || popup.ActualPlacement == PopupPlacements.BottomStretch)
                {
                    clipRect = new Rectangle(0, 0, location.Width, location.Height * d);
                    contentY = -location.Height * (1 - d);
                }
                else if (popup.ActualPlacement == PopupPlacements.BottomLeft)
                {
                    double width = IsHorizontalResizeEnabled ? location.Width * d : location.Width;
                    clipRect     = new Rectangle(0, 0, width, location.Height * d);
                    contentY     = -location.Height * (1 - d);
                }
                else if (popup.ActualPlacement == PopupPlacements.LeftBottom)
                {
                    double width = IsHorizontalResizeEnabled ? location.Width * d : location.Width;
                    double x     = IsHorizontalResizeEnabled ? location.Width * (1 - d) : 0;
                    clipRect     = new Rectangle(x, location.Height * (1 - d), width, location.Height * d);
                }
                else if (popup.ActualPlacement == PopupPlacements.LeftCenter)
                {
                    clipRect = new Rectangle(location.Width * (1 - d), 0, location.Width * d, location.Height);
                }
                else if (popup.ActualPlacement == PopupPlacements.LeftTop)
                {
                    double width = IsHorizontalResizeEnabled ? location.Width * d : location.Width;
                    double x     = IsHorizontalResizeEnabled ? location.Width * (1 - d) : 0;
                    clipRect     = new Rectangle(x, 0, width, location.Height * d);
                    contentY     = -location.Height * (1 - d);
                }
                else if (popup.ActualPlacement == PopupPlacements.TopLeft)
                {
                    double width = IsHorizontalResizeEnabled ? location.Width * d : location.Width;
                    clipRect     = new Rectangle(0, location.Height * (1 - d), width, location.Height * d);
                }
                else if (popup.ActualPlacement == PopupPlacements.TopCenter || popup.ActualPlacement == PopupPlacements.TopStretch)
                {
                    clipRect = new Rectangle(0, location.Height * (1 - d), location.Width, location.Height * d);
                }
                else if (popup.ActualPlacement == PopupPlacements.TopRight)
                {
                    double width = IsHorizontalResizeEnabled ? location.Width * d : location.Width;
                    double x     = IsHorizontalResizeEnabled ? location.Width * (1 - d) : 0;
                    clipRect     = new Rectangle(x, location.Height * (1 - d), width, location.Height * d);
                }
                else if (popup.ActualPlacement == PopupPlacements.FullScreen)
                {
                    rootLayout.TranslationY = location.Height * (1 - d);
                }
                else
                {
                    // No animation
                }

                if (popup.ActualPlacement != PopupPlacements.FullScreen)
                {
                    if (IsContentTranslationEnabled)
                    {
                        rootLayout.Content.TranslationX = contentX;
                        rootLayout.Content.TranslationY = contentY;
                    }

                    rootLayout.Clip(clipRect);
                }
            }, 0, 1, Easing.CubicOut);

            return(anim);
        }