Inline extractSingleTouch from fbjs

Summary: There is only a single use of this function across RN, and one more use in a test file. I inlined this function in both places to reduce the dependency on fbjs.

Reviewed By: yungsters

Differential Revision: D13138137

fbshipit-source-id: 32660c965a975d17e236bdd13ff0b2a8d64751ee
This commit is contained in:
Christoph Nakazawa
2018-11-26 06:24:05 -08:00
committed by Facebook Github Bot
parent f377926677
commit 2de01cb54d
2 changed files with 31 additions and 7 deletions

View File

@@ -12,21 +12,33 @@
const React = require('React');
const Recording = require('NativeModules').Recording;
const StyleSheet = require('StyleSheet');
const TouchEventUtils = require('fbjs/lib/TouchEventUtils');
const View = require('View');
const extractSingleTouch = nativeEvent => {
const touches = nativeEvent.touches;
const changedTouches = nativeEvent.changedTouches;
const hasTouches = touches && touches.length > 0;
const hasChangedTouches = changedTouches && changedTouches.length > 0;
return !hasTouches && hasChangedTouches
? changedTouches[0]
: hasTouches
? touches[0]
: nativeEvent;
};
class TouchTestApp extends React.Component {
handleStartShouldSetResponder = e => {
return true;
};
handleOnResponderMove = e => {
e = TouchEventUtils.extractSingleTouch(e.nativeEvent);
e = extractSingleTouch(e.nativeEvent);
Recording.record('move;' + e.touches.length);
};
handleResponderStart = e => {
e = TouchEventUtils.extractSingleTouch(e.nativeEvent);
e = extractSingleTouch(e.nativeEvent);
if (e.touches) {
Recording.record('start;' + e.touches.length);
} else {
@@ -35,7 +47,7 @@ class TouchTestApp extends React.Component {
};
handleResponderEnd = e => {
e = TouchEventUtils.extractSingleTouch(e.nativeEvent);
e = extractSingleTouch(e.nativeEvent);
if (e.touches) {
Recording.record('end;' + e.touches.length);
} else {