public static View FindFormsViewFromAccessibilityId(this View view, NativeView nativeView)
        {
            View formsView = null;

            var id = nativeView.ContentDescription;

            if (string.IsNullOrWhiteSpace(id))
            {
                formsView = null;
            }
            else if (view.StyleId == id)
            {
                formsView = view;
            }
            else
            {
                var d = view.GetInternalChildren();

                formsView = d == null ? null : d.OfType<View>().FirstOrDefault(a => a.StyleId == id);
            }

            return formsView;
        }
Example #2
0
 public void SetNativeView(NativeView videoView)
 {
     _videoView = videoView;
 }
Example #3
0
 void OnSearchButtonClicked(object?sender, EventArgs e)
 {
     VirtualView?.SearchButtonPressed();
     NativeView?.ResignFirstResponder();
 }
Example #4
0
 private void SetupUserInterface()
 {
     SetupCamera();
     NativeView.Add(_liveCameraStream);
     NativeView.ClipsToBounds = true;
 }
Example #5
0
 protected override void OnBindingContextChanged()
 {
     NativeView.SetBindingContext(BindingContext, (view) => (view as ViewGroup)?.GetChildrenOfType <global::Android.Views.View>());
     base.OnBindingContextChanged();
 }
 public void Invalidate() =>
 NativeView?.InvalidateDrawable();
Example #7
0
 public override void SetVirtualView(IView view)
 {
     base.SetVirtualView(view);
     NativeView.SetElement((Shell)view);
 }
Example #8
0
 protected override void OnBindingContextChanged()
 {
     NativeView.SetBindingContext(BindingContext, nv => nv.Subviews);
     base.OnBindingContextChanged();
 }
Example #9
0
        public override void SetVirtualView(IView view)
        {
            base.SetVirtualView(view);

            NativeView?.CreateTabs(this.VirtualView);
        }
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);

            _page = (GesturedContentPage)e.NewElement;

            // Subscribe to the events here
            if (_page.CaptureSwipeRightToLeft)
            {
                NativeView.AddGestureRecognizer(new UISwipeGestureRecognizer(g => {
                    _page.OnSwipeRightToLeft();
                })
                {
                    Direction = UISwipeGestureRecognizerDirection.Left
                });
            }

            if (_page.CaptureSwipeLeftToRight)
            {
                NativeView.AddGestureRecognizer(new UISwipeGestureRecognizer(g => {
                    _page.OnSwipeLeftToRight();
                })
                {
                    Direction = UISwipeGestureRecognizerDirection.Right
                });
            }

            if (_page.CaptureSwipeBottomToTop)
            {
                NativeView.AddGestureRecognizer(new UISwipeGestureRecognizer(g => {
                    _page.OnSwipeBottomToTop();
                })
                {
                    Direction = UISwipeGestureRecognizerDirection.Up
                });
            }

            if (_page.CaptureSwipeTopToBottom)
            {
                NativeView.AddGestureRecognizer(new UISwipeGestureRecognizer(g => {
                    _page.OnSwipeTopToBottom();
                })
                {
                    Direction = UISwipeGestureRecognizerDirection.Down
                });
            }

            if (_page.CaptureTap)
            {
                NativeView.AddGestureRecognizer(new UITapGestureRecognizer(g => {
                    _page.OnTap();
                })
                {
                    NumberOfTapsRequired = 1
                });
            }

            if (_page.CaptureLongTap)
            {
                NativeView.AddGestureRecognizer(new UILongPressGestureRecognizer(g => {
                    _page.OnLongTap();
                }));
            }
        }
