Ejemplo n.º 1
0
        void Initialize()
        {
            _dlgView.Parent = Application.Current.MainPage;


            _renderer = Dialogs.CreateNativeView(_dlgView);

            if (_dlgView.CornerRadius > 0)
            {
                _renderer.NativeView.Layer.CornerRadius  = _dlgView.CornerRadius;
                _renderer.NativeView.Layer.MasksToBounds = true;
            }

            if (_dlgView.BorderWidth > 0)
            {
                _renderer.NativeView.Layer.BorderWidth = (float)_dlgView.BorderWidth;
                _renderer.NativeView.Layer.BorderColor = _dlgView.BorderColor.ToCGColor();
            }

            var measure = Dialogs.Measure(_dlgView);

            _renderer.SetElementSize(measure);

            _contentViewController = new UIViewController
            {
                View = _renderer.NativeView
            };


            _dialogController = new DialogPresentationController(_dlgView, _overlayView, _contentViewController, _viewController);
            _contentViewController.TransitioningDelegate = _dialogController;

            OnceInitializeAction = null;
        }
Ejemplo n.º 2
0
        void Initialize(bool isCurrentScope = false)
        {
            OnceInitializeAction = null;

            OverlayView.BackgroundColor = _loadingView.OverlayColor.ToUIColor();
            OverlayView.Alpha           = 0f;
            OverlayView.TranslatesAutoresizingMaskIntoConstraints = false;

            SetOverlayConstrants(isCurrentScope);

            _loadingView.Parent = Application.Current.MainPage;

            _renderer = Dialogs.CreateNativeView(_loadingView);

            if (_loadingView.CornerRadius > 0)
            {
                _renderer.NativeView.Layer.CornerRadius  = _loadingView.CornerRadius;
                _renderer.NativeView.Layer.MasksToBounds = true;
            }

            var measure = Dialogs.Measure(_loadingView);

            _renderer.SetElementSize(measure);

            var nativeView = _renderer.NativeView;

            nativeView.TranslatesAutoresizingMaskIntoConstraints = false;

            OverlayView.AddSubview(nativeView);

            nativeView.WidthAnchor.ConstraintEqualTo((System.nfloat)_loadingView.Bounds.Width).Active   = true;
            nativeView.HeightAnchor.ConstraintEqualTo((System.nfloat)_loadingView.Bounds.Height).Active = true;

            Dialogs.SetLayoutAlignment(nativeView, OverlayView, _loadingView);
        }
Ejemplo n.º 3
0
        public void Show(ToastView view, object viewModel = null)
        {
            if (viewModel != null)
            {
                view.BindingContext = viewModel;
            }
            view.Parent = Application.Current.MainPage;

            var renderer = Dialogs.CreateNativeView(view);

            var measure = Dialogs.Measure(view);

            renderer.SetElementSize(measure);

            renderer.NativeView.Alpha = 0;
            if (view.CornerRadius > 0)
            {
                renderer.NativeView.Layer.CornerRadius  = view.CornerRadius;
                renderer.NativeView.Layer.MasksToBounds = true;
            }
            if (view.BorderWidth > 0)
            {
                renderer.NativeView.Layer.BorderWidth = (float)view.BorderWidth;
                renderer.NativeView.Layer.BorderColor = view.BorderColor.ToCGColor();
            }

            SetView(view, renderer.NativeView, renderer);

            view.Parent = null;

            view.RunPresentationAnimation();
            UIView.Animate(
                0.25,
                () => renderer.NativeView.Alpha = (System.nfloat)view.Opacity
                );

            Device.StartTimer(TimeSpan.FromMilliseconds(Math.Max(view.Duration - 250, 0)), () =>
            {
                view.RunDismissalAnimation();
                UIView.Animate(
                    0.25,
                    () => renderer.NativeView.Alpha = 0,
                    () => {
                    view.Parent = null;
                    renderer.NativeView.RemoveConstraints(renderer.NativeView.Constraints);
                    Dialogs.DisposeModelAndChildrenRenderers(view);
                    renderer = null;
                    view.Destroy();
                    view.BindingContext = null;
                    view = null;
                }
                    );

                return(false);
            });
        }
