2016-06-15 4 views
0

그래서 현재 React Native 앱을 작성 중이며 작은 문제가 발생했습니다. 버튼을 누르고 있으면 버튼 누름이 해제 될 때까지 반복적으로 기능을 실행하려고합니다.React Native onPressIn

onButtonPressIn() { 
    this.setState({pressStatus: true}) 
    recording = true 

    let myCallBack =() => { 
    setTimeout(this.executeFunction.bind(this), 50) 
    } 
    if (recording === true) { 
    myCallBack() 
    } 
} 

나는 if 문은 한 번만 코드를 실행 알지만, 내가 노력 다른 모든 방법이 전혀 작동하지 않았고, 아무 것도 허용하지 않았다 if 문 대신에 while 루프 : 여기 기능입니다 달리기. 또한 버튼을 놓을 때 녹음은 false로 설정된다는 점도 유의하십시오 (코드 시작 부분에 전역 변수로 선언 됨).

답변

0

전체 구성 요소를 보지 않고도 시작 :

let recording = false 
let ivRecording 
... 
onButtonPressIn() { 
    this.setState({pressStatus: true}) 
    recording = true 
    ivRecording = setInterval(() => this.executeFunction(), 50) 
} 
... 
onButtonPressRelease() { 
    this.setState({pressStatus: false}) 
    recording = false 
    clearInterval(ivRecording) 
} 
관련 문제