-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pull request #103
Pull request #103
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! What an interesting requirement.
Just a few thoughts.
src/Swipeable.js
Outdated
@@ -25,8 +25,15 @@ function getPosition(e) { | |||
: { x: e.clientX, y: e.clientY }; | |||
} | |||
|
|||
function rotateByAngle({ x, y }, angle) { | |||
const angleInRadians = (Math.PI / 180) * angle; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thoughts on quick out?
function rotateByAngle(positions, angle) {
if (angle === 0) return positions;
and don't destructure, since that will be the majority, currently, of use cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will add that
@@ -89,6 +89,8 @@ as well as the x distance, + or -, from where the swipe started to where it ende | |||
|
|||
**`innerRef`** will allow access to the Swipeable's inner dom node element react ref. See [#81](https://github.com/dogfessional/react-swipeable/issues/81) for more details. Example usage `<Swipeable innerRef={(el) => this.swipeableEl = el} >`. Then you'll have access to the dom element that Swipeable uses internally. | |||
|
|||
**`rotationAngle`** will allow to set a rotation angle, e.g. for a four-player game on a tablet, where each player has a 90° turned view. The default value is `0`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we "lock" this to a range of 0 - 360
? via a new proptype?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We thought about the same, but in the end it does not matter for the calculation - so why lock the range.
@@ -379,4 +380,125 @@ describe('Swipeable', () => { | |||
expect(swipeableDiv.prop('onTouchMove')).toBe(instance.eventMove); | |||
}); | |||
}); | |||
|
|||
describe('Handle Rotation by 90 degree: ', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding tests!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'course - won't work without. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, a question: the tests are mainly data-driven. Is it okay to refactor them into data-driven tests with less duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm all for cleaning up the tests and if you'd like to do that, could it be another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, external PR would be best
@hartzis Could you re-review? Added more tests for negative degrees and over-360-degrees for documentation and the early-return as requested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! i hope to get this merged and versioned within the week!
Adds the ability to change the swipe rotation for rotated components
In one of our projects, we used the react-image-gallery, but needed to rotate it for different views. Since the swipe component react-swipeable was unable to rotate the swipes accordingly, we added the appropriate parts in this PR. Changes are non-breaking.