Ejemplo n.º 4
0
        void Initialize()
        {
            OnceInitializeAction = null;

            ContentView.SetBackgroundColor(_loadingView.OverlayColor.ToAndroid());
            ContentView.Alpha = 1f;
            ContentView.SetPadding(0, (int)Dialogs.Context.ToPixels(24), 0, 0); // Statusbar

            _loadingView.Parent = XF.Application.Current.MainPage;

            _renderer = Dialogs.CreateNativeView(_loadingView);

            if (_loadingView.CornerRadius > 0)
            {
                var nativeView = _renderer.View as ViewGroup;
                var border     = new GradientDrawable();
                border.SetCornerRadius(Dialogs.Context.ToPixels(_loadingView.CornerRadius));
                if (!_loadingView.BackgroundColor.IsDefault)
                {
                    border.SetColor(_loadingView.BackgroundColor.ToAndroid());
                }
                nativeView.ClipToOutline = true;
                nativeView.SetBackground(border);
            }

            var measure = Dialogs.Measure(_loadingView);

            _loadingView.Layout(new XF.Rectangle(0, 0, measure.Width, measure.Height));


            var width  = (int)Dialogs.Context.ToPixels(_loadingView.Bounds.Width);
            var height = (int)Dialogs.Context.ToPixels(_loadingView.Bounds.Height);

            using (var param = new FrameLayout.LayoutParams(
                       ViewGroup.LayoutParams.WrapContent,
                       ViewGroup.LayoutParams.WrapContent
                       )
            {
                Width = width,
                Height = height,
                Gravity = Dialogs.GetGravity(_loadingView)
            })
            {
                Dialogs.SetOffsetMargin(param, _loadingView);
                ContentView.AddView(_renderer.View, 0, param);
            }
        }
Ejemplo n.º 5
0
        void Initialize()
        {
            _dlgView.Parent = XF.Application.Current.MainPage;

            _renderer = Dialogs.CreateNativeView(_dlgView);

            var measure = Dialogs.Measure(_dlgView);

            _dlgView.Layout(new XF.Rectangle(0, 0, measure.Width, measure.Height));

            _container = Dialogs.SetViewAppearance(_dlgView, _renderer.View as ViewGroup);

            _contentView = new FrameLayout(Dialogs.Context);
            using (var param = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent))
            {
                _contentView.LayoutParameters = param;
            }

            var fixPaddingTop = _dlgView.OverlayColor.IsTransparentOrDefault() ? Dialogs.StatusBarHeight : 0;

            if (_dlgView.UseCurrentPageLocation)
            {
                var padding = Dialogs.CalcWindowPadding();
                _contentView.SetPadding(0, padding.top - fixPaddingTop, 0, padding.bottom);
            }
            else
            {
                _contentView.SetPadding(0, Dialogs.StatusBarHeight - fixPaddingTop, 0, 0);
            }

            _contentView.SetBackgroundColor(_dlgView.OverlayColor.ToAndroid());
            _contentView.SetClipChildren(false);
            _contentView.SetClipToPadding(false);

            _contentView.FocusableInTouchMode = true;
            _contentView.Touch += _contentView_Touch;

            var width  = Dialogs.Context.ToPixels(_dlgView.Bounds.Width);
            var height = Dialogs.Context.ToPixels(_dlgView.Bounds.Height);

            using (var param = new FrameLayout.LayoutParams(
                       ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)
            {
                Width = (int)width,
                Height = (int)height,
                Gravity = Dialogs.GetGravity(_dlgView),
            })
            {
                Dialogs.SetOffsetMargin(param, _dlgView);
                _contentView.AddView(_container, 0, param);
            };

            // For now, Dynamic resizing is gaven to only Dialog.
            _dlgView.LayoutNative = () =>
            {
                if (_renderer == null || _renderer.View.IsDisposed())
                {
                    return;
                }

                var p = _renderer.View.LayoutParameters as FrameLayout.LayoutParams;
                var w = (int)Dialogs.Context.ToPixels(_dlgView.Bounds.Width);
                var h = (int)Dialogs.Context.ToPixels(_dlgView.Bounds.Height);


                using (var param = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)
                {
                    Width = w,
                    Height = h,
                    Gravity = p.Gravity
                })
                {
                    Dialogs.SetOffsetMargin(param, _dlgView);
                    _renderer.View.LayoutParameters = param;
                };
            };

            OnceInitializeAction = null;
        }
