Permalink
Browse files

Added ability to set custom accessibility tap handler to React Native

  • Loading branch information...
Georgiy Kassabli
Georgiy Kassabli committed May 20, 2015
1 parent 32666f0 commit d211359aeba005f30643d66d0dd1d212db1307e4
@@ -99,6 +99,12 @@ var View = React.createClass({
PropTypes.arrayOf(PropTypes.oneOf(AccessibilityTraits)),
]),
/**
* When `accessible` is true, the system will try to invoke this function
* when the user performs accessibility tap gesture.
*/
onAcccessibilityTap: PropTypes.func,
/**
* When `accessible` is true, the system will invoke this function when the
* user performs the magic tap gesture.
@@ -22,6 +22,7 @@ ReactNativeViewAttributes.UIView = {
accessibilityTraits: true,
testID: true,
onLayout: true,
onAccessibilityTap: true,
onMagicTap: true,
};
@@ -1309,6 +1309,9 @@ - (NSDictionary *)customDirectEventTypes
@"topLoadingError": @{
@"registrationName": @"onLoadingError"
},
@"topAccessibilityTap": @{
@"registrationName": @"onAccessibilityTap"
},
@"topMagicTap": @{
@"registrationName": @"onMagicTap"
},
View
@@ -16,11 +16,12 @@
@protocol RCTAutoInsetsProtocol;
@class RCTView;
typedef void (^RCTViewMagicTapHandler)(RCTView *view);
typedef void (^RCTViewEventHandler)(RCTView *view);
@interface RCTView : UIView
@property (nonatomic, copy) RCTViewMagicTapHandler magicTapHandler;
@property (nonatomic, copy) RCTViewEventHandler accessibilityTapHandler;
@property (nonatomic, copy) RCTViewEventHandler magicTapHandler;
/**
* Used to control how touch events are processed.
View
@@ -167,6 +167,16 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
}
}
- (BOOL)accessibilityActivate
{
if (self.accessibilityTapHandler) {
self.accessibilityTapHandler(self);
return YES;
} else {
return NO;
}
}
- (BOOL)accessibilityPerformMagicTap
{
if (self.magicTapHandler) {
@@ -172,18 +172,26 @@ - (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(RCTSparseArray *)
view.layer.borderWidth = json ? [RCTConvert CGFloat:json] : defaultView.layer.borderWidth;
}
}
RCT_CUSTOM_VIEW_PROPERTY(onAccessibilityTap, BOOL, RCTView)
{
view.accessibilityTapHandler = [self eventHandlerWithName:@"topAccessibilityTap" json:json];
}
RCT_CUSTOM_VIEW_PROPERTY(onMagicTap, BOOL, RCTView)
{
RCTViewMagicTapHandler handler = nil;
view.magicTapHandler = [self eventHandlerWithName:@"topMagicTap" json:json];
}
- (RCTViewEventHandler)eventHandlerWithName:(NSString *)eventName json:(id)json
{
RCTViewEventHandler 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];
[weakSelf.bridge.eventDispatcher sendInputEventWithName:eventName body:body];
};
}
view.magicTapHandler = handler;
return handler;
}
#define RCT_VIEW_BORDER_PROPERTY(SIDE) \

0 comments on commit d211359

Please sign in to comment.