コード例 #1
0
        public void InitContent(Xamarin.Forms.View content)
        {
            // build the loading page with native base
            content.Parent = Xamarin.Forms.Application.Current.MainPage;

            content.Layout(new Rectangle(0, 0,
                                         Xamarin.Forms.Application.Current.MainPage.Width,
                                         Xamarin.Forms.Application.Current.MainPage.Height));

            var renderer = content.GetOrCreateRenderer();

            _contentNativeView = renderer.View;

            _contentDialog = new Dialog(CrossCurrentActivity.Current.Activity);
            _contentDialog.RequestWindowFeature((int)WindowFeatures.NoTitle);
            _contentDialog.SetCancelable(true);
            _contentDialog.SetCanceledOnTouchOutside(true);
            _contentDialog.SetContentView(_contentNativeView);
            Window window = _contentDialog.Window;

            window.SetLayout(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
            window.ClearFlags(WindowManagerFlags.DimBehind);
            window.SetBackgroundDrawable(new ColorDrawable(Android.Graphics.Color.Transparent));

            _isContentInitialized = true;
        }
        public void PutView(View view)
        {
            view = (view as ContentView)?.Content;
            var coef = CrossCurrentActivity.Current.Activity.Resources.DisplayMetrics.Density;

            //  var size = CrossCurrentActivity.Current.Activity.Resources.GetDimensionPixelSize()

            view.Layout(new Rectangle(0, 0, (int)54, (int)54));
            if (Platform.GetRenderer(view) == null)
            {
                Platform.SetRenderer(view, Platform.CreateRendererWithContext(view, CrossCurrentActivity.Current.Activity));
            }

            var renderer = Platform.GetRenderer(view);

            renderer.Tracker.UpdateLayout();

            var viewToAdd =
                CrossCurrentActivity.Current.Activity.FindViewById <LinearLayout>(Resource.Id.toolbar_button_layout);

            var viewGroup = renderer.View;

            var layoutParams = new ViewGroup.LayoutParams((int)54 * (int)coef, (int)54 * (int)coef);

            viewGroup.LayoutParameters = layoutParams;
            viewGroup.Layout(0, 0, (int)54 * (int)coef, (int)54 * (int)coef);
            // viewToAdd.Invalidate();
            // viewToAdd.RequestLayout();
            // viewGroup.SetBackgroundColor(Color.Black);
            viewToAdd.AddView(viewGroup);
        }
コード例 #3
0
        public static Android.Views.View ToAndroid(this Xamarin.Forms.View view, Rectangle size, Context _context)
        {
            // NullReferenceException during swiping #314 (ScrollView)
            if (Platform.GetRenderer(view) == null || Platform.GetRenderer(view)?.Tracker == null || view is Xamarin.Forms.ListView)
            {
                Platform.SetRenderer(view, Platform.CreateRendererWithContext(view, _context));
            }

            var vRenderer = Platform.GetRenderer(view);

            var viewGroup = vRenderer.View;

            vRenderer.Tracker?.UpdateLayout();
            var layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);

            viewGroup.LayoutParameters = layoutParams;
            view.Layout(size);
            viewGroup.Layout(0, 0, (int)size.Width, (int)size.Height);

            /*if (view is Xamarin.Forms.ListView)
             * {
             *  var list = (Xamarin.Forms.ListView)view;
             *  if (list.SelectedItem != null)
             *  {
             *      list.ScrollTo(list.SelectedItem, ScrollToPosition.Center, false);
             *  }
             * }*/

            return(viewGroup);
        }
コード例 #4
0
 private void InitChildView(Xamarin.Forms.View view)
 {
     view.IsVisible         = false;
     view.VerticalOptions   = LayoutOptions.CenterAndExpand;
     view.HorizontalOptions = LayoutOptions.StartAndExpand;
     // 父容器的可视范围之外
     view.Layout(new Rectangle(0, -this.Bounds.Height, this.Bounds.Width, this.Bounds.Height));
 }
