Skip to content

Commit

Permalink
Merge pull request #56 from archriss/dev
Browse files Browse the repository at this point in the history
v2.1.5
  • Loading branch information
Exilz authored Jan 12, 2018
2 parents 3d511be + 27762b9 commit c89f299
Show file tree
Hide file tree
Showing 14 changed files with 900 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.js
*.md
14 changes: 7 additions & 7 deletions Demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
"test": "jest"
},
"dependencies": {
"react": "16.0.0-alpha.12",
"react-native": "0.48.2",
"react-native-image-gallery": "2.1.3"
"react": "16.2.0",
"react-native": "0.52.0",
"react-native-image-gallery": "2.1.5"
},
"devDependencies": {
"babel-jest": "21.0.2",
"babel-preset-react-native": "3.0.2",
"jest": "21.0.2",
"react-test-renderer": "16.0.0-alpha.12"
"babel-jest": "22.0.6",
"babel-preset-react-native": "4.0.0",
"jest": "22.0.6",
"react-test-renderer": "16.2.0"
},
"jest": {
"preset": "react-native"
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-image-gallery",
"version": "2.1.4",
"version": "2.1.5",
"description": "Pure JavaScript image gallery component for iOS and Android",
"main": "src/Gallery.js",
"scripts": {
Expand All @@ -18,8 +18,6 @@
"homepage": "https://github.com/archriss/react-native-image-gallery#readme",
"dependencies": {
"prop-types": "^15.6.0",
"react-native-gesture-responder": "0.1.1",
"react-native-scroller": "0.0.6",
"react-mixin": "^3.0.5",
"react-timer-mixin": "^0.13.3"
},
Expand Down
5 changes: 3 additions & 2 deletions src/Gallery.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { PureComponent } from 'react';
import { View, ViewPropTypes } from 'react-native';
import PropTypes from 'prop-types';
import { createResponder } from 'react-native-gesture-responder';
import { createResponder } from './libraries/GestureResponder';
import TransformableImage from './libraries/TransformableImage';
import ViewPager from './libraries/ViewPager';

Expand Down Expand Up @@ -232,7 +232,8 @@ export default class Gallery extends PureComponent {
onViewTransformed && onViewTransformed(transform, pageId);
})}
onTransformGestureReleased={((transform) => {
onTransformGestureReleased && onTransformGestureReleased(transform, pageId);
// need the 'return' here because the return value is checked in ViewTransformer
return onTransformGestureReleased && onTransformGestureReleased(transform, pageId);
})}
ref={((ref) => { this.imageRefs.set(pageId, ref); })}
key={'innerImage#' + pageId}
Expand Down
40 changes: 40 additions & 0 deletions src/libraries/GestureResponder/TouchDistanceMath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

export function distance (touchTrackA, touchTrackB, ofCurrent) {
let xa, ya, xb, yb;
if (ofCurrent) {
xa = touchTrackA.currentPageX;
ya = touchTrackA.currentPageY;
xb = touchTrackB.currentPageX;
yb = touchTrackB.currentPageY;
} else {
xa = touchTrackA.previousPageX;
ya = touchTrackA.previousPageY;
xb = touchTrackB.previousPageX;
yb = touchTrackB.previousPageY;
}
return Math.sqrt(Math.pow(xa - xb, 2) + Math.pow(ya - yb, 2));
}

export function maxDistance (touchBank, ofCurrent) {
let max = 0;
for (let i = 0; i < touchBank.length - 1; i++) {
for (let j = i + 1; j < touchBank.length; j++) {
let d = distance(touchBank[i], touchBank[j], ofCurrent);
if (d > max) {
max = d;
}
}
}
return max;
}

export function pinchDistance (touchHistory, touchesChangedAfter, ofCurrent) {
let touchBank = touchHistory.touchBank;
if (touchHistory.numberActiveTouches > 1) {
let filteredTouchBank = touchBank.filter((touchTrack) => {
return touchTrack && touchTrack.currentTimeStamp >= touchesChangedAfter;
});
return maxDistance(filteredTouchBank, ofCurrent);
}
}
99 changes: 99 additions & 0 deletions src/libraries/GestureResponder/TouchHistoryMath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* @providesModule TouchHistoryMath
*/

