Skip to content

Commit

Permalink
[React Native] Add magic tap accessibility gesture
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Akers committed May 19, 2015
1 parent 1c70f33 commit a4f92ba
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Libraries/Components/View/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ var View = React.createClass({
PropTypes.oneOf(AccessibilityTraits),
PropTypes.arrayOf(PropTypes.oneOf(AccessibilityTraits)),
]),

/**
* When `accessible` is true, the system will invoke this function when the
* user performs the magic tap gesture.
*/
onMagicTap: PropTypes.func,

/**
* Used to locate this view in end-to-end tests.
*/
Expand Down
1 change: 1 addition & 0 deletions Libraries/ReactNative/ReactNativeViewAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ReactNativeViewAttributes.UIView = {
accessibilityTraits: true,
testID: true,
onLayout: true,
onMagicTap: true,
};

ReactNativeViewAttributes.RCTView = merge(
Expand Down
3 changes: 3 additions & 0 deletions React/Modules/RCTUIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,9 @@ - (NSDictionary *)customDirectEventTypes
@"topLoadingError": @{
@"registrationName": @"onLoadingError"
},
@"topMagicTap": @{
@"registrationName": @"onMagicTap"
},
} mutableCopy];

[_viewManagers enumerateKeysAndObjectsUsingBlock:^(NSString *name, RCTViewManager *manager, BOOL *stop) {
Expand Down
5 changes: 5 additions & 0 deletions React/Views/RCTView.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@

@protocol RCTAutoInsetsProtocol;

@class RCTView;
typedef void (^RCTViewMagicTapHandler)(RCTView *view);

@interface RCTView : UIView

@property (nonatomic, copy) RCTViewMagicTapHandler magicTapHandler;

/**
* Used to control how touch events are processed.
*/
Expand Down
10 changes: 10 additions & 0 deletions React/Views/RCTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
}
}

- (BOOL)accessibilityPerformMagicTap
{
if (self.magicTapHandler) {
self.magicTapHandler(self);
return YES;
} else {
return NO;
}
}

#pragma mark - Statics for dealing with layoutGuides

+ (void)autoAdjustInsetsForView:(UIView<RCTAutoInsetsProtocol> *)parentView
Expand Down
14 changes: 14 additions & 0 deletions React/Views/RCTViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import "RCTUIManager.h"
#import "RCTUtils.h"
#import "RCTView.h"
#import "UIView+React.h"

@implementation RCTConvert(UIAccessibilityTraits)

Expand Down Expand Up @@ -171,6 +172,19 @@ - (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(RCTSparseArray *)
view.layer.borderWidth = json ? [RCTConvert CGFloat:json] : defaultView.layer.borderWidth;
}
}
RCT_CUSTOM_VIEW_PROPERTY(onMagicTap, BOOL, RCTView)
{
RCTViewMagicTapHandler handler = nil;
if ([RCTConvert BOOL:json]) {
__weak RCTViewManager *weakSelf = self;
handler = ^(RCTView *tappedView) {
NSDictionary *body = @{ @"target": tappedView.reactTag };
[weakSelf.bridge.eventDispatcher sendInputEventWithName:@"topMagicTap" body:body];
};
}

view.magicTapHandler = handler;
}

#define RCT_VIEW_BORDER_PROPERTY(SIDE) \
RCT_CUSTOM_VIEW_PROPERTY(border##SIDE##Width, CGFloat, RCTView) \
Expand Down

0 comments on commit a4f92ba

Please sign in to comment.