Skip to content

Instantly share code, notes, and snippets.

@dtopuzov
Last active August 22, 2016 16:32
Show Gist options
  • Save dtopuzov/15fcf41151dc44cb3d32efe1cec130f3 to your computer and use it in GitHub Desktop.
Save dtopuzov/15fcf41151dc44cb3d32efe1cec130f3 to your computer and use it in GitHub Desktop.
App Accessibility in NativeScript

App Accessibility in NativeScript

Native App Accessibility

A well-designed user interface (UI) often has elements that don't require an explicit label to indicate their purpose to the user. A checkbox next to an item in a task list application has a fairly obvious purpose, as does a trash can in a file manager application. However, to your users with vision impairment, other UI cues are needed. Fortunately, both iOS and Android provide APIs for making apps accessible to people with disabilities. Moreover, both platforms provide tools and technologies (like TalkBack and VoiceOver) that can make the lives of the visually impaired easier.

NativeScript Accessibility

The NativeScript framework produces native apps. Thus, all vendor tools for impaired users work right out of the box. Also, all popular automation tools and frameworks that are based on native Android and iOS accessibility models (like Appium) also just work, with no additional bridging code or programming required. In addition to the entire set of native accessibility capabilities, NativeScript also provides cross-platform APIs designed to assist developers with making more accessible apps.

Examples

automationText property that can be set on view:

<GridLayout width="290" automationText="MyGrid" />

On Android this property will set android:contentDescription attribute on specified element, which will help Android accessibility tools and services to work properly. On iOS this will set accessibilityIdentifier which is used to uniquely identify an element in the scripts you write using the UI Automation interfaces.

automationText can also be used with binding in more complex scenarios.

Take a look at the following example from the NativeScript Examples app: Google Play App Store Source

<Repeater.itemTemplate>
    <StackLayout touch="tileTouch" tap="navigateToExample" cssClass="example-item"
        automationText="{{ title }}" 
        orientation="{{ $parents['Repeater'].useListLayout, $parents['Repeater'].useListLayout ? 'horizontal' : 'vertical' }}" 
        visibility="{{ $parents['Repeater'].showOnlyNew, (!$parents['Repeater'].showOnlyNew || isNew) ? 'visible' : 'collapsed' }}">

        <GridLayout horizontalAlignment="center" columns="*" rows="*" 
            cssClass="{{ $parents['Repeater'].useListLayout, $parents['Repeater'].useListLayout ? 'example-img-list' : 'example-img-wrap' }}">
            <Image src="{{ image }}" cssClass="{{ isNew ? 'list-example-image-new' : 'list-example-image' }}"
                borderColor="{{ $parents['Repeater'].group.tint }}"
                stretch="aspectFit" />
            <Image src="{{ $parents['Page'].group.id, 'res://ic_new_' + $parents['Repeater'].group.id }}" cssClass="new" visibility="{{ isNew ? 'visible' : 'collapsed' }}" stretch="none" />
        </GridLayout>

        <StackLayout>
            <Label text="{{ title }}" 
                cssClass="{{ $parents['Repeater'].useListLayout, $parents['Repeater'].useListLayout ? 'example-title-list' : 'example-title-wrap' }}" />
            <Label text="{{ controls }}" textWrap="true" 
                cssClass="{{ $parents['Repeater'].useListLayout, $parents['Repeater'].useListLayout ? 'used-controls-list' : 'used-controls-wrap' }}" />
        </StackLayout>
    </StackLayout>
</Repeater.itemTemplate>

Result is: Image of Android's UI Atomation Viewer with example above

Keep in mind, NativeScript always gives you full access to all native APIs so you can have full control of native accessibility features.

For example:

var signOutButton = page.getViewById("signOutLabel");
signOutButton.android.setClickable(true); 

Summary

Many governments and organizations worldwide mandate apps have accessibility features for impaired users. It is important to us to provide you with all native accessibility features out of the box and also the very best in cross-platform abstractions so you can build and deploy a successful app for all users, regardless of physical abilities.

@vchimev
Copy link

vchimev commented Aug 19, 2016

A typo: Moreover, both platforms ...

@dtopuzov
Copy link
Author

Fixed.

@enchev
Copy link

enchev commented Aug 19, 2016

We need to state explicitly that we support and give direct access to the entire platform API both in Android and iOS. Furthermore you can even set native properties directly in the markup by using .[PLATFORM].myProperty = "some value".

@sipacate
Copy link

" that can make visually impaired live easier." change to " that can make the lives of the visually impaired easier."

"NativeScript framework produces native apps and all vendor tools for impaired work out-of-box. Same apply also for all popular automation tools and framework based on native Android and iOS accessibility models (like Appium). In addition, NativeScript has included cross-platform APIs designed to provide developers with support for making apps more accessible. NativeScript provides"
change to "The NativeScript framework produces native apps. Thus, all vendor tools for impaired users work right out of the box. Also, all popular automation tools and frameworks that are based on native Android and iOS accessibility models (like Appium) also just work, with no additional bridging code or programming required. In addition to the entire set of native accessibility capabilities, NativeScript also provides cross-platform APIs designed to assist developers with making more accessible apps."

"Following example if from NativeScript Examples app:" change to "Take a look at the following example from the NativeScript Examples app" [Add iOS and Android Links]
iOS: https://itunes.apple.com/us/app/examples-nativescript/id1046772499?ls=1&mt=8
Android: https://play.google.com/store/apps/details?id=org.nativescript.examples

"Have in mind that NativeScript lets you access all native APIs from the underlying platform so you can go deeper and have full control of native accessibility APIs."
change to
"Keep in mind, NativeScript always gives you full access to all native APIs so you can have full control of native accessibility features."

If this is the end of the article, add some closing statement like: "Many governments and organizations worldwide mandate apps have accessibility features for impaired users. It is important to us to provide you with all native accessiblity features out of the box and also the very best in cross-platform abstractions so you can build and deploy a successful app for all users, regardless of physical abilities."

@tjvantoll
Copy link

Currently this reads like a documentation article, which I think is a really good thing. Personally I’d prefer to see this published on the docs rather than the blogs.

@dtopuzov
Copy link
Author

Updated after @sipacate comments.

@sipacate
Copy link

I'm fine publishing it on the docs. I'll write an intro article on the blogs if that is what you guys want. However, I'd like to push this live ASAP, as it's the last thing I need in order to send out the latest issue of the newsletter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment