Skip to content

Commit

Permalink
Build the framework for RCTParagraphComponentAccessibilityProvider
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ZHUANGPP authored and facebook-github-bot committed Jul 2, 2020
1 parent e881b24 commit ffa0725
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ffa0725

Please sign in to comment.