From ffa07254de914f7876a17ec2d1ecac1dc10b116a Mon Sep 17 00:00:00 2001 From: Jiayan Zhuang Date: Thu, 2 Jul 2020 08:53:42 -0700 Subject: [PATCH] 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 --- ...TParagraphComponentAccessibilityProvider.h | 23 ++++++++++ ...ParagraphComponentAccessibilityProvider.mm | 46 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentAccessibilityProvider.h create mode 100644 React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentAccessibilityProvider.mm diff --git a/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentAccessibilityProvider.h b/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentAccessibilityProvider.h new file mode 100644 index 00000000000..30ad700e02a --- /dev/null +++ b/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentAccessibilityProvider.h @@ -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 + +#import + +#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 *)accessibilityElements; + +@end diff --git a/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentAccessibilityProvider.mm b/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentAccessibilityProvider.mm new file mode 100644 index 00000000000..248e5a437f3 --- /dev/null +++ b/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentAccessibilityProvider.mm @@ -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 +#import +#import +#import + +#import "RCTConversions.h" +#import "RCTFabricComponentsPlugins.h" + +using namespace facebook::react; + +@implementation RCTParagraphComponentAccessibilityProvider { + NSMutableArray *_accessibilityElements; + AttributedString _attributedString; + __weak UIView *_view; +} + +- (instancetype)initWithString:(AttributedString)attributedString view:(UIView *)view +{ + if (self = [super init]) { + _attributedString = attributedString; + _view = view; + } + return self; +} + +- (NSArray *)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