mirror of
https://github.com/status-im/react-native.git
synced 2025-01-13 02:54:42 +00:00
[React Native] Add magic tap accessibility gesture
This commit is contained in:
parent
1c70f33511
commit
a4f92ba3db
@ -98,6 +98,13 @@ var View = React.createClass({
|
|||||||
PropTypes.oneOf(AccessibilityTraits),
|
PropTypes.oneOf(AccessibilityTraits),
|
||||||
PropTypes.arrayOf(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.
|
* Used to locate this view in end-to-end tests.
|
||||||
*/
|
*/
|
||||||
|
@ -22,6 +22,7 @@ ReactNativeViewAttributes.UIView = {
|
|||||||
accessibilityTraits: true,
|
accessibilityTraits: true,
|
||||||
testID: true,
|
testID: true,
|
||||||
onLayout: true,
|
onLayout: true,
|
||||||
|
onMagicTap: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
ReactNativeViewAttributes.RCTView = merge(
|
ReactNativeViewAttributes.RCTView = merge(
|
||||||
|
@ -1309,6 +1309,9 @@ RCT_EXPORT_METHOD(clearJSResponder)
|
|||||||
@"topLoadingError": @{
|
@"topLoadingError": @{
|
||||||
@"registrationName": @"onLoadingError"
|
@"registrationName": @"onLoadingError"
|
||||||
},
|
},
|
||||||
|
@"topMagicTap": @{
|
||||||
|
@"registrationName": @"onMagicTap"
|
||||||
|
},
|
||||||
} mutableCopy];
|
} mutableCopy];
|
||||||
|
|
||||||
[_viewManagers enumerateKeysAndObjectsUsingBlock:^(NSString *name, RCTViewManager *manager, BOOL *stop) {
|
[_viewManagers enumerateKeysAndObjectsUsingBlock:^(NSString *name, RCTViewManager *manager, BOOL *stop) {
|
||||||
|
@ -15,8 +15,13 @@
|
|||||||
|
|
||||||
@protocol RCTAutoInsetsProtocol;
|
@protocol RCTAutoInsetsProtocol;
|
||||||
|
|
||||||
|
@class RCTView;
|
||||||
|
typedef void (^RCTViewMagicTapHandler)(RCTView *view);
|
||||||
|
|
||||||
@interface RCTView : UIView
|
@interface RCTView : UIView
|
||||||
|
|
||||||
|
@property (nonatomic, copy) RCTViewMagicTapHandler magicTapHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to control how touch events are processed.
|
* Used to control how touch events are processed.
|
||||||
*/
|
*/
|
||||||
|
@ -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
|
#pragma mark - Statics for dealing with layoutGuides
|
||||||
|
|
||||||
+ (void)autoAdjustInsetsForView:(UIView<RCTAutoInsetsProtocol> *)parentView
|
+ (void)autoAdjustInsetsForView:(UIView<RCTAutoInsetsProtocol> *)parentView
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#import "RCTUIManager.h"
|
#import "RCTUIManager.h"
|
||||||
#import "RCTUtils.h"
|
#import "RCTUtils.h"
|
||||||
#import "RCTView.h"
|
#import "RCTView.h"
|
||||||
|
#import "UIView+React.h"
|
||||||
|
|
||||||
@implementation RCTConvert(UIAccessibilityTraits)
|
@implementation RCTConvert(UIAccessibilityTraits)
|
||||||
|
|
||||||
@ -171,6 +172,19 @@ RCT_CUSTOM_VIEW_PROPERTY(borderWidth, CGFloat, RCTView)
|
|||||||
view.layer.borderWidth = json ? [RCTConvert CGFloat:json] : defaultView.layer.borderWidth;
|
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) \
|
#define RCT_VIEW_BORDER_PROPERTY(SIDE) \
|
||||||
RCT_CUSTOM_VIEW_PROPERTY(border##SIDE##Width, CGFloat, RCTView) \
|
RCT_CUSTOM_VIEW_PROPERTY(border##SIDE##Width, CGFloat, RCTView) \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user