Fabric: Added support of `accessibilityCustomActions` for <View>
Summary: @public Another small but important piece of Accessibility Support. Reviewed By: mdvacca Differential Revision: D8528921 fbshipit-source-id: d4ba87bab702d76a90e9ddb751999193243cdc74
This commit is contained in:
parent
3ea4a3309f
commit
ad78971569
|
@ -51,6 +51,16 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
*/
|
||||
@property (nonatomic, strong, nullable) UIColor *foregroundColor;
|
||||
|
||||
/**
|
||||
* Returns the object - usually (sub)view - which represents this
|
||||
* component view in terms of accessibility.
|
||||
* All accessibility properties will be applied to this object.
|
||||
* May be overridden in subclass which needs to be accessiblitywise
|
||||
* transparent in favour of some subview.
|
||||
* Defaults to `self`.
|
||||
*/
|
||||
@property (nonatomic, strong, nullable, readonly) NSObject *accessibilityElement;
|
||||
|
||||
/**
|
||||
* Insets used when hit testing inside this view.
|
||||
*/
|
||||
|
|
|
@ -131,6 +131,10 @@ using namespace facebook::react;
|
|||
if (oldViewProps.nativeId != newViewProps.nativeId) {
|
||||
self.nativeId = RCTNSStringFromString(newViewProps.nativeId);
|
||||
}
|
||||
|
||||
// `accessible`
|
||||
if (oldViewProps.accessible != newViewProps.accessible) {
|
||||
self.accessibilityElement.isAccessibilityElement = newViewProps.accessible;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,11 +150,65 @@ using namespace facebook::react;
|
|||
_layoutMetrics = layoutMetrics;
|
||||
|
||||
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
|
||||
}
|
||||
|
||||
- (void)invalidateBorder
|
||||
{
|
||||
const auto &props = *std::dynamic_pointer_cast<const ViewProps>(_props);
|
||||
|
||||
bool useCoreAnimationBorderRendering =
|
||||
props.borderStyle == BorderStyle::Solid &&
|
||||
props.borderWidth.isUniformed() &&
|
||||
props.borderRadius.isUniformed();
|
||||
|
||||
CALayer *layer = self.layer;
|
||||
if (_isCoreAnimationBorderRenderingEnabled != useCoreAnimationBorderRendering) {
|
||||
_isCoreAnimationBorderRenderingEnabled = useCoreAnimationBorderRendering;
|
||||
if (!useCoreAnimationBorderRendering) {
|
||||
layer.borderWidth = 0;
|
||||
layer.borderColor = nil;
|
||||
layer.cornerRadius = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (useCoreAnimationBorderRendering) {
|
||||
layer.borderWidth = (CGFloat)props.borderWidth.left;
|
||||
layer.borderColor = RCTCGColorRefFromSharedColor(props.borderColor);
|
||||
layer.cornerRadius = (CGFloat)props.borderRadius.topLeft;
|
||||
_contentView.layer.cornerRadius = (CGFloat)props.borderRadius.topLeft;
|
||||
_contentView.layer.masksToBounds = YES;
|
||||
} else {
|
||||
// Not supported yet.
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Accessibility
|
||||
|
||||
- (NSObject *)accessibilityElement
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Accessibility Events
|
||||
|
||||
- (NSArray<UIAccessibilityCustomAction *> *)accessibilityCustomActions
|
||||
{
|
||||
const auto &accessibilityProps = *std::dynamic_pointer_cast<const AccessibilityProps>(_props);
|
||||
|
||||
if (accessibilityProps.accessibilityActions.size() == 0) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSMutableArray<UIAccessibilityCustomAction *> *customActions = [NSMutableArray array];
|
||||
for (const auto &accessibilityAction : accessibilityProps.accessibilityActions) {
|
||||
[customActions addObject:[[UIAccessibilityCustomAction alloc] initWithName:RCTNSStringFromString(accessibilityAction)
|
||||
target:self
|
||||
selector:@selector(didActivateAccessibilityCustomAction:)]];
|
||||
}
|
||||
|
||||
return [customActions copy];
|
||||
}
|
||||
|
||||
- (BOOL)accessibilityActivate
|
||||
{
|
||||
_eventEmitter->onAccessibilityTap();
|
||||
|
|
|
@ -30,7 +30,7 @@ public:
|
|||
#pragma mark - Props
|
||||
|
||||
const bool accessible {true};
|
||||
const std::string accessibilityActions {""};
|
||||
const std::vector<std::string> accessibilityActions {};
|
||||
const std::string accessibilityLabel {""};
|
||||
const AccessibilityTraits accessibilityTraits {AccessibilityTraits::None};
|
||||
const bool accessibilityViewIsModal {false};
|
||||
|
|
Loading…
Reference in New Issue