mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 01:40:08 +00:00
Added ability to set custom accessibility tap handler to React Native
This commit is contained in:
parent
32666f0aa2
commit
d211359aeb
@ -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 @@ RCT_EXPORT_METHOD(clearJSResponder)
|
||||
@"topLoadingError": @{
|
||||
@"registrationName": @"onLoadingError"
|
||||
},
|
||||
@"topAccessibilityTap": @{
|
||||
@"registrationName": @"onAccessibilityTap"
|
||||
},
|
||||
@"topMagicTap": @{
|
||||
@"registrationName": @"onMagicTap"
|
||||
},
|
||||
|
@ -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.
|
||||
|
@ -167,6 +167,16 @@ static NSString *RCTRecursiveAccessibilityLabel(UIView *view)
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)accessibilityActivate
|
||||
{
|
||||
if (self.accessibilityTapHandler) {
|
||||
self.accessibilityTapHandler(self);
|
||||
return YES;
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)accessibilityPerformMagicTap
|
||||
{
|
||||
if (self.magicTapHandler) {
|
||||
|
@ -172,18 +172,26 @@ RCT_CUSTOM_VIEW_PROPERTY(borderWidth, CGFloat, RCTView)
|
||||
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) \
|
||||
|
Loading…
x
Reference in New Issue
Block a user