-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
164 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# react-gsap-hoc | ||
A higher order component for applying GSAP animations to React components - draft | ||
# react-gsap-enhancer | ||
A React comonent enhancer for applying GSAP animations to React components | ||
|
||
###[Work in progress (demo)](http://azazdeaz.github.io/react-gsap-enhancer/#/demo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export default { | ||
demo1: require('raw!./demo1.demoscript') | ||
'update-and-animate-transform': require('raw!./update-and-animate-transform.demoscript') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import attachRefs from './attachRefs' | ||
import Animation from './Animation' | ||
|
||
export default function () { | ||
return function (EnhancedCompoent) { | ||
return class GSAPEnhancer extends EnhancedCompoent { | ||
constructor(props) { | ||
super(props) | ||
this.__itemTree = new Map() | ||
this.__runningAnimations = new Set() | ||
} | ||
|
||
createAnimation = (create, options) => { | ||
var animation = new Animation( | ||
create, | ||
options, | ||
getDOMNodeByKeys.bind(this) | ||
) | ||
this.__runningAnimations.add(animation) | ||
animation.attach() | ||
return animation | ||
} | ||
|
||
componentDidMount() { | ||
saveRenderedStyles.call(this) | ||
|
||
if (super.componentDidMount) { | ||
super.componentDidMount() | ||
} | ||
} | ||
|
||
componentWillUpdate() { | ||
this.__runningAnimations.forEach(animation => animation.detach()) | ||
restoreRenderedStyles.call(this) | ||
|
||
if (super.componentWillUpdate) { | ||
super.componentWillUpdate() | ||
} | ||
} | ||
|
||
render () { | ||
return attachRefs(super.render(), this.__itemTree) | ||
} | ||
|
||
componentDidUpdate() { | ||
saveRenderedStyles.call(this) | ||
this.__runningAnimations.forEach(animation => animation.attach()) | ||
|
||
if (super.componentDidUpdate) { | ||
super.componentDidUpdate() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
function getDOMNodeByKeys(keyPath) { | ||
var item = {children: this.__itemTree} | ||
|
||
keyPath.forEach(key => { | ||
item = item.children.get(key) | ||
}) | ||
|
||
return item.node | ||
} | ||
|
||
function saveRenderedStyles() { | ||
walkItemTree.call(this, item => { | ||
item.savedStyle = item.node.getAttribute('style') | ||
item.node._gsTransform = null | ||
item.node._gsTweenID = null | ||
}) | ||
} | ||
|
||
function restoreRenderedStyles() { | ||
walkItemTree.call(this, item => { | ||
item.node.setAttribute('style', item.savedStyle) | ||
}) | ||
} | ||
|
||
function walkItemTree(callback) { | ||
function walk(map) { | ||
map.forEach(item => { | ||
if (item.node) { | ||
callback(item) | ||
if (item.children) { | ||
walk(item.children) | ||
} | ||
} | ||
}) | ||
} | ||
walk(this.__itemTree) | ||
} |
Oops, something went wrong.