-
Notifications
You must be signed in to change notification settings - Fork 307
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
Add example for triggering actions on swipe #8
Comments
Hey @sampl, you can use the provided callbacks for that. I modified the example: Don't forget to return the props in every callback. They are used in the event hooks of Cheers. |
@monstersintokyo just what I needed--thank you so much! |
@sampl you're welcome :-) |
@drcmda how would this example work now that we only have the Including Doing it like this isn't gonna work well updateState = () => this.setState({ ... });
<Gesture>
{({ ... }) => {
// Calling this.setState() from render() is bad...
if (some gesture condition is met) this.updateState();
return (
<Spring>
{...}
</Spring>
);
}
}
</Gesture> |
@tim-soft did something change? how did you do it before? i think otherwise in the class base api that needs to be componentDidUpdate that does the updateState(). |
In an older version, we could call setState() based on some gesture event like in https://codesandbox.io/embed/w0x1030lwk without interfering in the animation updateState = (props) => {
if (some gesture condition is met) this.setState({ ... });
return props;
}
<Gesture onMove={this.updateState}>
{({ ... }) => (
<Spring>
{...}
</Spring>
);
}
</Gesture> Using the |
the last bit i don't understand yet. if you're in onAction and you cause a setState, why wouldn't the spring animate? It's been a while but i think i've had trouble figuring out what to do with the renderprops api as it didn't lend itself to this sort of stuff, but using local state as a model for the animation should always work. |
Here's a codepen where I try to replicate https://codesandbox.io/embed/3vv25z07j6 The top slider uses onAction to decide when to call setState() You'll notice the top slider set the state, but doesn't move when you drag it around |
I see. Could i interest you in adding these events back via PR? now: https://github.com/react-spring/react-with-gesture/blob/master/index.js |
definitely 👍 |
How to solve ? |
@arpitprod This is an old issue. Swipe is documented in the documentation. |
I'd love to know the best way to trigger an event based on a gesture.
For ex: let's say someone using the demo drags the box to the right and releases it to "accept" that item. Where and how would you actually call an
acceptItem
function?Happy to refile elsewhere if this isn't the right place. Thanks!
The text was updated successfully, but these errors were encountered: