Skip to content
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

Animated transitions possible with back/forward buttons? #89

Open
dbmzzo opened this issue Oct 2, 2014 · 10 comments
Open

Animated transitions possible with back/forward buttons? #89

dbmzzo opened this issue Oct 2, 2014 · 10 comments

Comments

@dbmzzo
Copy link

dbmzzo commented Oct 2, 2014

Hello,

The router component has been a great help to me, but I've run into an issue that I'm not sure can be solved.

I have transitions between locations using the AnimatedLocations component, and they work great when clicking a link made with the Link component.

However, I'd also like the transitions to occur when the user uses the back/forward buttons.

Is this possible, perhaps (though I've tried and failed) by overriding the popstate or hashchange methods to manually load a location using react-router-component?

Thanks so much for your hard work on a great tool.

@STRML
Copy link
Owner

STRML commented Oct 3, 2014

Have you seen this project? https://github.com/andreypopp/react-router-page-transition

@dbmzzo
Copy link
Author

dbmzzo commented Oct 3, 2014

@STRML Yes, I saw that project and based my app's transitions on it. However, the native back and forward buttons don't trigger the animations for me. They also don't trigger the transitions in the http://andreypopp.github.io/react-router-page-transition/ example. Thanks for your prompt response!

@STRML
Copy link
Owner

STRML commented Oct 4, 2014

Yes - that code allows for a separate popState transition as animations on back/forward can get annoying. It is actually quite nice since you can set separate transitions on Links.

Using the code from the project, you can set the transitions on back/forward by specifying a popStateTransitionName:

<AnimatedLocations hash className="Main" transitionName="moveUp" popStateTransitionName="moveUp">
    <Location path="/" handler={MainPage} /> 
    <Location path="/about" handler={AboutPage} />
</AnimatedLocations>

See code

@jenil
Copy link

jenil commented Oct 5, 2014

Hey guys!
I too have been trying to get this working, but I have a doubt, the -enter transition works fine, but can someone explain to me how the -leave transition works? For me, the page that is coming in animates, but the page leaving just vanishes.

This is my CSS:

.moveUp-enter {
 -webkit-transform: translate3d(0,5%,0);
 transition: all .4s;
 opacity: 0.01;
}

.moveUp-enter.moveUp-enter-active {
  -webkit-transform: translate3d(0,0,0);
  opacity: 1;
}

.moveUp-leave {
  transition: all 4s;
  -webkit-transform: translate3d(0,0,0);
}

.moveUp-leave.moveUp-leave-active {
  -webkit-transform: translate3d(0,-105%,0);
  opacity: .01;
}

The 4s is for debugging purpose.

@STRML
Copy link
Owner

STRML commented Oct 5, 2014

Looks like you're missing the full set of rules from styles.css, especially the opacity bit.

There is more information in the React Docs for how this animation group works. Basically both elements are present in the DOM until React sees a transitionend event, then it is finally removed.

@jenil
Copy link

jenil commented Oct 5, 2014

I also tried with the exact same css on that file.

I read the docs throughly, but when happens is the -leave just happens in a flash.

@dbmzzo
Copy link
Author

dbmzzo commented Oct 5, 2014

@STRML thanks so much for the explanation of the popStateTransitionName prop. It worked like a charm.

@jenil27 Have you made sure that the -leave page isn't still in the DOM and just getting moved out of view? Your problem sounds very similar to an issue I had in which I thought the -leave page was disappearing (happened instantly even with long transition), but it in fact was not properly positioned (absolute) and was being pushed out of view by the -enter page element.

@jenil
Copy link

jenil commented Oct 6, 2014

@dbmzzo The page isn't in the DOM, it just goes out of the DOM within a few milliseconds when another page is entering. I have positioned the pages absolutely and copied the same animations from the styles.css. Still no luck :(

Here is a GIF showing the effect:
untitled

@lifeiscontent
Copy link

@jenil27 any updates on your luck? Did you get this working if so how?

@jenil
Copy link

jenil commented Feb 23, 2015

Nope, didn't figure it out. Gave up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants