question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What is the best way to have different transitions based on the app state?

See original GitHub issue

Say that I have two pages PageA and PageB.

I want to transition between PageA -> PageB using TransitionX.

But when I’m navigating between PageB -> PageA I want to use TransitionY.

Is this easily achieved with this package or is it best to use a more custom solution? (React Spring or similar)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
kapokocommented, Jul 29, 2019

I just found a solution for this. In my case I had pages that were dark themed and some that were light themed so I wanted use different transitions based on what page the user navigated to. I use pageProps for this. Here’s the simplified code:

// pages/index.js

const Index = props => (
    <h1>Index page</h1>
)

Index.getInitialProps = async function () {
    return { theme: 'light' }
}

export default Index
// pages/about.js

const About = props => (
    <h1>About page</h1>
)

About.getInitialProps = async function () {
    return { theme: 'dark' }
}

export default About

Then in _app.js we can fetch the theme prop and pass it to the PageTransition’s component classNames prop.

// pages/_app.js

class MyApp extends App {
    render() {
        const { Component, pageProps } = this.props;

        return (
            <Container>
                <PageTransition timeout={1000} classNames={`transition-${pageProps.theme}`}>
                   <Component {...pageProps} />
                </PageTransition>
            </Container>
        )
    }
}
export default MyApp

Now I can use the classes transition-light-enter transition-light-enter-active transition-light-enter-done transition-dark-enter transition-dark-enter-active transition-dark-enter-done etc. etc. to style the different transitions.

1reaction
kapokocommented, Jul 29, 2019

Sure thing. Called the example multiple-transitions to make it as general as possible.

https://github.com/illinois/next-page-transitions/pull/39

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling Common State Transitions - Apple Developer
Some of the most common transitions include launching the app, going to the background, and resuming. The app launches when it isn't running,...
Read more >
Understand the states and transitions of an iOS App
It takes very little effort to monitor the transition messages and handle the various app states. A little due diligence goes a long...
Read more >
Animation transitions - Unity - Manual
Drag the Duration “in” marker to change the duration of the transition and the Exit Time. Drag the target state to adjust the...
Read more >
Activity state changes - Android Developers
Different events, some user-triggered and some system-triggered, can cause an Activity to transition from one state to another.
Read more >
State Machine - Rive Guide
Connect your new states with Transitions. When you hover near a state, you'll see a dot appear. Click and drag on that dot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found