Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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;
                }
            }
        }