@samitouri / QOS-React-2 / commits / cf649b40a5

Move TouchHistoryMath to React Native repo (#12557)

This isn't used by React core and is just a pure helper so it might as well live where it's used. The React Native repo.

Sebastian Markbåge committed Apr 5, 2018 at 20:29 UTC cf649b40a56dc5c0ffe2595b963847f0ff8de245
4 files changed -172
packages/events/TouchHistoryMath.js deleted
-151
@@ -1,151 +0,0 @@
1 -/**
2 - * Copyright (c) 2016-present, Facebook, Inc.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - */
7 -
8 -const TouchHistoryMath = {
9 - /**
10 - * This code is optimized and not intended to look beautiful. This allows
11 - * computing of touch centroids that have moved after `touchesChangedAfter`
12 - * timeStamp. You can compute the current centroid involving all touches
13 - * moves after `touchesChangedAfter`, or you can compute the previous
14 - * centroid of all touches that were moved after `touchesChangedAfter`.
15 - *
16 - * @param {TouchHistoryMath} touchHistory Standard Responder touch track
17 - * data.
18 - * @param {number} touchesChangedAfter timeStamp after which moved touches
19 - * are considered "actively moving" - not just "active".
20 - * @param {boolean} isXAxis Consider `x` dimension vs. `y` dimension.
21 - * @param {boolean} ofCurrent Compute current centroid for actively moving
22 - * touches vs. previous centroid of now actively moving touches.
23 - * @return {number} value of centroid in specified dimension.
24 - */
25 - centroidDimension: function(
26 - touchHistory,
27 - touchesChangedAfter,
28 - isXAxis,
29 - ofCurrent,
30 - ) {
31 - const touchBank = touchHistory.touchBank;
32 - let total = 0;
33 - let count = 0;
34 -
35 - const oneTouchData =
36 - touchHistory.numberActiveTouches === 1
37 - ? touchHistory.touchBank[touchHistory.indexOfSingleActiveTouch]
38 - : null;
39 -
40 - if (oneTouchData !== null) {
41 - if (
42 - oneTouchData.touchActive &&
43 - oneTouchData.currentTimeStamp > touchesChangedAfter
44 - ) {
45 - total +=
46 - ofCurrent && isXAxis
47 - ? oneTouchData.currentPageX
48 - : ofCurrent && !isXAxis
49 - ? oneTouchData.currentPageY
50 - : !ofCurrent && isXAxis
51 - ? oneTouchData.previousPageX
52 - : oneTouchData.previousPageY;
53 - count = 1;
54 - }
55 - } else {
56 - for (let i = 0; i < touchBank.length; i++) {
57 - const touchTrack = touchBank[i];
58 - if (
59 - touchTrack !== null &&
60 - touchTrack !== undefined &&
61 - touchTrack.touchActive &&
62 - touchTrack.currentTimeStamp >= touchesChangedAfter
63 - ) {
64 - let toAdd; // Yuck, program temporarily in invalid state.
65 - if (ofCurrent && isXAxis) {
66 - toAdd = touchTrack.currentPageX;
67 - } else if (ofCurrent && !isXAxis) {
68 - toAdd = touchTrack.currentPageY;
69 - } else if (!ofCurrent && isXAxis) {
70 - toAdd = touchTrack.previousPageX;
71 - } else {
72 - toAdd = touchTrack.previousPageY;
73 - }
74 - total += toAdd;
75 - count++;
76 - }
77 - }
78 - }
79 - return count > 0 ? total / count : TouchHistoryMath.noCentroid;
80 - },
81 -
82 - currentCentroidXOfTouchesChangedAfter: function(
83 - touchHistory,
84 - touchesChangedAfter,
85 - ) {
86 - return TouchHistoryMath.centroidDimension(
87 - touchHistory,
88 - touchesChangedAfter,
89 - true, // isXAxis
90 - true, // ofCurrent
91 - );
92 - },
93 -
94 - currentCentroidYOfTouchesChangedAfter: function(
95 - touchHistory,
96 - touchesChangedAfter,
97 - ) {
98 - return TouchHistoryMath.centroidDimension(
99 - touchHistory,
100 - touchesChangedAfter,
101 - false, // isXAxis
102 - true, // ofCurrent
103 - );
104 - },
105 -
106 - previousCentroidXOfTouchesChangedAfter: function(
107 - touchHistory,
108 - touchesChangedAfter,
109 - ) {
110 - return TouchHistoryMath.centroidDimension(
111 - touchHistory,
112 - touchesChangedAfter,
113 - true, // isXAxis
114 - false, // ofCurrent
115 - );
116 - },
117 -
118 - previousCentroidYOfTouchesChangedAfter: function(
119 - touchHistory,
120 - touchesChangedAfter,
121 - ) {
122 - return TouchHistoryMath.centroidDimension(
123 - touchHistory,
124 - touchesChangedAfter,
125 - false, // isXAxis
126 - false, // ofCurrent
127 - );
128 - },
129 -
130 - currentCentroidX: function(touchHistory) {
131 - return TouchHistoryMath.centroidDimension(
132 - touchHistory,
133 - 0, // touchesChangedAfter
134 - true, // isXAxis
135 - true, // ofCurrent
136 - );
137 - },
138 -
139 - currentCentroidY: function(touchHistory) {
140 - return TouchHistoryMath.centroidDimension(
141 - touchHistory,
142 - 0, // touchesChangedAfter
143 - false, // isXAxis
144 - true, // ofCurrent
145 - );
146 - },
147 -
148 - noCentroid: -1,
149 -};
150 -
151 -export default TouchHistoryMath;
packages/react-native-renderer/src/ReactFabric.js
-2
@@ -14,7 +14,6 @@ import './ReactFabricInjection';
14
15 import * as ReactPortal from 'shared/ReactPortal';
16 import * as ReactGenericBatching from 'events/ReactGenericBatching';
17 -import TouchHistoryMath from 'events/TouchHistoryMath';
17 import ReactVersion from 'shared/ReactVersion';
18
19 import NativeMethodsMixin from './NativeMethodsMixin';
@@ -87,7 +86,6 @@ const ReactFabric: ReactNativeType = {
86 ReactNativeBridgeEventPlugin, // requireNativeComponent
87 ReactNativeComponentTree, // ScrollResponder
88 ReactNativePropRegistry, // flattenStyle, Stylesheet
90 - TouchHistoryMath, // PanResponder
89 createReactNativeComponentClass, // RCTText, RCTView, ReactNativeART
90 takeSnapshot, // react-native-implementation
91 },
packages/react-native-renderer/src/ReactNativeRenderer.js
-2
@@ -14,7 +14,6 @@ import './ReactNativeInjection';
14
15 import * as ReactPortal from 'shared/ReactPortal';
16 import * as ReactGenericBatching from 'events/ReactGenericBatching';
17 -import TouchHistoryMath from 'events/TouchHistoryMath';
17 import ReactVersion from 'shared/ReactVersion';
18 // Module provided by RN:
19 import UIManager from 'UIManager';
@@ -106,7 +105,6 @@ const ReactNativeRenderer: ReactNativeType = {
105 ReactNativeBridgeEventPlugin, // requireNativeComponent
106 ReactNativeComponentTree, // ScrollResponder
107 ReactNativePropRegistry, // flattenStyle, Stylesheet
109 - TouchHistoryMath, // PanResponder
108 createReactNativeComponentClass, // RCTText, RCTView, ReactNativeART
109 takeSnapshot, // react-native-implementation
110 computeComponentStackForErrorReporting,
scripts/rollup/shims/react-native/TouchHistoryMath.js deleted
-17
@@ -1,17 +0,0 @@
1 -/**
2 - * Copyright (c) 2013-present, Facebook, Inc.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @providesModule TouchHistoryMath
8 - */
9 -
10 -'use strict';
11 -
12 -const {
13 - __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
14 -} = require('ReactNative');
15 -
16 -module.exports =
17 - __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.TouchHistoryMath;