iOS Question Add accessibility features in B4i with UIAccessibility API Collection

b4x-de

Active Member
Licensed User
Longtime User
I need to add accessibility features to my iOS apps due to regulation in EU. (For details on the regulative issues in EU see my post in the Android forum here). There seems to be no intuitive way to achieve this in B4i that is comparable to the features in the B4A Accessibility lib. (Maybe I'm missing something? Please correct me if I'm wrong.)

To achieve accessibility in B4i I would like to use features directly from the UIAccessibility API Collection here:

https://developer.apple.com/documentation/objectivec/nsobject/uiaccessibility

Would someone please show me how make one of following methods available in B4i, then I could try to make all other available by myself what might result in new iAccessibility Lib comparable for the Android version.

var isAccessibilityElement: Bool
A Boolean value that indicates whether the element is an accessibility element that an assistive app can access.

var accessibilityLabel: String?
A succinct label in a localized string that identifies the accessibility element.

var accessibilityValue: String?
A localized string that contains the value of the accessibility element.

var accessibilityHint: String?
A localized string that contains a brief description of the result of performing an action on the accessibility element.
 

b4x-de

Active Member
Licensed User
Longtime User
This is a thin wrapper around the accessibility functions of iOS. This is the first draft of what might become an iAccessibility library in the future. I would be happy if you could test the library. Feedback is welcome!

Attached is the iAccessibility class in the b4xlib and an example project that shows how the operation can be used.

Exampe (see attached project):
Public Sub testAccessiblity
    acc.Initialize
    
    setLanguageForAll(Page1.RootPanel, "en-US")
    
    ' Set Description for ui elements
    acc.setAccessibilityHint("This is the first Label", Label1)
    acc.setAccessibilityHint("This is the last Label", Label4)
    
    acc.setAccessibilityHint("Please enter the first text.", TextField1)
    acc.setAccessibilityHint("Please enter the last text.", TextField4)
    
    acc.setAccessibilityHint("This is the button on the bottom of the page.", Button1)
    
    ' Set Label for Textfield
    setLabelsForAll(Page1.RootPanel)
    
    ' Focus
    setFocusForAll(Page1.RootPanel, True)
    acc.setNextFocus(Button1, TextField1)
    
End Sub

Private Sub TextField1_EnterPressed
    acc.focusNext(Sender)
End Sub

Private Sub TextField2_EnterPressed
    acc.focusNext(Sender)
End Sub

Private Sub TextField3_EnterPressed
    acc.focusNext(Sender)
End Sub

Private Sub TextField4_EnterPressed
    acc.focusNext(Sender)
End Sub

private Sub setLanguageForAll(pPanel As Panel, pstrLanguage As String)
    Dim vw As View
    
    For Each vw As View In pPanel.GetAllViewsRecursive
        acc.setAccessibilityLanguage(pstrLanguage, vw)
    Next
End Sub

Public Sub setLabelsForAll(pPanel As Panel)
    Dim i As Int
    Dim vwCurrent As B4XView
    Dim vwNext As B4XView
    
    If pPanel = Null Or Not(pPanel.IsInitialized) Then
        Log($"Failed due to missing or null param."$)
        Return
    End If
    
    For i = 0 To pPanel.NumberOfViews - 1
        vwCurrent = pPanel.GetView(i)
        
        If vwCurrent Is Panel Then
            setLabelsForAll(vwCurrent)
        Else If vwCurrent Is Label And i <= pPanel.NumberOfViews - 2 Then
            vwNext = pPanel.GetView(i + 1)
            If Not(vwNext = Null) And vwNext.IsInitialized Then
                acc.setAccessibilityLabel(vwCurrent, vwNext)
            End If
        End If
    Next
End Sub

In addition, here is the documentation of the class.

iAccessibility

Author:
Version:
0.01
  • iAccessibility
    • Functions:
      • focusNext (pCurrent As View) As View
        Sets the focus on the next view according to the order of the AccessibilityElements
        pCurrent - The current view
        Returns the view that has the next focus or Null if there is no following element to focus
      • Initialize
    • Properties:
 

Attachments

  • iAccessibility.b4xlib
    3.5 KB · Views: 106
  • iAccessibilityTest.zip
    3.7 KB · Views: 105
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…