React native 如何使数字在按入时自动增长,按出时自动停止

React native 如何使数字在按入时自动增长,按出时自动停止,react-native,React Native,我尝试过使用setInterval,但没有成功 handlePressIn = () => { const {value} = this.state this.timerId = setInterval(() => this.setState({ value: value + 1}), 500) } handlePressOut = () => { clearInterval(this.timerId) } render() {

我尝试过使用
setInterval
,但没有成功

handlePressIn = () => {
    const {value} = this.state
    this.timerId = setInterval(() => this.setState({ value: value + 1}), 500) 
  }

  handlePressOut = () => {
    clearInterval(this.timerId)
  }

  render() {
    return (
      <View style={styles.container}>
        <TouchableWithoutFeedback
          onPressIn={this.handlePressIn}
          onPressOut={this.handlePressOut}
        >
          <View style={styles.button}>
            <Animated.View style={styles.bgFill} />
            <Text style={styles.text}>Press And Hold Me</Text>
          </View>
        </TouchableWithoutFeedback>
        <View>
          <Text>{this.state.value}</Text>
        </View>
      </View>
    )
  }
handlePressIn=()=>{
const{value}=this.state
this.timerId=setInterval(()=>this.setState({value:value+1}),500)
}
handlePressOut=()=>{
clearInterval(this.timerId)
}
render(){
返回(
按住我
{this.state.value}
)
}
谢谢你的帮助

我做到了:v

 handlePressIn = () => {
        const {value} = this.state
        this.setState({ increasing: true })
      }
    
      handlePressOut = () => {
        this.setState({ increasing: false })
      }
    
      check = () => {
        const { increasing, value } = this.state
        let i = value + 30
        if ( this.state.increasing ) setTimeout(() => this.setState({ value: i }),100)
      }
      
      increasing = () => {
        let i = this.state.value + 1
        this.setState({ value: i })
    
      }
    
      componentDidMount() {
        setInterval(() => {
          this.check()
        }, 500)
      }