File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ import React , { Component } from 'react' ;
2+ import PropTypes from 'prop-types' ;
3+ import { ParallaxController } from 'react-scroll-parallax' ;
4+
5+ export default class ParallaxProvider extends Component {
6+ static propTypes = {
7+ children : PropTypes . node . isRequired ,
8+ } ;
9+
10+ static childContextTypes = {
11+ parallaxController : PropTypes . object ,
12+ } ;
13+
14+ getChildContext ( ) {
15+ // Passes down the reference to the controller
16+ const { parallaxController } = this ;
17+ return { parallaxController } ;
18+ }
19+
20+ componentWillMount ( ) {
21+ // Don't initialize on the server
22+ const isServer = typeof window === 'undefined' ;
23+
24+ if ( ! isServer ) {
25+ // Must not be the server so kick it off...
26+ this . parallaxController = ParallaxController . init ( ) ;
27+ }
28+ }
29+
30+ componentWillUnmount ( ) {
31+ if ( this . parallaxController ) {
32+ // Remove scroll and resize listener if the provider is unmounted
33+ this . parallaxController . destroy ( ) ;
34+ }
35+ }
36+
37+ render ( ) {
38+ const { children } = this . props ;
39+
40+ return children ;
41+ }
42+ }
Original file line number Diff line number Diff line change 11export Parallax from './components/Parallax' ;
2+ export ParallaxProvider from './components/ParallaxProvider' ;
23export ParallaxController from './libs/ParallaxController' ;
You can’t perform that action at this time.
0 commit comments