'use strict';

var TouchHistoryMath = {
/**
* This code is optimized and not intended to look beautiful. This allows
* computing of touch centroids that have moved after `touchesChangedAfter`
* timeStamp. You can compute the current centroid involving all touches
* moves after `touchesChangedAfter`, or you can compute the previous
* centroid of all touches that were moved after `touchesChangedAfter`.
*
* @param {TouchHistoryMath} touchHistory Standard Responder touch track
* data.
* @param {number} touchesChangedAfter timeStamp after which moved touches
* are considered "actively moving" - not just "active".
* @param {boolean} isXAxis Consider `x` dimension vs. `y` dimension.
* @param {boolean} ofCurrent Compute current centroid for actively moving
* touches vs. previous centroid of now actively moving touches.
* @return {number} value of centroid in specified dimension.
*/
centroidDimension: function (touchHistory, touchesChangedAfter, isXAxis, ofCurrent) {
var touchBank = touchHistory.touchBank;
var total = 0;
var count = 0;

var oneTouchData = touchHistory.numberActiveTouches === 1 ? touchHistory.touchBank[touchHistory.indexOfSingleActiveTouch] : null;

if (oneTouchData !== null) {
if (oneTouchData.touchActive && oneTouchData.currentTimeStamp > touchesChangedAfter) {
total += ofCurrent && isXAxis ? oneTouchData.currentPageX : ofCurrent && !isXAxis ? oneTouchData.currentPageY : !ofCurrent && isXAxis ? oneTouchData.previousPageX : oneTouchData.previousPageY;
count = 1;
}
} else {
for (var i = 0; i < touchBank.length; i++) {
var touchTrack = touchBank[i];
if (touchTrack !== null && touchTrack !== undefined && touchTrack.touchActive && touchTrack.currentTimeStamp >= touchesChangedAfter) {
var toAdd; // Yuck, program temporarily in invalid state.
if (ofCurrent && isXAxis) {
toAdd = touchTrack.currentPageX;
} else if (ofCurrent && !isXAxis) {
toAdd = touchTrack.currentPageY;
} else if (!ofCurrent && isXAxis) {
toAdd = touchTrack.previousPageX;
} else {
toAdd = touchTrack.previousPageY;
}
total += toAdd;
count++;
}
}
}
return count > 0 ? total / count : TouchHistoryMath.noCentroid;
},

currentCentroidXOfTouchesChangedAfter: function (touchHistory, touchesChangedAfter) {
return TouchHistoryMath.centroidDimension(touchHistory, touchesChangedAfter, true, // isXAxis
true // ofCurrent
);
},

currentCentroidYOfTouchesChangedAfter: function (touchHistory, touchesChangedAfter) {
return TouchHistoryMath.centroidDimension(touchHistory, touchesChangedAfter, false, // isXAxis
true // ofCurrent
);
},

previousCentroidXOfTouchesChangedAfter: function (touchHistory, touchesChangedAfter) {
return TouchHistoryMath.centroidDimension(touchHistory, touchesChangedAfter, true, // isXAxis
false // ofCurrent
);
},

previousCentroidYOfTouchesChangedAfter: function (touchHistory, touchesChangedAfter) {
return TouchHistoryMath.centroidDimension(touchHistory, touchesChangedAfter, false, // isXAxis
false // ofCurrent
);
},

currentCentroidX: function (touchHistory) {
return TouchHistoryMath.centroidDimension(touchHistory, 0, // touchesChangedAfter
true, // isXAxis
true // ofCurrent
);
},

currentCentroidY: function (touchHistory) {
return TouchHistoryMath.centroidDimension(touchHistory, 0, // touchesChangedAfter
false, // isXAxis
true // ofCurrent
);
},

noCentroid: -1
};

module.exports = TouchHistoryMath;
Loading

0 comments on commit c89f299

Please sign in to comment.