Пример #1
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;
        }