我正在为网络使用动画,我想知道是否有可能在一个迷人的组件中使用动画的价值?
比如:
const AnimatedImageContainer = glamorous(Animated.div)(({ translateY }) => ({
transform: `translateY(${translateY._value}px)`,
}));
<AnimatedImageContainer
translateY={this.state.anim.interpolate({
inputRange: [-200, 100],
outputRange: [200, 0],
extrapolate: 'clamp',
})}
>
<AnimatedImage src={image} />
</AnimatedImageContainer>或者说:
<AnimatedImageContainer
css={{
transform: [
{
translateY: this.state.anim.interpolate({
inputRange: [-200, 100],
outputRange: [200, 0],
extrapolate: 'clamp',
}),
},
],
}}
>
<AnimatedImage src={image} />
</AnimatedImageContainer>发布于 2018-01-30 23:00:53
类似于ReactiveNative您可以在createAnimatedComponent()中封装组件。
如下所示(https://codesandbox.io/s/93202y1qyo):
import React from "react";
import { render } from "react-dom";
import glamorous from "glamorous";
import Animated from "animated";
const View = glamorous.div({
display: "flex"
});
const Button = Animated.createAnimatedComponent(
glamorous.button({
position: "absolute",
fontSize: 16,
border: "none",
display: "inline-block",
padding: "10px 20px",
textAlign: "center",
borderRadius: 4,
color: "#fff",
boxShadow: "0 4px 6px rgba(50,50,93,.11), 0 1px 3px rgba(0,0,0,.08)",
backgroundColor: "red"
})
);
class App extends React.Component {
state = {
animation: new Animated.Value(0)
};
componentDidMount() {
const { animation } = this.state;
Animated.timing(animation, { toValue: 1, duration: 3000 }).start();
}
render() {
const { animation } = this.state;
return (
<View>
<Button
style={{
opacity: animation
}}
>
Fade in...
</Button>
</View>
);
}
}
render(<App />, document.getElementById("root"));https://stackoverflow.com/questions/48449427
复制相似问题