From fff5dc39436cfe705ec40c0518926a450b5ef98c Mon Sep 17 00:00:00 2001 From: Matt Apperson Date: Wed, 27 Jan 2016 07:13:14 -0800 Subject: [PATCH] Add 3dTouch props to touch events Summary: This adds the first of the three 3dTouch API types, that found on the touch event. It adds the `force` prop to touch events when running on iOS 9 devices: Closes https://github.com/facebook/react-native/pull/3055 Reviewed By: svcscm Differential Revision: D2860540 Pulled By: nicklockwood fb-gh-sync-id: 95a3eb433837c844f755b3ed4a3dfcb28452c284 --- React/Base/RCTTouchHandler.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/React/Base/RCTTouchHandler.m b/React/Base/RCTTouchHandler.m index f2490a7ad..c0f6b6f42 100644 --- a/React/Base/RCTTouchHandler.m +++ b/React/Base/RCTTouchHandler.m @@ -108,7 +108,7 @@ typedef NS_ENUM(NSInteger, RCTTouchEventType) { } // Create touch - NSMutableDictionary *reactTouch = [[NSMutableDictionary alloc] initWithCapacity:9]; + NSMutableDictionary *reactTouch = [[NSMutableDictionary alloc] initWithCapacity:11]; reactTouch[@"target"] = reactTag; reactTouch[@"identifier"] = @(touchID); reactTouch[@"touches"] = (id)kCFNull; // We hijack this touchObj to serve both as an event @@ -150,6 +150,12 @@ typedef NS_ENUM(NSInteger, RCTTouchEventType) { reactTouch[@"locationX"] = @(touchViewLocation.x); reactTouch[@"locationY"] = @(touchViewLocation.y); reactTouch[@"timestamp"] = @(nativeTouch.timestamp * 1000); // in ms, for JS + + if ([nativeTouch.view respondsToSelector:@selector(traitCollection)] && + [nativeTouch.view.traitCollection respondsToSelector:@selector(forceTouchCapability)]) { + + reactTouch[@"force"] = @(RCTZeroIfNaN(nativeTouch.force/nativeTouch.maximumPossibleForce)); + } } /**