Esempio n. 1
0
		// Code taken from 
		// http://www.michaelridland.com/xamarin/creating-native-view-xamarin-forms-viewpage/
        public static ViewGroup ConvertFormsToNative(Xamarin.Forms.View view, Xamarin.Forms.Rectangle size)
        {
            var renderer = Platform.CreateRenderer(view);
            var viewGroup = renderer.ViewGroup;
            renderer.Tracker.UpdateLayout();
            var layoutParams = new ViewGroup.LayoutParams((int)size.Width, (int)size.Height);
            viewGroup.LayoutParameters = layoutParams;
            view.Layout(size);
            viewGroup.Layout(0, 0, (int)view.WidthRequest, (int)view.HeightRequest);
            return viewGroup;
        }
        public static FrameworkElement ConvertFormsToNative(Xamarin.Forms.View view, Rectangle size)
        {
            //var vRenderer = RendererFactory.GetRenderer (view);

            if (Platform.GetRenderer(view) == null)
                Platform.SetRenderer(view, Platform.CreateRenderer(view));

            var vRenderer = Platform.GetRenderer(view);

            view.Layout(new Rectangle(0, 0, size.Width, size.Height));

            //vRenderer.ContainerElement.Arrange(new Rect(0, 0, size.Width, size.Height));

            return vRenderer.ContainerElement;
        }
        public static ViewGroup ConvertFormsToNative(Xamarin.Forms.View view, Rectangle size)
        {
			//var vRenderer = RendererFactory.GetRenderer (view);

			if (Platform.GetRenderer(view) == null)
				Platform.SetRenderer(view, Platform.CreateRenderer(view));
			var vRenderer = Platform.GetRenderer(view);

            
            var viewGroup = vRenderer.ViewGroup;
            vRenderer.Tracker.UpdateLayout ();
            var layoutParams = new ViewGroup.LayoutParams ((int)size.Width, (int)size.Height);
            viewGroup.LayoutParameters = layoutParams;
            view.Layout (size);
            viewGroup.Layout (0, 0, (int)view.WidthRequest, (int)view.HeightRequest);
            return viewGroup; 
        }
Esempio n. 4
0
        public IXFPopupCtrl CreateDialog(Xamarin.Forms.Page page, Xamarin.Forms.View content, bool cancelable)
        {
            CustomDialog dlg = null;

            if (content != null)
            {

                var render = Convert(content, page);

                if (render != null)
                {

                    var size = content.GetSizeRequest(XFPopupConst.SCREEN_WIDTH, XFPopupConst.SCREEN_HEIGHT);

                    var width = (int)size.Request.Width;
                    var height = (int)size.Request.Height;

                    if (width > XFPopupConst.SCREEN_WIDTH)
                    {
                        width = (int)(XFPopupConst.SCREEN_WIDTH * 3 / 4);
                    }

                    if (height > (XFPopupConst.SCREEN_HEIGHT * 3 / 4))
                    {
                        height = (int)(XFPopupConst.SCREEN_HEIGHT * 3 / 4);
                    }

                    content.WidthRequest = width;
                    content.HeightRequest = height;

                    //important
                    content.Layout(new Rectangle(0, 0, width, height));

                    dlg = new CustomDialog(content, cancelable);

                }

            }
            return dlg;
        }
Esempio n. 5
0
        public void ShowTopNoti(Xamarin.Forms.Page page, Xamarin.Forms.View noti, int ttl = 1500)
        {
            if (noti != null && page != null) {

                var render = Convert(noti, page);

                if (render != null) {
                    nfloat width = XFPopupConst.SCREEN_WIDTH;
                    var size = noti.GetSizeRequest(XFPopupConst.SCREEN_WIDTH - 4, XFPopupConst.SCREEN_HEIGHT * 0.2f);
                    nfloat height = (int)size.Request.Height;

                    if (height > (XFPopupConst.SCREEN_HEIGHT * 0.2f))
                    {
                        height = (int)(XFPopupConst.SCREEN_HEIGHT * 0.2f);
                    }

                    //important
                    noti.Layout(new Xamarin.Forms.Rectangle(0, 0, width, height));

                    var win = new UIWindow(new CGRect(0,0,width,height));
                    win.WindowLevel = UIKit.UIWindowLevel.Alert;
                    var native = render as UIKit.UIView;
                    win.AddSubview (native);
                    win.Alpha = 0;
                    win.MakeKeyAndVisible ();

                    native.Frame = new CGRect(1, 0 , width - 2, 0) ;

                    win.Alpha = 1;
                    UIView.Animate (
                        duration: 1f,
                        delay: 0f,
                        options: UIViewAnimationOptions.TransitionNone,
                        animation: () => {
                            native.Frame = new CoreGraphics.CGRect (1, 20, width - 2, height - 2);
                        },
                        completion: () => {
                            UIView.Animate(
                                duration: ttl/1000,
                                delay: 0f,
                                options: UIViewAnimationOptions.CurveEaseInOut,
                                animation: () => { win.Alpha = 0; },
                                completion: () => {
                                    native.RemoveFromSuperview();
                                    native = null;
                                    win.RemoveFromSuperview();
                                    win = null;
                                }
                            );
                        }
                    );

                }

            }
        }
