[英]How to make rectangle with animated width React Native
I have created a demo for that 我已经为此创建了一个演示
import * as React from 'react';
import { Text, View, Animated } from 'react-native';
import GestureRecognizer, {swipeDirections} from 'react-native-swipe-gestures';
export default class App extends React.Component {
state = {
widthAnim: new Animated.Value(0)
}
maxWidthAnimate = () => {
Animated.timing(this.state.widthAnim , {
toValue: 1,
duration: 2000
});
}
minWidthAnimate = () => {
Animated.timing(this.state.widthAnim , {
toValue: 0,
duration: 2000
});
}
render() {
const width = this.state.widthAnim.interpolate(
{
inputRange: [0, 0.5, 1],
outputRange: [50, 200, 50]
}
);
return (
<View>
<GestureRecognizer
onSwipeLeft={this.minWidthAnimate}
onSwipeRight={this.maxWidthAnimate}
>
<Animated.View style={{width: width, height: 100, backgroundColor: "blue", borderBottomRightRadius: 100, borderTopRightRadius: 100}}>
</Animated.View>
</GestureRecognizer>
</View>
);
}
}
Here is an expo link: https://snack.expo.io/BJvTVMOSN 这是一个博览会链接: https : //snack.expo.io/BJvTVMOSN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.