Example #11
0
        public void Measure(int widthMeasureSpec, int heightMeasureSpec, int?maxHeightPixels, int?maxWidthPixels)
        {
            //if (width == -1)
            //	width = double.PositiveInfinity;

            //if (height == -1)
            //	height = double.PositiveInfinity;

            //Width = width;
            //Height = height;
            //MaxWidth = maxWidth;
            //MaxHeight = maxHeight;
            //X = x;
            //Y = y;
            var width     = widthMeasureSpec.GetSize();
            var height    = heightMeasureSpec.GetSize();
            var maxWidth  = maxWidthPixels;
            var maxHeight = maxHeightPixels;

            Context context;

            if (Handler == null || !(_context.TryGetTarget(out context)) || !NativeView.IsAlive())
            {
                return;
            }

            if (View == null)
            {
                //MauiView.Measure(0, 0);
                //MauiView.Arrange(Rectangle.Zero);
                return;
            }

            // NativeView.Measure(widthMeasureSpec, heightMeasureSpec);

            var layoutParams = NativeView.LayoutParameters;

            //if (double.IsInfinity(height))
            //	height = request.Height;

            //if (double.IsInfinity(width))
            //	width = request.Width;

            if (height > maxHeight)
            {
                heightMeasureSpec = MeasureSpecMode.AtMost.MakeMeasureSpec(maxHeight.Value);
            }

            if (width > maxWidth)
            {
                widthMeasureSpec = MeasureSpecMode.AtMost.MakeMeasureSpec(maxWidth.Value);
            }

            if (layoutParams.Width != LP.MatchParent && width > 0)
            {
                layoutParams.Width = width;
            }
            else
            {
                widthMeasureSpec = MeasureSpecMode.Unspecified.MakeMeasureSpec(0);
            }

            if (layoutParams.Height != LP.MatchParent && height > 0)
            {
                layoutParams.Height = height;
            }
            else
            {
                heightMeasureSpec = MeasureSpecMode.Unspecified.MakeMeasureSpec(0);
            }

            NativeView.LayoutParameters = layoutParams;
            //var c = NativeView.Context;
            //var l = (int)c.ToPixels(x);
            //var t = (int)c.ToPixels(y);
            //var r = (int)c.ToPixels(width) + l;
            //var b = (int)c.ToPixels(height) + t;

            //NativeView.Layout(l, t, r, b);
            NativeView.Measure(widthMeasureSpec, heightMeasureSpec);
        }
Example #12
0
        public override void LoadView()
        {
            View panel;
            var  layout = new LinearLayout(Orientation.Vertical)
            {
                SubViews = new View[]
                {
                    new NativeView()
                    {
                        View = new UIView()
                        {
                            BackgroundColor = UIColor.Blue
                        },
                        LayoutParameters = new LayoutParameters(AutoSize.FillParent, 50),
                    },
                    new LinearLayout(Orientation.Vertical)
                    {
                        Padding = new UIEdgeInsets(10, 10, 10, 10),
                        Layer   = new CAGradientLayer()
                        {
                            Colors = new MonoTouch.CoreGraphics.CGColor[]
                            {
                                new MonoTouch.CoreGraphics.CGColor(0.9f, 0.9f, 0.9f, 1f),
                                new MonoTouch.CoreGraphics.CGColor(0.7f, 0.7f, 0.7f, 1f)
                            },
                            Locations = new NSNumber[]
                            {
                                0.0f,
                                1.0f
                            },
                            CornerRadius = 5,
                        },
                        SubViews = new View[]
                        {
                            new NativeView()
                            {
                                View = new UILabel(RectangleF.Empty)
                                {
                                    Text            = "Hello World",
                                    Font            = UIFont.SystemFontOfSize(24),
                                    BackgroundColor = UIColor.Clear,
                                }
                            },
                            panel = new NativeView()
                            {
                                View = new UILabel(RectangleF.Empty)
                                {
                                    Text            = "Goodbye",
                                    Font            = UIFont.SystemFontOfSize(24),
                                    BackgroundColor = UIColor.Clear,
                                }
                            }
                        },
                        LayoutParameters = new LayoutParameters()
                        {
                            Width   = AutoSize.FillParent,
                            Height  = AutoSize.WrapContent,
                            Margins = new UIEdgeInsets(10, 10, 10, 10),
                        },
                    },
                    new NativeView()
                    {
                        View = new UIView()
                        {
                            BackgroundColor = UIColor.Blue
                        },
                        LayoutParameters = new LayoutParameters(AutoSize.FillParent, 50),
                    },
                    new NativeView()
                    {
                        View             = new UIButton(UIButtonType.RoundedRect),
                        LayoutParameters = new LayoutParameters(AutoSize.FillParent, AutoSize.WrapContent),
                        Init             = v =>
                        {
                            v.As <UIButton>().SetTitle("Change Visibility", UIControlState.Normal);
                            v.As <UIButton>().TouchUpInside += (sender, e) =>
                            {
                                switch (panel.LayoutParameters.Visibility)
                                {
                                case Visibility.Gone:
                                    panel.LayoutParameters.Visibility = Visibility.Visible;
                                    break;

                                case Visibility.Visible:
                                    panel.LayoutParameters.Visibility = Visibility.Invisible;
                                    break;

                                case Visibility.Invisible:
                                    panel.LayoutParameters.Visibility = Visibility.Gone;
                                    break;
                                }

                                this.View.SetNeedsLayout();
                            };
                        }
                    }
                },
            };

            // We've now defined our layout, to actually use it we simply create a UILayoutHost control and pass it the layout
            this.View = new XibFree.UILayoutHost(layout);
            this.View.BackgroundColor = UIColor.Gray;
        }
 public void RemoveRecognizer(BaseGestureRecognizer recognizer)
 {
     NativeView.RemoveGestureRecognizer(NativeRecognizer);
     NativeRecognizer = null;
     recognizer.NativeGestureRecognizer = null;
 }
