Esempio n. 1
0
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();
            if (_lastSize.Equals(CGSize.Empty) || !_lastSize.Equals(Frame.Size))
            {
                _view.Layout(Frame.ToRectangle());
                _lastSize = Frame.Size;
            }

            _nativeView.Frame = ContentView.Bounds;
        }
Esempio n. 2
0
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();
            if (_lastSize.Equals(CGSize.Empty) || !_lastSize.Equals(Frame.Size))
            {
                _viewCell.View.Layout(Frame.ToRectangle());
                _viewCell.OnSizeChanged(new Xamarin.Forms.Size(Frame.Size.Width, Frame.Size.Height));
                _lastSize = Frame.Size;
            }

            _view.Frame = ContentView.Bounds;
        }
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();

            if (_lastSize.Equals(CGSize.Empty) || !_lastSize.Equals(Frame.Size) && ViewCell != null)
            {
                ViewCell?.View?.Layout(Frame.ToRectangle());
                _lastSize = Frame.Size;
            }

            if (_view != null && !_view.Frame.Equals(Bounds))
            {
                _view.Frame = Bounds;
            }
        }
Esempio n. 4
0
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();

            if (_lastSize.Equals(CGSize.Empty) || !_lastSize.Equals(Frame.Size))
            {
                _viewCell.View.Layout(Frame.ToRectangle());
                var result = _viewCell.View.Measure(-1, -1, MeasureFlags.IncludeMargins);
                //ContentView.Bounds = new CGRect(ContentView.Bounds.X, ContentView.Bounds.Y, result.Minimum.Width, 200);
                //ContentView.Frame = new CGRect(ContentView.Frame.X, ContentView.Frame.Y, result.Minimum.Width, 200);
                //_viewCell.View.Layout(new Rectangle(0, 0, result.Minimum.Width, 200));
                _lastSize = Frame.Size;
            }

            _view.Frame = ContentView.Bounds;
        }
Esempio n. 5
0
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();
            //TODO update sizes of the xamarin view
            if (_lastSize.Equals(CGSize.Empty) || !_lastSize.Equals(Frame.Size) || true)
            {
                var layout = _fastCell.View as Layout <View>;
                if (layout != null)
                {
                    layout.Layout(Frame.ToRectangle());
                    layout.ForceLayout();
                    FixChildLayouts(layout);
                }
                _lastSize = Frame.Size;
            }

            _view.Frame = ContentView.Bounds;
        }
Esempio n. 6
0
        public override void SetFrameSize(CGSize newSize)
        {
            bool changed = !newSize.Equals(Frame.Size);

            base.SetFrameSize(newSize);
            if (changed)
            {
                context.InvokeUserCode(eventSink.OnBoundsChanged);
            }
        }
Esempio n. 7
0
        public override UIImage ToNativeImage(CGSize targetSize, UIColor color = default(UIColor), Thickness margin = default(Thickness))
        {
            if (bezierPath == null)
            {
                return(null);
            }

            CGSize imageSize = bezierPath.Bounds.Size;

            if ((int)imageSize.Width <= 0 && (int)imageSize.Height <= 0)
            {
                return(null);
            }

            if (nfloat.IsNaN(targetSize.Width) && nfloat.IsNaN(targetSize.Height))
            {
                targetSize = new CGSize(0.85f * imageSize.Width, 0.85f * imageSize.Height);
            }
            else if (nfloat.IsNaN(targetSize.Width))
            {
                targetSize.Width = (imageSize.Width / imageSize.Height) * targetSize.Height;
            }
            else if (nfloat.IsNaN(targetSize.Height))
            {
                targetSize.Height = (imageSize.Height / imageSize.Width) * targetSize.Width;
            }

            if ((int)targetSize.Width <= 0 && (int)targetSize.Height <= 0)
            {
                return(null);
            }

            nfloat scale     = 1f;
            var    translate = CGPoint.Empty;

            if (!imageSize.Equals(targetSize))
            {
                var scaleX = targetSize.Width / imageSize.Width;
                var scaleY = targetSize.Height / imageSize.Height;
                scale = (nfloat)Math.Min(targetSize.Width / imageSize.Width, targetSize.Height / imageSize.Height);

                if (scaleX > scaleY)
                {
                    translate.X = (targetSize.Width - (imageSize.Width * scale)) * 0.5f;
                }
                else if (scaleX < scaleY)
                {
                    translate.Y = (targetSize.Height - (imageSize.Height * scale)) * 0.5f;
                }
            }

            UIImage image;

#if __IOS__
            UIGraphics.BeginImageContextWithOptions(targetSize, false, 0);
            using (var context = UIGraphics.GetCurrentContext()) {
                context.TranslateCTM(translate.X, translate.Y);
                context.ScaleCTM(scale, scale);

                context.InterpolationQuality = CGInterpolationQuality.High;
                context.SetFillColor((color ?? UIColor.Black).CGColor);
                bezierPath.UsesEvenOddFillRule = (FillRule == FillRule.EvenOdd);
                bezierPath.Fill();

                image = UIGraphics.GetImageFromCurrentImageContext();
                UIGraphics.EndImageContext();
            }
#elif __MACOS__
            // macOS TODO
            image = null;
#endif

            return(image);
        }
Esempio n. 8
0
        /*static TPKeyboardAvoidingState KeyboardAvoidingState()
         * {
         * TPKeyboardAvoidingState state = State;
         * if(state == null)
         * state = new TPKeyboardAvoidingState();
         *
         * return state;
         * }*/

        public static void TPKeyboardAvoiding_keyboardWillShow(this UIScrollView scrollView, NSNotification notification)
        {
            CGRect keyboardRect = scrollView.ConvertRectFromView((notification.UserInfo.ObjectForKey(UIKeyboard.FrameEndUserInfoKey) as NSValue).CGRectValue, null);

            if (keyboardRect == CGRect.Empty)
            {
                return;
            }

            //TPKeyboardAvoidingState state = KeyboardAvoidingState();
            if (State == null)
            {
                State = new TPKeyboardAvoidingState();
            }

            UIView firstResponder = scrollView.TPKeyboardAvoiding_findFirstResponderBeneathView(scrollView);

            if (firstResponder == null)
            {
                return;
            }

            State.keyboardRect = keyboardRect;

            if (!State.keyboardVisible)
            {
                State.priorInset = scrollView.ContentInset;
                State.priorScrollIndicatorInsets = scrollView.ScrollIndicatorInsets;
                State.priorPagingEnabled         = scrollView.PagingEnabled;
            }

            State.keyboardVisible    = true;
            scrollView.PagingEnabled = false;

            if (scrollView is TPKeyboardAvoidingScrollView)
            {
                State.priorContentSize = scrollView.ContentSize;

                if (CGSize.Equals(scrollView.ContentSize, new CGSize(0, 0)))
                {
                    // Set the content size, if it's not set. Do not set content size explicitly if auto-layout
                    // is being used to manage subviews
                    scrollView.ContentSize = scrollView.TPKeyboardAvoiding_calculatedContentSizeFromSubviewFrames();
                }
            }

            // Shrink view's inset by the keyboard's height, and scroll to show the text field/view being edited
            //TODO : need fix
            UIView.BeginAnimations(null);
            NSNumber number = notification.UserInfo.ValueForKey(UIKeyboard.AnimationCurveUserInfoKey) as NSNumber;

            UIView.SetAnimationCurve((UIViewAnimationCurve)number.Int32Value);
            number = notification.UserInfo.ValueForKey(UIKeyboard.AnimationDurationUserInfoKey) as NSNumber;
            UIView.SetAnimationDuration(number.FloatValue);
            //          UIView.SetAnimationCurve (UIViewAnimationCurve.EaseIn);
            //          UIView.SetAnimationDuration (1.0);

            scrollView.ContentInset = scrollView.TPKeyboardAvoiding_contentInsetForKeyboard();

            nfloat viewableHeight = scrollView.Bounds.Size.Height - scrollView.ContentInset.Top - scrollView.ContentInset.Bottom;

            scrollView.SetContentOffset(new CGPoint(scrollView.ContentOffset.X, (nfloat)scrollView.TPKeyboardAvoiding_idealOffsetForViewwithViewingAreaHeight(firstResponder, viewableHeight)), false);

            scrollView.ScrollIndicatorInsets = scrollView.ContentInset;
            scrollView.LayoutIfNeeded();

            UIView.CommitAnimations();
        }