Ejemplo n.º 6
0
        void Initialize()
        {
            _dlgView.Parent = XF.Application.Current.MainPage;

            _renderer = Dialogs.CreateNativeView(_dlgView);

            var measure = Dialogs.Measure(_dlgView);

            _dlgView.Layout(new XF.Rectangle(0, 0, measure.Width, measure.Height));

            if (_dlgView.CornerRadius > 0)
            {
                var nativeView = _renderer.View as ViewGroup;
                var border     = new GradientDrawable();
                border.SetCornerRadius(Dialogs.Context.ToPixels(_dlgView.CornerRadius));
                if (!_dlgView.BackgroundColor.IsDefault)
                {
                    border.SetColor(_dlgView.BackgroundColor.ToAndroid());
                }
                nativeView.ClipToOutline = true;
                nativeView.SetBackground(border);
            }


            _contentView = new FrameLayout(Dialogs.Context);
            using (var param = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent))
            {
                _contentView.LayoutParameters = param;
            }

            if (_dlgView.UseCurrentPageLocation)
            {
                var padding = Dialogs.CalcWindowPadding();
                _contentView.SetPadding(0, padding.top, 0, padding.bottom);
            }
            else
            {
                _contentView.SetPadding(0, (int)Dialogs.Context.ToPixels(24), 0, 0); // Statusbar
            }

            _contentView.SetBackgroundColor(_dlgView.OverlayColor.ToAndroid());
            _contentView.SetClipChildren(false);
            _contentView.SetClipToPadding(false);

            _contentView.SetOnKeyListener(this);
            _contentView.FocusableInTouchMode = true;
            _contentView.Touch += _contentView_Touch;

            var width  = Dialogs.Context.ToPixels(_dlgView.Bounds.Width);
            var height = Dialogs.Context.ToPixels(_dlgView.Bounds.Height);

            using (var param = new FrameLayout.LayoutParams(
                       ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)
            {
                Width = (int)width,
                Height = (int)height,
                Gravity = Dialogs.GetGravity(_dlgView),
            })
            {
                Dialogs.SetOffsetMargin(param, _dlgView);
                _contentView.AddView(_renderer.View, 0, param);
            };

            OnceInitializeAction = null;
        }
Ejemplo n.º 7
0
        public void Show(ToastView view, object viewModel = null)
        {
            view.Parent         = XF.Application.Current.MainPage;
            view.BindingContext = viewModel;

            var toast = new Android.Widget.Toast(Dialogs.Context);

            var offsetX = (int)Dialogs.Context.ToPixels(view.OffsetX);
            var offsetY = (int)Dialogs.Context.ToPixels(view.OffsetY);

            // HACK: For some reason, the offset direction is reversed when GravityFlags contains Left or Bottom.
            if (view.HorizontalLayoutAlignment == XF.LayoutAlignment.End)
            {
                offsetX *= -1;
            }
            if (view.VerticalLayoutAlignment == XF.LayoutAlignment.End)
            {
                offsetY *= -1;
            }

            toast.SetGravity(Dialogs.GetGravity(view), offsetX, offsetY);
            toast.Duration = Android.Widget.ToastLength.Long;

            var renderer = Dialogs.CreateNativeView(view);

            var measure = Dialogs.Measure(view);

            view.Layout(new XF.Rectangle(new XF.Point(0, 0), measure));

            var realW = (int)Dialogs.Context.ToPixels(measure.Width);
            var realH = (int)Dialogs.Context.ToPixels(measure.Height);

            var layout = new LinearLayout(Dialogs.Context);

            using (var param = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent)
            {
                Width = realW,
                Height = realH
            }){
                layout.LayoutParameters = param;
            }

            using (var param = new LinearLayout.LayoutParams(realW, realH)
            {
                Width = realW, Height = realH
            }){
                layout.AddView(renderer.View, param);
            }

            if (view.CornerRadius > 0)
            {
                var border = new GradientDrawable();
                border.SetCornerRadius(Dialogs.Context.ToPixels(view.CornerRadius));
                if (!view.BackgroundColor.IsDefault)
                {
                    border.SetColor(view.BackgroundColor.ToAndroid());
                    border.Alpha = (int)(view.Opacity * 255);
                }
                layout.ClipToOutline = true;
                layout.SetBackground(border);
            }

            toast.View = layout;

            view.RunPresentationAnimation();

            toast.Show();

            var duration = Math.Max(Math.Min(view.Duration - 260, 3500), 0); // give a bit millisecond margin

            var handler = new Handler();

            handler.PostDelayed(new Runnable(view.RunDismissalAnimation), duration);

            handler.PostDelayed(new Runnable(() =>
            {
                //view.RunDismissalAnimation();
                //await Task.Delay(250);
                toast?.Cancel();

                view.Parent = null;

                if (!renderer.View.IsDisposed())
                {
                    renderer.View.RemoveFromParent();
                    renderer.View.Dispose();
                }

                layout.Dispose();

                // I coudn't reproduce https://github.com/muak/AiForms.Dialogs/issues/2.
                // But I let this code disabled because it has no influent even if it is disabled.
                //toast.View = null;

                renderer.Dispose();
                renderer = null;
                toast?.Dispose();
                toast = null;

                view.Destroy();
                view.BindingContext = null;
            }), view.Duration);
        }