Esempio n. 6
0
        public IXFPopupCtrl CreateDropDown(Xamarin.Forms.View anchor, Xamarin.Forms.View drop)
        {
            CustomPopup dlg = null;
            //first try to get the PopupHolderRenderer
            //first try to get the PopupHolderRenderer
            if(anchor == null || drop == null){
                return null;
            }

            var anchorRender = anchor.GetValue(RendererProperty) as UIView;
            if (anchorRender == null) {
                return null;
            }

            var render = Convert(drop, anchor);

            if (render == null) {
                return null;
            }

            if (render != null) {

                var size = drop.GetSizeRequest(anchorRender.Bounds.Width, XFPopupConst.SCREEN_HEIGHT);
                var width = anchorRender.Bounds.Width;
                var height = (int)size.Request.Height;
                if (height > (XFPopupConst.SCREEN_HEIGHT * 3/ 4))
                {
                    height = (int)(XFPopupConst.SCREEN_HEIGHT * 3/ 4);
                }

                //important
                drop.Layout(new Xamarin.Forms.Rectangle(0, 0, width - 2*padding, height));

                var native = render as UIKit.UIView;
                native.Frame = new CoreGraphics.CGRect (padding, padding, width - 2*padding, height);

                dlg = new CustomPopup(native, true, width, height + 2*padding, ShowType.DropDown,anchorRender);

            }
            return dlg;
        }
Esempio n. 7
0
        public IXFPopupCtrl CreateDialog(Page page, Xamarin.Forms.View content,bool cancelable)
        {
            CustomPopup dlg = null;

            if (content != null) {

                var render = Convert(content, page);

                if (render != null) {

                    var size = content.GetSizeRequest(XFPopupConst.SCREEN_WIDTH, XFPopupConst.SCREEN_HEIGHT);

                    var width = (int)size.Request.Width;
                    var height = (int)size.Request.Height;

                    if (width > XFPopupConst.SCREEN_WIDTH)
                    {
                        width = (int)(XFPopupConst.SCREEN_WIDTH * 3 / 4);
                    }

                    if (height > (XFPopupConst.SCREEN_HEIGHT * 3/ 4))
                    {
                        height = (int)(XFPopupConst.SCREEN_HEIGHT * 3/ 4);
                    }

                    //important
                    content.Layout(new Xamarin.Forms.Rectangle(0, 0, width, height));

                    var native = render as UIKit.UIView;

                    native.Frame = new CoreGraphics.CGRect (padding, padding, width, height);

                    dlg = new CustomPopup(native,cancelable,width + 2*padding,height + 2*padding,ShowType.Dialog);

                }

            }
            return dlg;
        }
Esempio n. 8
0
        public IXFPopupCtrl CreateDialog(Page page, Xamarin.Forms.View content,bool cancelable)
        {
            CustomDialog dlg = null;
            //first try to get the PopupHolderRenderer

            if (content != null) {

                var render = Convert(content, page);

                if (render != null) {

                    var size = content.GetSizeRequest(XFPopupConst.SCREEN_WIDTH, XFPopupConst.SCREEN_HEIGHT);

                    var width = (int)size.Request.Width;
                    var height = (int)size.Request.Height;

                    if (width > XFPopupConst.SCREEN_WIDTH)
                    {
                        width = (int)(XFPopupConst.SCREEN_WIDTH * 3 / 4);
                    }

                    if (height > (XFPopupConst.SCREEN_HEIGHT * 3/ 4))
                    {
                        height = (int)(XFPopupConst.SCREEN_HEIGHT * 3/ 4);
                    }

                    //important
                    content.Layout(new Rectangle(0, 0, width, height));

                    float density = Forms.Context.Resources.DisplayMetrics.Density;
                    width = (int)(width * density);
                    height = (int)(height * density);

                    var native = render as Android.Views.View;
                    native.LayoutParameters = new ViewGroup.LayoutParams(width, height);

                    LinearLayout ll = new LinearLayout(Forms.Context);
                    ll.SetBackgroundResource(Resource.Layout.rounded_rectangle_bgr);
                    ll.LayoutParameters = new ViewGroup.LayoutParams(width + 4, height + 4);
                    ll.AddView(native);

                    dlg = new CustomDialog(ll,cancelable);

                }

            }
            return dlg;
        }
Esempio n. 9
0
        public IXFPopupCtrl CreateDropDown(Xamarin.Forms.View anchor, Xamarin.Forms.View drop)
        {
            CustomDropDown dropctr = null;
            //get the renderer of anchor
            if (anchor != null) {
                var ar = anchor.GetValue(RendererProperty);
                if (ar != null) {
                    var dropView = Convert(drop, anchor);

                    if (dropView == null) {
                        return null;
                    }

                    double w = (int)anchor.Width;
                    double h = XFPopupConst.SCREEN_HEIGHT/2;
                    drop.WidthRequest = w;
                    var size = drop.GetSizeRequest(w, XFPopupConst.SCREEN_HEIGHT / 2);
                    if (size.Request.Height < h) {
                        h = size.Request.Height;
                    }

                    drop.Layout(new Rectangle(0, 0, w, h));

                    float density = Forms.Context.Resources.DisplayMetrics.Density;
                    w = w * density;
                    h = h * density;

                    var native = dropView as Android.Views.View;
                    native.LayoutParameters = new ViewGroup.LayoutParams((int)w, (int)h);

                    dropctr = new CustomDropDown(ar as Android.Views.View, native, (int)w + 4, (int)h+10);

                }

            }

            return dropctr;
        }