Estoy haciendo una aplicación con reaccionar nativo. Si no hay respuesta táctil en una pantalla actual, quiero una acción que avance automáticamente a la siguiente pantalla después de 5 segundos.
Si se presiona un botón o se ingresa texto de entrada, estoy pensando en borrar setTimeout y contar 5 segundos nuevamente. Así que envolví las funciones para poner onPress y onChange que tengo en la pantalla. Sin embargo, funciona como si se hubiera presionado el botón. ¿Cómo debo envolverlo?... Te agradecería que me lo hicieras saber.
//ReceiptScreen ... componentWillUnmount() { this._isMounted = false; clearTimeout(this.nextScreenTimer); } handleSendPress = () => { if (isValidEmail(this.state.email)) { this.props.sendEmailReceipt(this.state.email, this.props.order); } else { Alert.alert( null, [ { text: 'close', onPress: () => null, }, ], {cancelable: true}, ); } }; handleScreenTimeout = func => { console.log('what', func); clearTimeout(this.nextScreenTimer); this.nextScreenTimer = setTimeout(() => { this.handlePressClose(); }, 5000); func(); }; componentDidMount() { this.nextScreenTimer = setTimeout(() => { this.handlePressClose(); }, 5000); } .... render() { .... <InputButton placeholder={'example@gmail.com'} value={this.state.email} onChangeText={text => this.setState({email: text})} loading={this.props.isEmailReceiptFetching} onPress={this.handleScreenTimeout(this.handleSendPress)} /> }
Debe cambiar el siguiente controlador onPress
onPress={this.handleScreenTimeout(this.handleSendPress)}
ser una función que llame a su función dentro de ella como se muestra a continuación
onPress={() => this.handleScreenTimeout(this.handleSendPress)}