[React Native] Add magic tap accessibility gesture

This commit is contained in:
Alex Akers 2015-05-19 06:21:52 -07:00
parent 1c70f33511
commit a4f92ba3db
6 changed files with 40 additions and 0 deletions

View File

@ -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.
*/

View File

@ -22,6 +22,7 @@ ReactNativeViewAttributes.UIView = {
accessibilityTraits: true,
testID: true,
onLayout: true,
onMagicTap: true,
};
ReactNativeViewAttributes.RCTView = merge(

View File

@ -1309,6 +1309,9 @@ RCT_EXPORT_METHOD(clearJSResponder)
@"topLoadingError": @{
@"registrationName": @"onLoadingError"
},
@"topMagicTap": @{
@"registrationName": @"onMagicTap"
},
} mutableCopy];
[_viewManagers enumerateKeysAndObjectsUsingBlock:^(NSString *name, RCTViewManager *manager, BOOL *stop) {

View File

@ -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.
*/

View File

@ -167,6 +167,16 @@ static NSString *RCTRecursiveAccessibilityLabel(UIView *view)
}
}
- (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

View File

@ -17,6 +17,7 @@
#import "RCTUIManager.h"
#import "RCTUtils.h"
#import "RCTView.h"
#import "UIView+React.h"
@implementation RCTConvert(UIAccessibilityTraits)
@ -171,6 +172,19 @@ RCT_CUSTOM_VIEW_PROPERTY(borderWidth, CGFloat, RCTView)
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) \