Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ViewModel] Implement UIAccessibilityTraitButton #22

Open
CharlesMcD opened this issue Feb 3, 2022 · 0 comments
Open

[ViewModel] Implement UIAccessibilityTraitButton #22

CharlesMcD opened this issue Feb 3, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@CharlesMcD
Copy link
Member

When using a simple ViewModel instead of a ButtonViewModel, we don't see any of the buttons being described as "button", because the view model is bound to plain views. One way to fix this is to force the accessibility role or trait.

On iOS, you simply add the UIAccessibilityTraitButton trait to the accessibilityTraits value: view.accessibilityTraits |= .button

On Android, it's a bit more complicated, you have to use an accessibilityDelegate to force the class name, or override view.onInitializeAccessibilityNodeInfo

ViewCompat.setAccessibilityDelegate(model, object : AccessibilityDelegateCompat() {
    override fun onInitializeAccessibilityNodeInfo(host: View, info: AccessibilityNodeInfoCompat) {
        super.onInitializeAccessibilityNodeInfo(host, info)
        info.className = android.widget.Button::class.java.name
    }

This wouldn't be necessary it the button view model were attached to actual button views.

Thanks @dominiclabbe for the proposition!

@CharlesMcD CharlesMcD added the enhancement New feature or request label Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant