コード例 #1
0
ファイル: ViewHandler.Android.cs プロジェクト: Glepooek/maui
        static partial void MappingSemantics(IViewHandler handler, IView view)
        {
            if (handler.PlatformView == null)
            {
                return;
            }

            AccessibilityDelegateCompat?accessibilityDelegate = null;

            if (handler.PlatformView is View viewPlatform)
            {
                accessibilityDelegate = ViewCompat.GetAccessibilityDelegate(viewPlatform) as MauiAccessibilityDelegateCompat;
            }

            if (handler.PlatformView is not PlatformView platformView)
            {
                return;
            }

            platformView = platformView.GetSemanticPlatformElement();

            var desc = view.Semantics?.Description;
            var hint = view.Semantics?.Hint;

            // We use MauiAccessibilityDelegateCompat to fix the issue of AutomationId breaking accessibility
            // Because AutomationId gets set on the contentDesc we have to clear that out on the accessibility node via
            // the use of our MauiAccessibilityDelegateCompat
            if (!string.IsNullOrWhiteSpace(hint) ||
                !string.IsNullOrWhiteSpace(desc) ||
                !string.IsNullOrWhiteSpace(view.AutomationId))
            {
                if (accessibilityDelegate == null)
                {
                    var currentDelegate = ViewCompat.GetAccessibilityDelegate(platformView);
                    if (currentDelegate is MauiAccessibilityDelegateCompat)
                    {
                        currentDelegate = null;
                    }

                    accessibilityDelegate = new MauiAccessibilityDelegateCompat(currentDelegate)
                    {
                        Handler = handler
                    };

                    ViewCompat.SetAccessibilityDelegate(platformView, accessibilityDelegate);
                }

                if (!string.IsNullOrWhiteSpace(hint) ||
                    !string.IsNullOrWhiteSpace(desc))
                {
                    platformView.ImportantForAccessibility = ImportantForAccessibility.Yes;
                }
            }
            else if (accessibilityDelegate != null)
            {
                ViewCompat.SetAccessibilityDelegate(platformView, null);
            }
        }
コード例 #2
0
ファイル: ViewHandler.Android.cs プロジェクト: hevey/maui
 partial void DisconnectingHandler(NativeView nativeView)
 {
     if (nativeView.IsAlive() &&
         ViewCompat.GetAccessibilityDelegate(nativeView) is MauiAccessibilityDelegateCompat ad)
     {
         ad.Handler = null;
         ViewCompat.SetAccessibilityDelegate(nativeView, null);
     }
 }
コード例 #3
0
ファイル: ViewHandler.Android.cs プロジェクト: Glepooek/maui
        partial void DisconnectingHandler(PlatformView platformView)
        {
            if (platformView.IsAlive())
            {
                platformView.FocusChange -= OnPlatformViewFocusChange;

                if (ViewCompat.GetAccessibilityDelegate(platformView) is MauiAccessibilityDelegateCompat ad)
                {
                    ad.Handler = null;
                    ViewCompat.SetAccessibilityDelegate(platformView, null);
                }
            }
        }
コード例 #4
0
ファイル: ViewHandler.Android.cs プロジェクト: hevey/maui
        static partial void MappingSemantics(IViewHandler handler, IView view)
        {
            if (handler.NativeView == null)
            {
                return;
            }

            var accessibilityDelegate = ViewCompat.GetAccessibilityDelegate(handler.NativeView as View) as MauiAccessibilityDelegateCompat;

            if (view.Semantics != null && accessibilityDelegate == null)
            {
                if (handler.NativeView is not NativeView nativeView)
                {
                    return;
                }

                if (nativeView is AndroidX.AppCompat.Widget.SearchView sv)
                {
                    nativeView = sv.FindViewById(Resource.Id.search_button) !;
                }

                if (!string.IsNullOrWhiteSpace(view.Semantics.Hint) || !string.IsNullOrWhiteSpace(view.Semantics.Description))
                {
                    if (accessibilityDelegate == null)
                    {
                        var currentDelegate = ViewCompat.GetAccessibilityDelegate(nativeView);
                        if (currentDelegate is MauiAccessibilityDelegateCompat)
                        {
                            currentDelegate = null;
                        }

                        accessibilityDelegate = new MauiAccessibilityDelegateCompat(currentDelegate)
                        {
                            Handler = handler
                        };

                        ViewCompat.SetAccessibilityDelegate(nativeView, accessibilityDelegate);
                    }
                }
                else if (accessibilityDelegate != null)
                {
                    ViewCompat.SetAccessibilityDelegate(nativeView, null);
                }

                if (accessibilityDelegate != null)
                {
                    nativeView.ImportantForAccessibility = ImportantForAccessibility.Yes;
                }
            }
        }
