Build the framework for RCTParagraphComponentAccessibilityProvider

Summary:
Changelog:
[iOS][Added] - This is the first step to build RCTParagraphComponentAccessibilityProvider.  The main idea of RCTParagraphComponentAccessibilityProvider is to provide an array of accessible elements for the AttributedString in PCTParagraphComponentView.

Reviewed By: sammy-SC

Differential Revision: D22214855

fbshipit-source-id: 69d47555e86452620f89a4b2e21ed6065c8e669c
This commit is contained in:
Jiayan Zhuang
2020-07-02 08:55:39 -07:00
committed by Facebook GitHub Bot
parent e881b244ca
commit ffa07254de
2 changed files with 69 additions and 0 deletions
@@ -0,0 +1,23 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <UIKit/UIKit.h>
#import <react/attributedstring/AttributedString.h>
#import "RCTParagraphComponentView.h"
@interface RCTParagraphComponentAccessibilityProvider : NSObject
- (instancetype)initWithString:(facebook::react::AttributedString)attributedString view:(UIView *)view;
/**
@abstract Array of accessibleElements for use in UIAccessibilityContainer implementation.
*/
- (NSArray<UIAccessibilityElement *> *)accessibilityElements;
@end
@@ -0,0 +1,46 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTParagraphComponentAccessibilityProvider.h"
#import <Foundation/Foundation.h>
#import <react/components/text/ParagraphProps.h>
#import <react/textlayoutmanager/RCTTextLayoutManager.h>
#import <react/textlayoutmanager/TextLayoutManager.h>
#import "RCTConversions.h"
#import "RCTFabricComponentsPlugins.h"
using namespace facebook::react;
@implementation RCTParagraphComponentAccessibilityProvider {
NSMutableArray<UIAccessibilityElement *> *_accessibilityElements;
AttributedString _attributedString;
__weak UIView *_view;
}
- (instancetype)initWithString:(AttributedString)attributedString view:(UIView *)view
{
if (self = [super init]) {
_attributedString = attributedString;
_view = view;
}
return self;
}
- (NSArray<UIAccessibilityElement *> *)accessibilityElements
{
// verify if accessibleElements are exist
// build an array of the accessibleElements
// add first element has the text for the whole textview in order to read out the whole text
// add additional elements for those parts of text with embedded link so VoiceOver could specially recognize links
// add accessible element for truncation attributed string for automation purposes only
_accessibilityElements = [NSMutableArray new];
return _accessibilityElements;
}
@end