Skip to content

Instantly share code, notes, and snippets.

@mhaagens
Created June 8, 2017 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhaagens/a21cc02fdd068862fa15d1860799184c to your computer and use it in GitHub Desktop.
Save mhaagens/a21cc02fdd068862fa15d1860799184c to your computer and use it in GitHub Desktop.
Pseduo-code Styled Components + Animated
const CustomDiv = styled(Animated.view)`
transform: ${props => `rotate(props.rotateDeg)`}
`;
class App extends Component {
constructor(props) {
super(props)
this.state = {
rotate: new Animated.Value(0)
}
}
componentDidMount() {
setInterval(() => {
Animated.spring(this.state.rotate, {toVal: this.state.rotate._val === 0 ? 1 : 0}).start();
}, 1000);
}
render() {
const rotateDeg = this.state.rotate.interpolate({
inputRange: [0,1],
outputRange: ["0deg", "360deg"]
});
return (
<CustomDiv rotateDeg={rotateDeg} />
)
}
}
@kitten
Copy link

kitten commented Jun 8, 2017

To make this work you'll unfortunately have to pass all the animated values in style :(

@mhaagens
Copy link
Author

mhaagens commented Jun 8, 2017

Maybe I could pass all the values and then extend the styled object after (if I need to add more styles after)?

@mhaagens
Copy link
Author

mhaagens commented Jun 8, 2017

Ah, now I understand. Just pass the style object the regular way, but then it pretty much bypasses styled-components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment