Fabric: Implementatiton of <View hitSlop={}/> on the native side

Summary: The implementation was basically ported from existing one.

Reviewed By: fkgozali

Differential Revision: D8344057

fbshipit-source-id: c0ec3b7b986080eab62532244da73859b445fcbb
This commit is contained in:
Valentin Shergin 2018-06-15 11:25:24 -07:00 committed by Facebook Github Bot
parent cde30eb6b7
commit 8bdc1ff10b
2 changed files with 18 additions and 0 deletions

View File

@ -45,6 +45,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, strong, nullable) NSString *nativeId;
/**
* Insets used when hit testing inside this view.
*/
@property (nonatomic, assign) UIEdgeInsets hitTestEdgeInsets;
@end
NS_ASSUME_NONNULL_END

View File

@ -36,6 +36,14 @@ using namespace facebook::react;
}
}
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
if (UIEdgeInsetsEqualToEdgeInsets(self.hitTestEdgeInsets, UIEdgeInsetsZero)) {
return [super pointInside:point withEvent:event];
}
CGRect hitFrame = UIEdgeInsetsInsetRect(self.bounds, self.hitTestEdgeInsets);
return CGRectContainsPoint(hitFrame, point);
}
- (void)updateProps:(SharedProps)props
oldProps:(SharedProps)oldProps
@ -53,6 +61,11 @@ using namespace facebook::react;
}
// TODO: Implement all sutable non-layout <View> props.
// `hitSlop`
if (oldViewProps.hitSlop != newViewProps.hitSlop) {
self.hitTestEdgeInsets = RCTUIEdgeInsetsFromEdgeInsets(newViewProps.hitSlop);
}
// `nativeId`
if (oldViewProps.nativeId != newViewProps.nativeId) {
self.nativeId = [NSString stringWithCString:newViewProps.nativeId.c_str()