Skip to content

Commit

Permalink
Accessibility Escape
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #22047

Differential Revision: D13146179

Pulled By: cpojer

fbshipit-source-id: b8a089114a5deafee47dd482e484d413c8c39137
  • Loading branch information
rustle authored and facebook-github-bot committed Dec 7, 2018
1 parent 900f2df commit ee7c702
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions Libraries/Components/View/ReactNativeViewAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ReactNativeViewAttributes.UIView = {
onAccessibilityAction: true,
onAccessibilityTap: true,
onMagicTap: true,
onAccessibilityEscape: true,
collapsable: true,
needsOffscreenAlphaCompositing: true,
style: ReactNativeStyleAttributes,
Expand Down
8 changes: 8 additions & 0 deletions Libraries/Components/View/ViewPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ type DirectEventProps = $ReadOnly<{|
* See http://facebook.github.io/react-native/docs/view.html#onmagictap
*/
onMagicTap?: ?() => void,

/**
* When `accessible` is `true`, the system will invoke this function when the
* user performs the escape gesture.
*
* See http://facebook.github.io/react-native/docs/view.html#onaccessibilityescape
*/
onAccessibilityEscape?: ?Function,
|}>;

type TouchEventProps = $ReadOnly<{|
Expand Down
5 changes: 5 additions & 0 deletions RNTester/js/AccessibilityIOSExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class AccessibilityIOSExample extends React.Component<{}> {
accessible={true}>
<Text>Accessibility magic tap example</Text>
</View>
<View
onAccessibilityEscape={() => alert('onAccessibilityEscape success')}
accessible={true}>
<Text>Accessibility escape example</Text>
</View>
<View accessibilityLabel="Some announcement" accessible={true}>
<Text>Accessibility label example</Text>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,12 @@ - (BOOL)accessibilityPerformMagicTap
return YES;
}

- (BOOL)accessibilityPerformEscape
{
_eventEmitter->onAccessibilityEscape();
return YES;
}

- (BOOL)didActivateAccessibilityCustomAction:(UIAccessibilityCustomAction *)action
{
_eventEmitter->onAccessibilityAction(RCTStringFromNSString(action.name));
Expand Down
1 change: 1 addition & 0 deletions React/Views/RCTView.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@property (nonatomic, copy) RCTDirectEventBlock onAccessibilityAction;
@property (nonatomic, copy) RCTDirectEventBlock onAccessibilityTap;
@property (nonatomic, copy) RCTDirectEventBlock onMagicTap;
@property (nonatomic, copy) RCTDirectEventBlock onAccessibilityEscape;

/**
* Accessibility properties
Expand Down
10 changes: 10 additions & 0 deletions React/Views/RCTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@ - (BOOL)accessibilityPerformMagicTap
}
}

- (BOOL)accessibilityPerformEscape
{
if (_onAccessibilityEscape) {
_onAccessibilityEscape(nil);
return YES;
} else {
return NO;
}
}

- (NSString *)description
{
NSString *superDescription = super.description;
Expand Down
1 change: 1 addition & 0 deletions React/Views/RCTViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ - (RCTShadowView *)shadowView
RCT_REMAP_VIEW_PROPERTY(onAccessibilityAction, reactAccessibilityElement.onAccessibilityAction, RCTDirectEventBlock)
RCT_REMAP_VIEW_PROPERTY(onAccessibilityTap, reactAccessibilityElement.onAccessibilityTap, RCTDirectEventBlock)
RCT_REMAP_VIEW_PROPERTY(onMagicTap, reactAccessibilityElement.onMagicTap, RCTDirectEventBlock)
RCT_REMAP_VIEW_PROPERTY(onAccessibilityEscape, reactAccessibilityElement.onAccessibilityEscape, RCTDirectEventBlock)
RCT_REMAP_VIEW_PROPERTY(testID, reactAccessibilityElement.accessibilityIdentifier, NSString)

RCT_EXPORT_VIEW_PROPERTY(backgroundColor, UIColor)
Expand Down
4 changes: 4 additions & 0 deletions ReactCommon/fabric/components/view/ViewEventEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ void ViewEventEmitter::onAccessibilityMagicTap() const {
dispatchEvent("magicTap");
}

void ViewEventEmitter::onAccessibilityEscape() const {
dispatchEvent("accessibilityEscape");
}

#pragma mark - Layout

void ViewEventEmitter::onLayout(const LayoutMetrics &layoutMetrics) const {
Expand Down
1 change: 1 addition & 0 deletions ReactCommon/fabric/components/view/ViewEventEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ViewEventEmitter : public TouchEventEmitter {
void onAccessibilityAction(const std::string &name) const;
void onAccessibilityTap() const;
void onAccessibilityMagicTap() const;
void onAccessibilityEscape() const;

#pragma mark - Layout

Expand Down

0 comments on commit ee7c702

Please sign in to comment.