コード例 #5
0
        public void ShowContent(Xamarin.Forms.View content, bool mathParent = true)
        {
            // build the loading page with native base
            content.Parent = Xamarin.Forms.Application.Current.MainPage;

            if (mathParent)
            {
                content.Layout(new Rectangle(0, 0,
                                             Xamarin.Forms.Application.Current.MainPage.Width,
                                             Xamarin.Forms.Application.Current.MainPage.Height));
            }
            else
            {
                content.Layout(new Rectangle(Xamarin.Forms.Application.Current.MainPage.Width - content.WidthRequest, Xamarin.Forms.Application.Current.MainPage.Height - content.HeightRequest,
                                             content.WidthRequest,
                                             content.HeightRequest));
            }

            var renderer = content.GetOrCreateRenderer();

            contentNativeView = renderer?.View;

            contentDialog = new Dialog(CrossCurrentActivity.Current.Activity);
            contentDialog.RequestWindowFeature((int)WindowFeatures.NoTitle);
            if (mathParent)
            {
                contentDialog.SetCanceledOnTouchOutside(false);
                contentDialog.SetOnKeyListener(new DialogInterfaceOnKeyListener());
            }
            else
            {
                contentDialog.SetCanceledOnTouchOutside(true);
            }
            contentDialog.SetContentView(contentNativeView);

            Window window = contentDialog.Window;

            window.SetLayout(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
            window.ClearFlags(WindowManagerFlags.DimBehind);
            window.SetBackgroundDrawable(new ColorDrawable(Android.Graphics.Color.Transparent));

            // Show Popup
            contentDialog?.Show();
        }
コード例 #6
0
ファイル: IosXFPopupSrvc.cs プロジェクト: thaihung203/xfpopup
        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;
                        }
                            );
                    }
                        );
                }
            }
        }
コード例 #7
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);
        }
コード例 #8
0
        public static Android.Views.View ConvertToNative(this Xamarin.Forms.View view, Context context, Rectangle size)
        {
            var vRenderer = Platform.CreateRendererWithContext(view, context);
            var viewGroup = vRenderer.View;

            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);
        }
コード例 #9
0
        public static ViewGroup ConvertFormsToNative(Xamarin.Forms.View view, Rectangle size)
        {
            var vRenderer = Platform.CreateRenderer(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);
        }
コード例 #10
0
 public static Task <ViewGroup> ConvertFormsToNative(Xamarin.Forms.View view, Rectangle size, IVisualElementRenderer vRenderer)
 {
     return(Task.Run(() => {
         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);
         //await FixImageSourceOfImageViews(viewGroup as ViewGroup); // Not sure why this was being done in original
         return viewGroup;
     }));
 }
コード例 #11
0
        public static AView ToAndroidView(this Xamarin.Forms.View view, Rectangle size)
        {
            var vRenderer = Platform.CreateRendererWithContext(view, _context);
            var aView     = vRenderer.View;

            vRenderer.Tracker.UpdateLayout();
            view.Layout(size);

            var layoutParams = new ViewGroup.LayoutParams((int)size.Width, (int)size.Height);

            aView.LayoutParameters = layoutParams;
            aView.Layout(0, 0, (int)view.WidthRequest, (int)view.HeightRequest);
            return(aView);
        }
コード例 #12
0
 public static Task <Android.Views.View> ConvertFormsToNative(Xamarin.Forms.View view, Rectangle size, IVisualElementRenderer vRenderer)
 {
     return(Task.Run(() =>
     {
         var renderer = Platform.CreateRendererWithContext(view, CrossCurrentActivity.Current.Activity);
         var nativeView = renderer.View;
         renderer.Tracker.UpdateLayout();
         var layoutParams = new ViewGroup.LayoutParams((int)size.Width, (int)size.Height);
         nativeView.LayoutParameters = layoutParams;
         view.Layout(size);
         nativeView.Layout(0, 0, (int)view.WidthRequest, (int)view.HeightRequest);
         //await FixImageSourceOfImageViews(viewGroup as ViewGroup); // Not sure why this was being done in original
         return nativeView;
     }));
 }
コード例 #13
0
        public static FrameworkElement ToWindows(this Xamarin.Forms.View view, Rectangle size)
        {
            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 Windows.Foundation.Rect(0, 0, size.Width, size.Height));

            return(vRenderer.ContainerElement);
        }
