Skip to content

Commit

Permalink
Add 3dTouch props to touch events
Browse files Browse the repository at this point in the history
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 #3055

Reviewed By: svcscm

Differential Revision: D2860540

Pulled By: nicklockwood

fb-gh-sync-id: 95a3eb433837c844f755b3ed4a3dfcb28452c284
  • Loading branch information
Matt Apperson authored and facebook-github-bot-9 committed Jan 27, 2016
1 parent 4bf418a commit fff5dc3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion React/Base/RCTTouchHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ - (void)_recordNewTouches:(NSSet<UITouch *> *)touches
}

// 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
Expand Down Expand Up @@ -150,6 +150,12 @@ - (void)_updateReactTouchAtIndex:(NSInteger)touchIndex
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));
}
}

/**
Expand Down

1 comment on commit fff5dc3

@hufeng
Copy link

@hufeng hufeng commented on fff5dc3 Jan 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love

Please sign in to comment.