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

Add browser API to enable page transitions plugins #1415

Closed

Conversation

tannerlinsley
Copy link

This is very provisional, but I’m excited where it’s going :)

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 8, 2017

Deploy preview ready!

Built with commit fdf1c51

https://deploy-preview-1415--gatsbygram.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 8, 2017

Deploy preview ready!

Built with commit fdf1c51

https://deploy-preview-1415--using-drupal.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 8, 2017

Deploy preview ready!

Built with commit fdf1c51

https://deploy-preview-1415--gatsbyjs.netlify.com

@tannerlinsley
Copy link
Author

Here is a demo

const React = require('react')
const { Transition } = require('react-move')

exports.componentRenderer = ({currentPage, previousPage}) => {
  console.log(currentPage, previousPage)
  return (
    <Transition
      data={[
        currentPage,
        previousPage
      ]}
      getKey={d => d.location.pathname}
      enter={d => ({
        transform: `translateX(100%)`,
        opacity: 1,
        zIndex: 1,
        boxShadow: '0 0 20px 0 rgba(0,0,0,0)',
      })}
      update={d => ({
        transform: `translateX(0%)`,
        opacity: 1,
        zIndex: 1,
        boxShadow: '0 0 100px 0 rgba(0,0,0,.5)'
      })}
      leave={d => ({
        transform: `translateX(-33%)`,
        opacity: .8,
        zIndex: 0
      })}
      ignore={['zIndex']}
      duration={700}
    >
      {nodes => (
        <div>
          {nodes.map(node => {
            const { component: Component, ...rest } = node.data
            return <div key={node.key} style={{
              position: 'absolute',
              left: 0,
              right: 0,
              top: 0,
              bottom: 0,
              background: 'white',
              ...node.state
            }}>
              <Component {...rest} />
            </div>
          })}
        </div>
      )}
    </Transition>
  )
}

@KyleAMathews
Copy link
Contributor

@0x80

Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! This is really exciting!

I tried your demo code on www and it mostly worked. I had to add a check if there was a previous page so as to not navigate on the initial render which I think plugins will always need to handle but otherwise it worked as expected! Exciting!

...this.state.pageResources.json,
const pluginResponses = apiRunner('componentRenderer', {
previousPage: {
...this.props,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be this.previousProps

return createElement(this.state.pageResources.component, {
...this.props,
...this.state.pageResources.json,
const pluginResponses = apiRunner('componentRenderer', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's name this API replacePageComponentRenderer per https://www.gatsbyjs.org/docs/api-specification/#operators

@tannerlinsley
Copy link
Author

I'll update these changes asap

@0x80
Copy link
Contributor

0x80 commented Jul 10, 2017

When I tried the example code, besides the mentioned previousPage workaround, the props.data of the rendered page seems to be undefined. So the result of the graphql query appears to be missing. I can't quite figure out where it went wrong.

@KyleAMathews
Copy link
Contributor

@tannerlinsley hey I'm going to take a crack at finishing this — a client needs this functionality added ASAP.

@KyleAMathews
Copy link
Contributor

Deploy preview failed.

Built with commit fdf1c51

https://app.netlify.com/sites/using-glamor/deploys/5963ed5ecf321c63a9d70aaf

@KyleAMathews
Copy link
Contributor

Ok so didn't end up finishing this as the client and I decided to go with a simple entry animation for components not an exit & entry animation.

I did push a commit fixing up some things. Want to push this across the finish line still @tannerlinsley ?

@KyleAMathews KyleAMathews changed the title Feature: gatsby-browser now supports componentRenderer plugin Add browser API to enable page transitions plugins Jul 16, 2017
@theiliad
Copy link
Contributor

Is there an update on this? Any sample code?

@hochem
Copy link

hochem commented Sep 1, 2017

@theiliad I added an example that doesn't rely on gatsby package modification in #1854

@LekoArts
Copy link
Contributor

Any news on this? 👍

@KyleAMathews
Copy link
Contributor

Closing this as @stevensurgnier added an API with alternative approach to solving this issue #2557

Thanks to everyone who's participated here! Check out the new API and let us know what you think!

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

Successfully merging this pull request may close these issues.

7 participants