コード例 #5
0
 static partial void MappingSemantics(IViewHandler handler, IView view)
 {
     if (view.Semantics != null &&
         handler is ViewHandler viewHandler &&
         viewHandler.AccessibilityDelegate == null &&
         ViewCompat.GetAccessibilityDelegate(handler.NativeView as NativeView) == null)
     {
         if (!string.IsNullOrEmpty(view.Semantics.Hint))
         {
             viewHandler.AccessibilityDelegate = new MauiAccessibilityDelegate()
             {
                 Handler = viewHandler
             };
             ViewCompat.SetAccessibilityDelegate(handler.NativeView as NativeView, viewHandler.AccessibilityDelegate);
         }
     }
 }
コード例 #6
0
        static partial void MappingSemantics(ViewHandler handler, IView view)
        {
            if (handler.NativeView == null)
            {
                return;
            }

            if (view.Semantics != null &&
                handler is ViewHandler viewHandler &&
                viewHandler.AccessibilityDelegate == null &&
                ViewCompat.GetAccessibilityDelegate(handler.NativeView as NativeView) == null)
            {
                if (handler.NativeView is not NativeView nativeView)
                {
                    return;
                }

                if (nativeView is AndroidX.AppCompat.Widget.SearchView sv)
                {
                    nativeView = sv.FindViewById(Resource.Id.search_button) !;
                }

                if (!string.IsNullOrWhiteSpace(view.Semantics.Hint) || !string.IsNullOrWhiteSpace(view.Semantics.Description))
                {
                    if (viewHandler.AccessibilityDelegate == null)
                    {
                        viewHandler.AccessibilityDelegate = new MauiAccessibilityDelegate()
                        {
                            Handler = viewHandler
                        };
                        ViewCompat.SetAccessibilityDelegate(nativeView, viewHandler.AccessibilityDelegate);
                    }
                }
                else if (viewHandler.AccessibilityDelegate != null)
                {
                    viewHandler.AccessibilityDelegate = null;
                    ViewCompat.SetAccessibilityDelegate(nativeView, null);
                }

                if (viewHandler.AccessibilityDelegate != null)
                {
                    nativeView.ImportantForAccessibility = ImportantForAccessibility.Yes;
                }
            }
        }
コード例 #7
0
        internal static void AddOrRemoveControlsAccessibilityDelegate(this View virtualView)
        {
            if (virtualView?.Handler?.NativeView is not AView view)
            {
                return;
            }

            bool needsDelegate   = virtualView.ControlsAccessibilityDelegateNeeded();
            var  currentDelegate = ViewCompat.GetAccessibilityDelegate(view);

            if (needsDelegate)
            {
                if (currentDelegate is ControlsAccessibilityDelegate)
                {
                    return;
                }

                // This means the current delegate didn't come from our code at all so we just exit and assume
                // the user wants full control of the delegate
                // If the user is inheriting from AccessibilityDelegateCompatWrapper then we will continue wrapping
                if (currentDelegate != null && currentDelegate is not AccessibilityDelegateCompatWrapper)
                {
                    return;
                }

                var controlsDelegate = new ControlsAccessibilityDelegate(currentDelegate, virtualView.Handler);
                ViewCompat.SetAccessibilityDelegate(view, controlsDelegate);
            }
            else if (currentDelegate != null)
            {
                if (currentDelegate is ControlsAccessibilityDelegate cad)
                {
                    ViewCompat.SetAccessibilityDelegate(view, cad.WrappedDelegate);
                    return;
                }
            }
        }