Skip to content

Commit 1d7da87

Browse files
msagerydExilz
authored andcommitted
Bundled react-native-scroller and react-native-gesture-responder
1 parent 685a832 commit 1d7da87

File tree

10 files changed

+860
-5
lines changed

10 files changed

+860
-5
lines changed

src/Gallery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { PureComponent } from 'react';
22
import { View, ViewPropTypes } from 'react-native';
33
import PropTypes from 'prop-types';
4-
import { createResponder } from 'react-native-gesture-responder';
4+
import { createResponder } from './libraries/GestureResponder';
55
import TransformableImage from './libraries/TransformableImage';
66
import ViewPager from './libraries/ViewPager';
77

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
export function distance(touchTrackA, touchTrackB, ofCurrent) {
4+
let xa, ya, xb, yb;
5+
if(ofCurrent) {
6+
xa = touchTrackA.currentPageX;
7+
ya = touchTrackA.currentPageY;
8+
xb = touchTrackB.currentPageX;
9+
yb = touchTrackB.currentPageY;
10+
} else {
11+
xa = touchTrackA.previousPageX;
12+
ya = touchTrackA.previousPageY;
13+
xb = touchTrackB.previousPageX;
14+
yb = touchTrackB.previousPageY;
15+
}
16+
return Math.sqrt(Math.pow(xa - xb, 2) + Math.pow(ya - yb, 2));
17+
}
18+
19+
export function maxDistance(touchBank, ofCurrent) {
20+
let max = 0;
21+
for(let i = 0; i < touchBank.length - 1; i++) {
22+
for(let j = i+1; j < touchBank.length; j++) {
23+
let d = distance(touchBank[i], touchBank[j], ofCurrent);
24+
if(d > max) {
25+
max = d;
26+
}
27+
}
28+
}
29+
return max;
30+
}
31+
32+
export function pinchDistance(touchHistory, touchesChangedAfter, ofCurrent) {
33+
let touchBank = touchHistory.touchBank;
34+
if(touchHistory.numberActiveTouches > 1) {
35+
let filteredTouchBank = touchBank.filter((touchTrack) => {
36+
return touchTrack && touchTrack.currentTimeStamp >= touchesChangedAfter;
37+
});
38+
return maxDistance(filteredTouchBank, ofCurrent);
39+
}
40+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* @providesModule TouchHistoryMath
3+
*/
4+
5+
'use strict';
6+
7+
var TouchHistoryMath = {
8+
/**
9+
* This code is optimized and not intended to look beautiful. This allows
10+
* computing of touch centroids that have moved after `touchesChangedAfter`
11+
* timeStamp. You can compute the current centroid involving all touches
12+
* moves after `touchesChangedAfter`, or you can compute the previous
13+
* centroid of all touches that were moved after `touchesChangedAfter`.
14+
*
15+
* @param {TouchHistoryMath} touchHistory Standard Responder touch track
16+
* data.
17+
* @param {number} touchesChangedAfter timeStamp after which moved touches
18+
* are considered "actively moving" - not just "active".
19+
* @param {boolean} isXAxis Consider `x` dimension vs. `y` dimension.
20+
* @param {boolean} ofCurrent Compute current centroid for actively moving
21+
* touches vs. previous centroid of now actively moving touches.
22+
* @return {number} value of centroid in specified dimension.
23+
*/
24+
centroidDimension: function (touchHistory, touchesChangedAfter, isXAxis, ofCurrent) {
25+
var touchBank = touchHistory.touchBank;
26+
var total = 0;
27+
var count = 0;
28+
29+
var oneTouchData = touchHistory.numberActiveTouches === 1 ? touchHistory.touchBank[touchHistory.indexOfSingleActiveTouch] : null;
30+
31+
if (oneTouchData !== null) {
32+
if (oneTouchData.touchActive && oneTouchData.currentTimeStamp > touchesChangedAfter) {
33+
total += ofCurrent && isXAxis ? oneTouchData.currentPageX : ofCurrent && !isXAxis ? oneTouchData.currentPageY : !ofCurrent && isXAxis ? oneTouchData.previousPageX : oneTouchData.previousPageY;
34+
count = 1;
35+
}
36+
} else {
37+
for (var i = 0; i < touchBank.length; i++) {
38+
var touchTrack = touchBank[i];
39+
if (touchTrack !== null && touchTrack !== undefined && touchTrack.touchActive && touchTrack.currentTimeStamp >= touchesChangedAfter) {
40+
var toAdd; // Yuck, program temporarily in invalid state.
41+
if (ofCurrent && isXAxis) {
42+
toAdd = touchTrack.currentPageX;
43+
} else if (ofCurrent && !isXAxis) {
44+
toAdd = touchTrack.currentPageY;
45+
} else if (!ofCurrent && isXAxis) {
46+
toAdd = touchTrack.previousPageX;
47+
} else {
48+
toAdd = touchTrack.previousPageY;
49+
}
50+
total += toAdd;
51+
count++;
52+
}
53+
}
54+
}
55+
return count > 0 ? total / count : TouchHistoryMath.noCentroid;
56+
},
57+
58+
currentCentroidXOfTouchesChangedAfter: function (touchHistory, touchesChangedAfter) {
59+
return TouchHistoryMath.centroidDimension(touchHistory, touchesChangedAfter, true, // isXAxis
60+
true // ofCurrent
61+
);
62+
},
63+
64+
currentCentroidYOfTouchesChangedAfter: function (touchHistory, touchesChangedAfter) {
65+
return TouchHistoryMath.centroidDimension(touchHistory, touchesChangedAfter, false, // isXAxis
66+
true // ofCurrent
67+
);
68+
},
69+
70+
previousCentroidXOfTouchesChangedAfter: function (touchHistory, touchesChangedAfter) {
71+
return TouchHistoryMath.centroidDimension(touchHistory, touchesChangedAfter, true, // isXAxis
72+
false // ofCurrent
73+
);
74+
},
75+
76+
previousCentroidYOfTouchesChangedAfter: function (touchHistory, touchesChangedAfter) {
77+
return TouchHistoryMath.centroidDimension(touchHistory, touchesChangedAfter, false, // isXAxis
78+
false // ofCurrent
79+
);
80+
},
81+
82+
currentCentroidX: function (touchHistory) {
83+
return TouchHistoryMath.centroidDimension(touchHistory, 0, // touchesChangedAfter
84+
true, // isXAxis
85+
true // ofCurrent
86+
);
87+
},
88+
89+
currentCentroidY: function (touchHistory) {
90+
return TouchHistoryMath.centroidDimension(touchHistory, 0, // touchesChangedAfter
91+
false, // isXAxis
92+
true // ofCurrent
93+
);
94+
},
95+
96+
noCentroid: -1
97+
};
98+
99+
module.exports = TouchHistoryMath;

0 commit comments

Comments
 (0)