Created
June 8, 2017 17:18
-
-
Save mhaagens/a21cc02fdd068862fa15d1860799184c to your computer and use it in GitHub Desktop.
Pseduo-code Styled Components + Animated
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
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} /> | |
) | |
} | |
} |
Maybe I could pass all the values and then extend the styled object after (if I need to add more styles after)?
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
To make this work you'll unfortunately have to pass all the animated values in
style
:(