-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Usage with react-router v4 #2
Comments
@mjsisley hey, thanks a lot! For sure it will work with React-router. I will make an example for it. Anything you look for specifically or just a plain transition between routes? |
Happy with that one or need more? |
Thanks for the example! I'm looking forward to implementing this as I prefer it to Animated's imperative approach. I realize Issues shouldn't be used for support questions, but it seems relevant to this particular issue. I'm trying to create an AnimatedSwitch component that I can re-use across multiple "Layouts" in my app. I'm not sure how to pass the
Usage would look something like:
|
Passing props down like that is hard with react-router. There's been this issue: remix-run/react-router#4105 (comment) but for your use-case none of the examples would would, not even cloning. I've struggled with similar problems in the past. The only way i see would be allowing AnimatedSwitch itself to call a render child into which it can pass "styles", but that wouldn't be any different from how it is right now. I'd probably leave Transition as it is, use it whenever it has to be used, but perhaps inject its props so that it becomes short to use, like so: const props = {
config: config.slow,
from: { opacity: 0, transform: 'scale3d(0.5,0.5,0.5)' },
enter: { opacity: 1, transform: 'scale3d(1,1,1)' },
leave: { opacity: 0, transform: 'scale3d(0.5,0.5,0.5)' },
}
<Transition {...props} keys={location.pathname}>
{styles => (
<Switch location={location}>
<Route path="/auth/login" render={props => Login({...props, style })} />
<Route path="/auth/signup" render={props => Signup({...props, style })} />
</Switch>
)}
</Transition> |
@drcmda Thanks a bunch for adding these examples! They cover the use cases I had in mind. |
Hi, will this also work for react-router v3? |
The spring is pretty forward in what it does, it simply moves props (or styles) from here to there. It should work with any react component. |
@dylinmaust @drcmda I implemented const AnimatedSwitch = withRouter(_AnimatedSwitch)
function _AnimatedSwitch({ location, children, ...transitionProps }) {
return (
<Transition native keys={location.pathname} {...transitionProps}>
{style => (
<Switch>
{React.Children.map(children, child => {
const { component: Component, ...childProps } = child.props
const AnimatedComponent = animated(Component)
return React.createElement(child.type, {
...childProps,
render: props => <AnimatedComponent {...{ ...props, style }} />
})
})}
</Switch>
)}
</Transition>
)
} Usage : <AnimatedSwitch
from={{ transform: 'translateY(100px)', opacity: 0 }}
enter={{ transform: 'translateY(0px)', opacity: 1 }}
leave={{ transform: 'translateY(100px)', opacity: 0 }}
>
<Route
exact
path="/page-1"
component={Page1}
/>
<Route exact path="/page-2" component={Page2} />
</AnimatedSwitch> It seems to work so far. Do you see anything wrong? |
Doing a search for import React from 'react';
import { Location, Router } from '@reach/router';
import { Transition } from 'react-spring/renderprops';
import styled from 'styled-components';
const StyledRouter = styled(Router)`
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
`;
function FadeInRouter({ children }) {
return (
<Location>
{({ location }) => (
<Transition
items={location}
keys={(location) => location.key}
from={{ opacity: 0 }}
enter={{ opacity: 1 }}
leave={{ opacity: 0 }}
>
{(location) => (props) => (
<StyledRouter location={location} style={props}>
{children}
</StyledRouter>
)}
</Transition>
)}
</Location>
);
}
export default FadeInRouter; and later you can use this router <FadeInRouter>
<ContactUs path="contact-us" />
<About path="about />
</FadeInRouter> |
Syncing upstream changes
*Total -- 31,135.93kb -> 20,686.13kb (33.56%) /demo/src/sandboxes/wordle/thumbnail.png -- 44.81kb -> 5.11kb (88.6%) /demo/src/sandboxes/smile-grid/thumbnail.png -- 114.00kb -> 19.07kb (83.28%) /demo/src/sandboxes/css-variables/thumbnail.png -- 71.26kb -> 14.28kb (79.97%) /demo/src/sandboxes/css-keyframes/thumbnail.png -- 45.24kb -> 12.32kb (72.77%) /demo/src/sandboxes/parallax/thumbnail.png -- 538.96kb -> 161.65kb (70.01%) /demo/src/sandboxes/list-reordering/thumbnail.png -- 112.72kb -> 33.93kb (69.89%) /demo/src/sandboxes/draggable-list/thumbnail.png -- 112.72kb -> 33.93kb (69.89%) /demo/src/sandboxes/animating-auto/thumbnail.png -- 33.91kb -> 10.33kb (69.54%) /demo/src/sandboxes/css-gradients/thumbnail.png -- 2,359.90kb -> 721.76kb (69.42%) /cypress/snapshots/All Integration Specs/horizontal pmndrs#2.snap.png -- 15.97kb -> 5.07kb (68.29%) /cypress/snapshots/All Integration Specs/horizontal pmndrs#3.snap.png -- 15.97kb -> 5.07kb (68.29%) /cypress/snapshots/All Integration Specs/vertical pmndrs#2.snap.png -- 15.97kb -> 5.07kb (68.29%) /demo/src/sandboxes/noise/thumbnail.png -- 1,751.61kb -> 556.77kb (68.21%) /demo/src/sandboxes/chain/thumbnail.png -- 33.61kb -> 10.70kb (68.18%) /demo/src/sandboxes/popup-modal/thumbnail.png -- 84.03kb -> 28.13kb (66.52%) /demo/src/sandboxes/trail/thumbnail.png -- 76.91kb -> 25.77kb (66.5%) /demo/src/sandboxes/svg-filter/thumbnail.png -- 42.20kb -> 14.20kb (66.34%) /assets/projects/next.png -- 23.57kb -> 8.46kb (64.1%) /cypress/snapshots/All Integration Specs/horizontal #1.snap.png -- 16.51kb -> 6.33kb (61.68%) /cypress/snapshots/All Integration Specs/vertical #1.snap.png -- 16.51kb -> 6.33kb (61.68%) /assets/projects/aragon.png -- 27.59kb -> 10.81kb (60.82%) /demo/src/sandboxes/parallax-sticky/thumbnail.png -- 107.66kb -> 43.11kb (59.95%) /demo/src/sandboxes/macos-dock/thumbnail.png -- 177.95kb -> 73.71kb (58.58%) /demo/src/sandboxes/simple-transition/thumbnail.png -- 166.75kb -> 79.62kb (52.25%) /demo/src/sandboxes/scrolling-wave/thumbnail.png -- 119.52kb -> 57.53kb (51.86%) /assets/projects/csb.png -- 30.14kb -> 14.70kb (51.22%) /demo/src/sandboxes/rocket-decay/thumbnail.png -- 34.78kb -> 17.70kb (49.11%) /cypress/snapshots/All Integration Specs/vertical pmndrs#3.snap.png -- 16.00kb -> 8.24kb (48.52%) /demo/src/sandboxes/springy-boxes/thumbnail.png -- 570.88kb -> 295.11kb (48.31%) /demo/src/sandboxes/notification-hub/thumbnail.png -- 80.27kb -> 42.60kb (46.92%) /demo/src/sandboxes/multistage-transition/thumbnail.png -- 62.53kb -> 33.83kb (45.9%) /demo/src/sandboxes/slide/thumbnail.png -- 83.89kb -> 46.47kb (44.6%) /demo/src/sandboxes/webgl-switch/thumbnail.png -- 345.12kb -> 192.32kb (44.27%) /demo/src/sandboxes/floating-button/thumbnail.png -- 3,141.47kb -> 1,764.19kb (43.84%) /demo/src/sandboxes/tree/thumbnail.png -- 47.16kb -> 26.87kb (43.03%) /demo/src/sandboxes/parallax-vert/thumbnail.png -- 42.17kb -> 24.33kb (42.32%) /demo/src/sandboxes/goo-blobs/thumbnail.png -- 110.36kb -> 70.29kb (36.31%) /demo/src/sandboxes/cards-stack/thumbnail.png -- 694.04kb -> 485.62kb (30.03%) /demo/src/sandboxes/card/thumbnail.png -- 266.36kb -> 192.83kb (27.61%) /demo/src/sandboxes/masonry/thumbnail.png -- 1,548.59kb -> 1,181.22kb (23.72%) /demo/src/sandboxes/image-fade/thumbnail.png -- 577.86kb -> 442.00kb (23.51%) /demo/src/sandboxes/flip-card/thumbnail.png -- 577.86kb -> 442.00kb (23.51%) /demo/src/sandboxes/viewpager/thumbnail.png -- 3,348.35kb -> 2,568.20kb (23.3%) /demo/src/sandboxes/exit-before-enter/thumbnail.png -- 3,193.60kb -> 2,454.14kb (23.15%) /docs/public/images/quotee/arzafran.png -- 57.51kb -> 46.26kb (19.56%) /docs/public/spring-icon.png -- 121.24kb -> 98.10kb (19.09%) /docs/public/share.jpg -- 303.25kb -> 246.24kb (18.8%) /demo/public/bright-rain.png -- 4,843.07kb -> 3,988.58kb (17.64%) /demo/src/sandboxes/floating-button/public/bright-rain.png -- 4,843.07kb -> 3,988.58kb (17.64%) /demo/public/cross.jpg -- 12.42kb -> 10.65kb (14.27%) /demo/src/sandboxes/webgl-switch/public/cross.jpg -- 12.42kb -> 10.65kb (14.27%) /.github/publish-ci/vite/public/vite.svg -- 1.46kb -> 1.42kb (2.81%) /demo/favicon.svg -- 0.39kb -> 0.38kb (2.48%) /packages/parallax/test/src/favicon.svg -- 1.49kb -> 1.46kb (2.17%) /docs/public/icon-link.svg -- 0.47kb -> 0.46kb (1.86%) /docs/public/favicon-32x32.png -- 2.46kb -> 2.44kb (0.71%) /docs/public/images/quotee/bruno_lemos.jpeg -- 21.33kb -> 21.19kb (0.65%) /docs/public/images/quotee/alexander_prinzhorn.jpeg -- 15.88kb -> 15.82kb (0.42%) /.github/publish-ci/next/public/logo.svg -- 1.10kb -> 1.09kb (0.09%) /.github/publish-ci/vite/src/logo.svg -- 1.10kb -> 1.09kb (0.09%) Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>
This library looks awesome!
Has this been tested with
react-router
v4 for route based transitions? It would be awesome if the docs included an example for this use case!The text was updated successfully, but these errors were encountered: