Improved 3D touch implementation, and added example

Summary:
public
This diff improves the implementation of 3D touch by adding a `forceTouchAvailable` constant to View that can be used to check if the feature is supported.

I've also added an example of how you can use the `force` property of the touch event to measure touch pressure in React Native.

Reviewed By: vjeux

Differential Revision: D2864926

fb-gh-sync-id: 754c54989212ce4e4863716ceaba59673f0bb29d
This commit is contained in:
Nick Lockwood
2016-01-27 09:04:14 -08:00
committed by facebook-github-bot-9
parent 21a4c6e853
commit f685878938
7 changed files with 144 additions and 60 deletions

View File

@@ -434,6 +434,19 @@ UIWindow *__nullable RCTKeyWindow(void)
return RCTSharedApplication().keyWindow;
}
BOOL RCTForceTouchAvailable(void)
{
static BOOL forceSupported;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
forceSupported = [UITraitCollection class] &&
[UITraitCollection instancesRespondToSelector:@selector(forceTouchCapability)];
});
return forceSupported &&
(RCTKeyWindow() ?: [UIView new]).traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable;
}
UIAlertView *__nullable RCTAlertView(NSString *title,
NSString *__nullable message,
id __nullable delegate,
@@ -475,7 +488,7 @@ id __nullable RCTNilIfNull(id __nullable value)
return value == (id)kCFNull ? nil : value;
}
RCT_EXTERN double RCTZeroIfNaN(double value)
double RCTZeroIfNaN(double value)
{
return isnan(value) || isinf(value) ? 0 : value;
}