コード例 #14
0
        private Android.Views.View ConvertFormsToNative(Xamarin.Forms.View view, 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);
            view.BackgroundColor = Color.Transparent;
            viewGroup.Layout((int)size.X, (int)size.Y, (int)size.Width, (int)size.Height);

            return(viewGroup);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
ファイル: IosXFPopupSrvc.cs プロジェクト: thaihung203/xfpopup
        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);
        }
コード例 #17
0
        private static Android.Views.View ConvertFormsToNative(Xamarin.Forms.View view, Display display)
        {
            Android.Graphics.Point size = new Android.Graphics.Point();
            display.GetRealSize(size);
            var rectSize = new Rectangle(0, 0, size.X / 1.5, size.Y / 1.5);

            var renderer   = Platform.CreateRendererWithContext(view, Android.App.Application.Context);
            var nativeView = renderer.View;

            renderer.Tracker.UpdateLayout();
            var layoutParams = new ViewGroup.LayoutParams((int)rectSize.Width, (int)rectSize.Height);

            nativeView.LayoutParameters = layoutParams;
            view.Layout(rectSize);
            nativeView.Layout(0, 0, (int)view.WidthRequest, (int)view.HeightRequest);

            return(nativeView);
        }
コード例 #18
0
        public static ViewGroup ToAndroid(this 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);
        }
コード例 #19
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);
        }
コード例 #20
0
        private Android.Views.View ConvertFormsToNative(Xamarin.Forms.View view, Xamarin.Forms.Rectangle size)
        {
            viewRenderer = Platform.CreateRendererWithContext(view, Context);
            var viewGroup = viewRenderer.View;

            viewRenderer.Tracker.UpdateLayout();

            if (view.HeightRequest > 0)
            {
                size.Height = view.HeightRequest;
            }

            var layoutParams = new ViewGroup.LayoutParams((int)(size.Width * Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Density), (int)(size.Height * Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Density));

            viewGroup.LayoutParameters = layoutParams;
            view.Layout(size);
            viewGroup.Layout(0, 0, (int)view.Width, (int)view.Height);
            return(viewGroup);
        }
コード例 #21
0
        public static AViews.View ToAndroid(this 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.View;

            vRenderer.Tracker.UpdateLayout();
            var layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);

            viewGroup.LayoutParameters = layoutParams;
            view.Layout(size);
            viewGroup.Layout(0, 0, (int)view.WidthRequest, (int)view.HeightRequest);
            return(viewGroup);
        }
コード例 #22
0
        private async Task Animate(Xamarin.Forms.View view, bool isCurrent)
        {
            //if (isCurrent)
            view.IsVisible = true;

            Rectangle beginRect = Rectangle.Zero;
            Rectangle endRect   = Rectangle.Zero;

            //设置起始和终止值
            beginRect = setbeginRect(isCurrent, _Direct);
            endRect   = setendRect(isCurrent, _Direct);

            view.Layout(beginRect);
            await view.LayoutTo(endRect, easing : Easing.Linear)
            .ContinueWith(t =>
            {
                // BUG 会使填充失效
                view.IsVisible = isCurrent;
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
コード例 #23
0
        public static AViews.View ToAndroid(this Xamarin.Forms.View view, Rectangle size, Context context)
        {
            //var vRenderer = RendererFactory.GetRenderer (view);

            // NullReferenceException during swiping #314 (ScrollView)
            if (Platform.GetRenderer(view) == null || Platform.GetRenderer(view)?.Tracker == null)
            {
                Platform.SetRenderer(view, Platform.CreateRendererWithContext(view, context.ApplicationContext));
            }

            var vRenderer = Platform.GetRenderer(view);

            var viewGroup = vRenderer.View;

            vRenderer.Tracker?.UpdateLayout();
            var layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);

            viewGroup.LayoutParameters = layoutParams;
            view.Layout(size);
            viewGroup.Layout(0, 0, (int)view.WidthRequest, (int)view.HeightRequest);
            return(viewGroup);
        }
コード例 #24
0
ファイル: IosXFPopupSrvc.cs プロジェクト: thaihung203/xfpopup
        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);
        }
コード例 #25
0
ファイル: WPXFPopupSrvc.cs プロジェクト: thaihung203/xfpopup
        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);
        }