Example #14
0
 void OnSetImageSource(UIImage?obj)
 {
     NativeView.SetImage(obj?.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal);
     NativeView.HorizontalAlignment = UIControlContentHorizontalAlignment.Fill;
     NativeView.VerticalAlignment   = UIControlContentVerticalAlignment.Fill;
 }
Example #15
0
        public override void SetVirtualView(IView view)
        {
            base.SetVirtualView(view);

            NativeView?.Setup(this.VirtualView);
        }
Example #16
0
 public SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint) => NativeView.GetSizeRequest(widthConstraint, heightConstraint, 44.0, 44.0);
 void UpdateFlowDirection()
 {
     NativeView.UpdateFlowDirection(Element);
 }
 public virtual void UpdateValue(string property, object value)
 {
     _mapper?.UpdateProperty(this, VirtualView, property);
     NativeView?.NotifyUpdate();
 }
Example #19
0
 public override Size GetDesiredSize(double widthConstraint, double heightConstraint)
 {
     return(NativeView.GetDesiredSize(widthConstraint, heightConstraint));
 }
 void UpdateContent() =>
 NativeView.UpdateContent(VirtualView.Content, MauiContext);
Example #21
0
        public override void LoadView()
        {
            View panel;
            var layout = new LinearLayout(Orientation.Vertical)
            {
                SubViews = new View[]
                {
                    new NativeView()
                    {
                        View = new UIView()	{ BackgroundColor = UIColor.Blue },
                        LayoutParameters = new LayoutParameters(AutoSize.FillParent, 50),
                    },
                    new LinearLayout(Orientation.Vertical)
                    {
                        Padding = new UIEdgeInsets(10,10,10,10),
                        Layer = new CAGradientLayer()
                        {
                            Colors = new MonoTouch.CoreGraphics.CGColor[]
                            {
                                new MonoTouch.CoreGraphics.CGColor(0.9f, 0.9f, 0.9f, 1f),
                                new MonoTouch.CoreGraphics.CGColor(0.7f, 0.7f, 0.7f, 1f)
                            },
                            Locations = new NSNumber[]
                            {
                                0.0f,
                                1.0f
                            },
                            CornerRadius = 5,
                        },
                        SubViews = new View[]
                        {
                            new NativeView()
                            {
                                View = new UILabel(RectangleF.Empty)
                                {
                                    Text="Hello World",
                                    Font = UIFont.SystemFontOfSize(24),
                                    BackgroundColor = UIColor.Clear,
                                }
                            },
                            panel = new NativeView()
                            {
                                View = new UILabel(RectangleF.Empty)
                                {
                                    Text="Goodbye",
                                    Font = UIFont.SystemFontOfSize(24),
                                    BackgroundColor = UIColor.Clear,
                                }
                            }
                        },
                        LayoutParameters = new LayoutParameters()
                        {
                            Width = AutoSize.FillParent,
                            Height = AutoSize.WrapContent,
                            Margins = new UIEdgeInsets(10,10,10,10),
                        },
                    },
                    new NativeView()
                    {
                        View = new UIView()	{ BackgroundColor = UIColor.Blue },
                        LayoutParameters = new LayoutParameters(AutoSize.FillParent, 50),
                    },
                    new NativeView()
                    {
                        View = new UIButton(UIButtonType.RoundedRect),
                        LayoutParameters = new LayoutParameters(AutoSize.FillParent, AutoSize.WrapContent),
                        Init = v =>
                        {
                            v.As<UIButton>().SetTitle("Change Visibility", UIControlState.Normal);
                            v.As<UIButton>().TouchUpInside += (sender, e) =>
                            {
                                switch (panel.LayoutParameters.Visibility)
                                {
                                    case Visibility.Gone:
                                        panel.LayoutParameters.Visibility = Visibility.Visible;
                                        break;
                                    case Visibility.Visible:
                                        panel.LayoutParameters.Visibility = Visibility.Invisible;
                                        break;
                                    case Visibility.Invisible:
                                        panel.LayoutParameters.Visibility = Visibility.Gone;
                                        break;
                                }

                                this.View.SetNeedsLayout();
                            };
                        }
                    }
                },
            };

            // We've now defined our layout, to actually use it we simply create a UILayoutHost control and pass it the layout
            this.View = new XibFree.UILayoutHost(layout);
            this.View.BackgroundColor=UIColor.Gray;
        }
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);
            if (Element == null)
            {
                return;
            }

            var cx = rect.Width / 2f;
            var cy = rect.Height / 2f;

            var colorSpace = CGColorSpace.CreateDeviceRGB();
            var context    = UIGraphics.GetCurrentContext();

            var gradientColors    = new CGColor[] { UIColor.LightGray.CGColor, Element.BackgroundColor.ToCGColor() };
            var gradientLocations = new nfloat[] { 0f, 1f };
            var gradient          = new CGGradient(colorSpace, gradientColors, gradientLocations);

            var shadow = new NSShadow()
            {
                ShadowColor      = UIColor.Gray,
                ShadowOffset     = new CGSize(3, 3),
                ShadowBlurRadius = 3
            };

            // Draw the hexagon (POINTY-TOP ONLY)
            var radius = Element.Radius;

            if (Element.BorderColor.A > 0 &&
                Element.BorderSize > 0)
            {
                radius -= Element.BorderSize / 2f;
            }
            var points = new List <CGPoint>();

            for (int i = 0; i < 6; ++i)
            {
                points.Add(new CGPoint(cx + radius * Math.Cos((i * 60 - 30) * Math.PI / 180f),
                                       cy + radius * Math.Sin((i * 60 - 30) * Math.PI / 180f)));
            }

            var midPoint = new CGPoint(0.5 * (points[0].X + points[1].X), 0.5 * (points[0].Y + points[1].Y));
            var path     = new CGPath();

            path.MoveToPoint(midPoint);
            for (var i = 0; i < points.Count; ++i)
            {
                path.AddLineToPoint(new CGPoint(points[(i + 1) % points.Count].X, points[(i + 1) % points.Count].Y));
            }
            path.CloseSubpath();

            context.AddPath(path);

            //CoreAnimation.CAShapeLayer mask = new CoreAnimation.CAShapeLayer();
            //context.SetShadow(shadow.ShadowOffset, shadow.ShadowBlurRadius, UIColor.Gray.CGColor);

            context.SetFillColor(Element.BackgroundColor.ToCGColor());
            if (Element.BorderColor.A > 0 &&
                Element.BorderSize > 0)
            {
                context.SetLineWidth((nfloat)Element.BorderSize);
                context.SetStrokeColor(Element.BorderColor.ToCGColor());
                context.DrawPath(CGPathDrawingMode.FillStroke);
            }
            else
            {
                context.DrawPath(CGPathDrawingMode.Fill);
            }
            //context.SaveState();
            //context.BeginTransparencyLayer();
            //path.AddClip();
            //context.DrawLinearGradient(gradient, points[0], points[1], CGGradientDrawingOptions.DrawsAfterEndLocation);
            //context.EndTransparencyLayer();
            //context.RestoreState();

            // Draw Text
            if (!String.IsNullOrEmpty(Element.FAText))
            {
                double eigthHeight   = rect.Height / 8;
                double quarterHeight = rect.Height / 4;
                double threeEights   = eigthHeight * 3;
                if (!String.IsNullOrEmpty(Element.Text))
                {
                    // FAText Icon with Text
                    //CGRect faRect = new CGRect(rect.X, rect.Y + eigthHeight, rect.Width, threeEights);   // no overlap
                    CGRect  faRect  = new CGRect(rect.X, rect.Y + eigthHeight, rect.Width, rect.Height / 2); // bottom of rect slightly overlaps with text-label
                    UILabel faLabel = new UILabel(faRect)
                    {
                        Text          = Element.FAText,
                        TextAlignment = UITextAlignment.Center,
                        TextColor     = Element.TextColor.ToUIColor(),
                        Font          = UIFont.FromName(Element.FAFontFamily,
                                                        (nfloat)Element.FAFontSize)
                    };
                    CGRect  labelRect = new CGRect(rect.X, rect.Height / 2, rect.Width, quarterHeight);
                    UILabel label     = new UILabel(labelRect)
                    {
                        Text          = Element.Text,
                        TextAlignment = UITextAlignment.Center,
                        TextColor     = Element.TextColor.ToUIColor(),
                        Font          = UIFont.FromName(Element.FontFamily,
                                                        (nfloat)Element.FontSize)
                    };
                    NativeView.AddSubviews(new UIView[] { faLabel, label });
                }
                else
                {
                    if (Element.IsMenu)
                    {
                        // FAText Icon only (used for IsMenu property of HexagonLayout)
                        CGRect  faRect  = new CGRect(rect.X, rect.Y + eigthHeight, rect.Width, rect.Height / 2);
                        UILabel faLabel = new UILabel(faRect)
                        {
                            Text          = Element.FAText,
                            TextAlignment = UITextAlignment.Center,
                            TextColor     = Element.TextColor.ToUIColor(),
                            Font          = UIFont.FromName(Element.FAFontFamily,
                                                            (nfloat)Element.FAFontSize)
                        };
                        NativeView.AddSubview(faLabel);
                    }
                    else
                    {
                        // FAText Icon only (centered)
                        CGRect  faRect  = new CGRect(rect.X, rect.Y, rect.Width, rect.Height);
                        UILabel faLabel = new UILabel(faRect)
                        {
                            Text          = Element.FAText,
                            TextAlignment = UITextAlignment.Center,
                            TextColor     = Element.TextColor.ToUIColor(),
                            Font          = UIFont.FromName(Element.FAFontFamily,
                                                            (nfloat)Element.FAFontSize)
                        };
                        NativeView.AddSubview(faLabel);
                    }
                }
            }
            else
            {
                UILabel label = new UILabel(rect)
                {
                    Text          = Element.Text,
                    TextAlignment = UITextAlignment.Center,
                    TextColor     = Element.TextColor.ToUIColor(),
                    Font          = UIFont.FromName(Element.FontFamily,
                                                    (nfloat)Element.FontSize)
                };
                NativeView.AddSubview(label);
            }
        }
