简体   繁体   English

如何制作具有动画宽度的矩形React Native

[英]How to make rectangle with animated width React Native

I'm new to React Native. 我是React Native的新手。 I need to create a custom slider and I think it can make with animations. 我需要创建一个自定义滑块,并且我认为它可以通过动画制作。 So could you explain how to create this animation? 那么,您能解释一下如何创建此动画吗?

在此处输入图片说明

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM