Beispiel #1
0
 public void OnTransitionStart(Android.Transitions.Transition transition)
 {
     _startingType = _container.LayerType;
     if (_startingType != LayerType.Hardware && !_container.IsDisposed())
     {
         _container.SetLayerType(LayerType.Hardware, null);
     }
 }
Beispiel #2
0
        public static void Focus(this AView platformView, FocusRequest request)
        {
            request.IsFocused = true;

            // Android does the actual focus/unfocus work on the main looper
            // So in case we're setting the focus in response to another control's un-focusing,
            // we need to post the handling of it to the main looper so that it happens _after_ all the other focus
            // work is done; otherwise, a call to ClearFocus on another control will kill the focus we set

            var q = Looper.MyLooper();

            if (q != null)
            {
                new Handler(q).Post(RequestFocus);
            }
            else
            {
                MainThread.InvokeOnMainThreadAsync(RequestFocus);
            }

            void RequestFocus()
            {
                if (platformView == null || platformView.IsDisposed())
                {
                    return;
                }

                platformView?.RequestFocus();
            }
        }
Beispiel #3
0
        public static void SetClipToOutline(this AView view, bool value)
        {
            if (view.IsDisposed() || !Forms.IsLollipopOrNewer)
            {
                return;
            }

            view.ClipToOutline = value;
        }
Beispiel #4
0
        public static bool GetClipToOutline(this AView view)
        {
            if (view.IsDisposed() || !Forms.IsLollipopOrNewer)
            {
                return(false);
            }

            return(view.ClipToOutline);
        }
Beispiel #5
0
        public static bool SetElevation(this AView view, float value)
        {
            if (view.IsDisposed() || !Forms.IsLollipopOrNewer)
            {
                return(false);
            }

            view.Elevation = value;
            return(true);
        }
Beispiel #6
0
        public static void EnsureId(this AView view)
        {
            if (view.IsDisposed())
            {
                return;
            }

            if (view.Id == AView.NoId)
            {
                view.Id = AppCompat.Platform.GenerateViewId();
            }
        }
Beispiel #7
0
        public static void SetClipToOutline(this AView view, bool value, VisualElement element)
        {
            if (view.IsDisposed())
            {
                return;
            }

            var shouldClip = value;

            if (element is Frame frame)
            {
                shouldClip = frame.IsSet(Layout.IsClippedToBoundsProperty)
                                        ? frame.IsClippedToBounds : frame.CornerRadius > 0f;
            }

            if (view is FastRenderers.FrameRenderer && System.Maui.Maui.IsLollipopOrNewer)
            {
                view.SetClipToOutline(shouldClip);
                return;
            }

            // setClipBounds is only available in API 18 +
            if ((int)Build.VERSION.SdkInt >= 18)
            {
                if (!(view is ViewGroup viewGroup))
                {
                    return;
                }

                // Forms layouts should not impose clipping on their children
                viewGroup.SetClipChildren(false);

                // But if IsClippedToBounds is true, they _should_ enforce clipping at their own edges
                viewGroup.ClipBounds = shouldClip ? new Rect(0, 0, viewGroup.Width, viewGroup.Height) : null;
            }
            else
            {
                // For everything in 17 and below, use the setClipChildren method
                if (!(view.Parent is ViewGroup parent))
                {
                    return;
                }

                if ((int)Build.VERSION.SdkInt >= 18 && parent.ClipChildren == shouldClip)
                {
                    return;
                }

                parent.SetClipChildren(shouldClip);
                parent.Invalidate();
            }
        }
Beispiel #8
0
        public static void Focus(this AView platformView, FocusRequest request)
        {
            // Android does the actual focus/unfocus work on the main looper
            // So in case we're setting the focus in response to another control's un-focusing,
            // we need to post the handling of it to the main looper so that it happens _after_ all the other focus
            // work is done; otherwise, a call to ClearFocus on another control will kill the focus we set here
            MainThread.BeginInvokeOnMainThread(() =>
            {
                if (platformView == null || platformView.IsDisposed())
                {
                    return;
                }

                platformView?.RequestFocus();
            });
        }
Beispiel #9
0
        public static void EnsureLongClickCancellation(this AView view, MotionEvent motionEvent, bool handled, VisualElement element)
        {
            if (view.IsDisposed())
            {
                return;
            }

            if (motionEvent.Action == MotionEventActions.Up && handled && view.LongClickable && element.IsInViewCell())
            {
                // In order for long presses/clicks (for opening context menus) to work in a ViewCell
                // which contains any Clickable Views (e.g., any with TapGestures associated, or Buttons)
                // the top-level container in the ViewCell has to be LongClickable; unfortunately, Android
                // cancels a pending long press/click during MotionEventActions.Up, which the View won't
                // get if the gesture listener has already processed it. So when all these conditions are
                // true, we need to go ahead and send the Up event to the View; if we don't, the context menu will open
                view.OnTouchEvent(motionEvent);
            }
        }