Example #23
0
        public void OnResize(int width, int height)
        {
            if (mRealTexture != null)
            {
                mRealTexture.Dispose();
            }
            if (mTmpTexture != null)
            {
                mTmpTexture.Dispose();
            }

            mRealTexture = new SharpDX.Direct3D11.Texture2D(mDevice.Device, new SharpDX.Direct3D11.Texture2DDescription
            {
                ArraySize         = 1,
                BindFlags         = SharpDX.Direct3D11.BindFlags.RenderTarget | SharpDX.Direct3D11.BindFlags.ShaderResource,
                CpuAccessFlags    = SharpDX.Direct3D11.CpuAccessFlags.None,
                Format            = Format.B8G8R8A8_UNorm,
                Height            = height,
                Width             = width,
                MipLevels         = 1,
                OptionFlags       = SharpDX.Direct3D11.ResourceOptionFlags.SharedKeyedmutex,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = SharpDX.Direct3D11.ResourceUsage.Default
            });

            using (var resource = mRealTexture.QueryInterface <SharpDX.DXGI.Resource>())
                mTmpTexture = D2DDevice.OpenSharedResource <Texture2D>(resource.SharedHandle);

            if (NativeView != null)
            {
                NativeView.Dispose();
            }
            NativeView = new SharpDX.Direct3D11.ShaderResourceView(mDevice.Device, mRealTexture,
                                                                   new SharpDX.Direct3D11.ShaderResourceViewDescription
            {
                Format    = Format.B8G8R8A8_UNorm,
                Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D,
                Texture2D = new SharpDX.Direct3D11.ShaderResourceViewDescription.Texture2DResource
                {
                    MipLevels       = 1,
                    MostDetailedMip = 0
                }
            });

            if (RenderTarget != null)
            {
                RenderTarget.Dispose();
            }
            using (var surface = mTmpTexture.QueryInterface <Surface>())
                RenderTarget = new RenderTarget(Direct2DFactory, surface, new RenderTargetProperties()
                {
                    DpiX        = 0.0f,
                    DpiY        = 0.0f,
                    MinLevel    = SharpDX.Direct2D1.FeatureLevel.Level_DEFAULT,
                    PixelFormat = new PixelFormat()
                    {
                        AlphaMode = AlphaMode.Premultiplied, Format = Format.Unknown
                    },
                    Type  = RenderTargetType.Hardware,
                    Usage = RenderTargetUsage.None
                });

            if (mMutex10 != null)
            {
                mMutex10.Dispose();
            }
            if (mMutex11 != null)
            {
                mMutex11.Dispose();
            }

            mMutex10 = mTmpTexture.QueryInterface <KeyedMutex>();
            mMutex11 = mRealTexture.QueryInterface <KeyedMutex>();

            Brushes.Initialize(RenderTarget);
            Fonts.Initialize(DirectWriteFactory);

            Button.Initialize();
            Frame.Initialize();

            // right now the texture is unowned and only a key of 0 will succeed.
            // after releasing it with a specific key said key then can be used for
            // further locking.
            mMutex10.Acquire(0, -1);
            mMutex10.Release(Key11);
        }
