mirror of
https://github.com/TextureGroup/Texture.git
synced 2026-04-07 19:17:39 +00:00
* [ASDisplayViewAccessibility] A few accessibility improvements This diff includes a few improvements for accessibility in Texture. * When determining a node’s accessibility elements, ignore any elements that are hidden, transparent, or out of the window. This matches UIKit’s behavior. * When sorting the accessible elements and their origins are equal, give precedence to elements with shorter accessibility frames, followed by elements with narrower widths. * Allow the ability to customize the comparator block that sorts the accessibility elements * Create an experiment to stop caching accessibilityElements in `_ASDisplayView`. If we cache elements, we will require users to clear the cache (by calling `setAccessibilityElements` to get the side effect of clearing the cache) when nodes change their hidden state or opacity. This seems like a lot to request of the user. We will put this in an experiment so we can see the perf implication is both when using voice over and when not using voice over. A few other notes: * I got rid of the `ASAccessibilityElementPositioning` protocol in favor of passing `NSObjects` to the sort comparator. `NSObject` implements the informal `UIAccessibilityProtocol` and therefore has an `accessibilityFrame` property. * I removed `static` from the `SortAccessibilityElements()` method definition. This allows me to declare it as `extern` in test it via unit tests.
31 lines
1.9 KiB
Objective-C
31 lines
1.9 KiB
Objective-C
//
|
|
// _ASDisplayViewAccessiblity.h
|
|
// Texture
|
|
//
|
|
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
|
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
|
|
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
// WARNING: When dealing with accessibility elements, please use the `accessibilityElements`
|
|
// property instead of the older methods e.g. `accessibilityElementCount()`. While the older methods
|
|
// should still work as long as accessibility is enabled, this framework provides no guarantees on
|
|
// their correctness. For details, see
|
|
// https://developer.apple.com/documentation/objectivec/nsobject/1615147-accessibilityelements
|
|
|
|
// After recusively collecting all of the accessibility elements of a node, they get sorted. This sort determines
|
|
// the order that a screen reader will traverse the elements. By default, we sort these elements based on their
|
|
// origin: lower y origin comes first, then lower x origin. If 2 nodes have an equal origin, the node with the smaller
|
|
// height is placed before the node with the smaller width. If two nodes have the exact same rect, we throw up our hands
|
|
// and return NSOrderedSame.
|
|
//
|
|
// In general this seems to work fairly well. However, if you want to provide a custom sort you can do so via
|
|
// setUserDefinedAccessibilitySortComparator(). The two elements you are comparing are NSObjects, which conforms to the
|
|
// informal UIAccessibility protocol, so you can safely compare properties like accessibilityFrame.
|
|
typedef NSComparisonResult (^ASSortAccessibilityElementsComparator)(NSObject *, NSObject *);
|
|
|
|
// Use this method to supply your own custom sort comparator used to determine the order of the accessibility elements
|
|
void setUserDefinedAccessibilitySortComparator(ASSortAccessibilityElementsComparator userDefinedComparator);
|