Example #24
0
 void OnSetImageSource(ImageSource?nativeImageSource)
 {
     NativeView.UpdateImageSource(nativeImageSource);
 }
Example #25
0
 protected override void DisconnectHandler(LayoutViewGroup nativeView)
 {
     // If we're being disconnected from the xplat element, then we should no longer be managing its chidren
     NativeView?.RemoveAllViews();
     base.DisconnectHandler(nativeView);
 }
        public SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
        {
            var size = NativeView.GetSizeRequest(widthConstraint, heightConstraint, 44.0, 44.0);

            return(size);
        }
Example #27
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (_isDisposed || NativeView == null)
            {
                return;
            }

            NativeView.SetNeedsDisplay();
            NativeView.SetNeedsLayout();

            //if (e.PropertyName == "IsOpened")
            //{
            var     dragView       = Element as eliteElements.eliteVideo;
            CGPoint translation    = panGesture.TranslationInView(Superview);
            var     currentCenterX = Center.X;
            var     currentCenterY = Center.Y;
            int     axisAdditionX  = 20 + (int)(dragView.Width / 2);
            int     axisAdditionY  = 50 + (int)(dragView.Height / 2);

            //if (dragView.IsMenuSandboxEnabled)
            //{
            //SMART CONTAINMENT LOGIC
            //Is on the left side?
            if (currentCenterX <= axisAdditionX)
            {
                currentCenterX += (axisAdditionX - currentCenterX);
                //Upper Y axis
                if (currentCenterY <= axisAdditionY)
                {
                    currentCenterY += (axisAdditionY - currentCenterY);
                }
                //Bottom Y Axis
                if ((currentCenterY + axisAdditionY) >= sH)
                {
                    currentCenterY = (sH - axisAdditionY);
                }

                Center = new CGPoint(currentCenterX, currentCenterY);
            }

            //Left X is good but Y top is not
            if (currentCenterY <= axisAdditionY)
            {
                currentCenterY += (axisAdditionY - currentCenterY);
                if (currentCenterX <= axisAdditionX)
                {
                    currentCenterX += (axisAdditionX - currentCenterX);
                }
                Center = new CGPoint(currentCenterX, currentCenterY);
            }

            //Left X is good but Y bottom is not
            if ((currentCenterY + axisAdditionY) >= sH)
            {
                currentCenterY = (sH - axisAdditionY);
                Center         = new CGPoint(currentCenterX, currentCenterY);
            }

            //Is on the right side?
            if ((currentCenterX + axisAdditionX) >= sW)
            {
                currentCenterX = (sW - axisAdditionX);

                //Upper Y axis
                if (currentCenterY <= axisAdditionY)
                {
                    currentCenterY += (axisAdditionY - currentCenterY);
                }
                //Bottom Y Axis
                if ((currentCenterY + axisAdditionY) >= sH)
                {
                    currentCenterY = (sH - axisAdditionY);
                }

                Center = new CGPoint(currentCenterX, currentCenterY);
            }

            lastLocation = Center;
            //}

            //}

            base.OnElementPropertyChanged(sender, e);
        }
Example #28
0
 void OnSetImageSource(Drawable?obj)
 {
     NativeView.SetImageDrawable(obj);
 }
Example #29
0
 public SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
 {
     return(NativeView.GetSizeRequest(widthConstraint, heightConstraint));
 }
        /// ------------------------------------------------------------------------------------------------
        ///
        protected override void OnElementChanged(Xamarin.Forms.Platform.iOS.ElementChangedEventArgs <View> e)
        {
            try
            {
                base.OnElementChanged(e);
                if (e.OldElement != null)
                {
                    if (formsMap == null)
                    {
                        formsMap = (CustomMap)e.NewElement;
                    }
                    this.MapViewInstance().GetViewForAnnotation = null;
                    customPins.Clear();
                }
                if (e.NewElement != null)
                {
                    if (formsMap == null)
                    {
                        formsMap = (CustomMap)e.NewElement;
                    }
                    var customView = Control as CustomMKAnnotationView;

                    if (Control != null)
                    {
                        Control.RemoveGestureRecognizer(_tapRecogniser);
                    }
                    base.OnElementChanged(e);
                    if (Control != null)
                    {
                        Control.AddGestureRecognizer(_tapRecogniser);
                    }

                    if (customPins == null)
                    {
                        customPins = new List <CustomPin>();
                    }
                    else if (customPins != null && customPins.Count != 0)
                    {
                        customPins.Clear();
                    }

                    var singlePin = MapViewModel.GetCurrentPin();
                    if (singlePin != null)
                    {
                        formsMap.Pins.Add(singlePin.Pin);
                        customPins.Add(singlePin);
                    }
                    formsMap.ClearPins = () =>
                    {
                        if (customPins != null)
                        {
                            formsMap?.Pins.Clear();
                            customPins.Clear();
                        }
                    };
                    formsMap.LoadPins = Pins =>
                    {
                        if (Pins != null)
                        {
                            customPins.Clear();
                            formsMap.Pins.Clear();
                            foreach (var pin in Pins)
                            {
                                formsMap.CustomPins = Pins;
                                formsMap.Pins.Add(pin.Pin);
                                customPins.Add(pin);
                            }
                        }
                    };
                    this.MapViewInstance().GetViewForAnnotation = GetViewForAnnotation;
                    formsMap.DisposeMapControl = () =>
                    {
                        try
                        {
                            //
                            annotationView?.RemoveFromSuperview();
                            annotationView?.Dispose();
                            //
                            _nativeMap?.RemoveFromSuperview();
                            _nativeMap?.Delegate?.Dispose();
                            _nativeMap.Delegate = null;
                            _nativeMap?.Dispose();
                            //
                            NativeView?.RemoveFromSuperview();
                            NativeView?.Dispose();
                            //
                            formsMap   = null;
                            customPins = null;
                            singlePin  = null;
                            //
                            customView?.RemoveFromSuperview();
                            customView?.Dispose();
                            //
                            Control?.RemoveFromSuperview();
                            Control?.Dispose();
                            //
                        }
                        catch (ObjectDisposedException ex)
                        {
                        }
                        catch (Exception ex)
                        {
                        }
                    };
                }
            }
            catch (Exception ex)
            {
            }
        }