亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

React Native:如何通過警報擴展此計時器?

React Native:如何通過警報擴展此計時器?

神不在的星期二 2021-10-21 13:32:14
我是本機反應的新手。我有一個倒數計時器(當前設置為 5 秒),當時間到了時,我想要一個警報,讓用戶可以選擇重新啟動計時器。屏幕中會有其他元素,所以我不一定想要“刷新”(例如,如果用戶輸入了一些文本,我不希望它在計時器延長時消失)。時間到了時會彈出警報,但我不確定如何通過警報按鈕重置計時器。import React, { Component } from 'react';import {  StyleSheet,  TouchableOpacity,  Text,  View,  TextInput,  Alert,} from 'react-native'import CountDown from 'react-native-countdown-component';export default class Payment extends Component {  constructor(props) {    super(props);    this.state = {      timer: 5,    };  }    timesUp = () => {    Alert.alert(      "Time's Up!",      "How can we help you?",      [        {           text: "Extend Timer",          // I want to restart the timer here          onPress: this.setState(newTime => ({ timer: 5})) },        {          text: "Cancel",          onPress: () => console.log("Cancel Pressed") },      ],      { cancelable: false }    );  }  render() {    return (      <View>        <View style={{ marginTop: 20}}>          <CountDown            size={15}            until={this.state.timer}            onFinish={this.timesUp}            digitStyle={{backgroundColor: '#FFF', borderWidth: 2, borderColor: '#cccccc'}}            digitTxtStyle={{color: 'black'}}            separatorStyle={{color: 'black'}}            timeToShow={['M', 'S']}            timeLabels={{m: null, s: null}}            showSeparator          />      </View>    );  }}
查看完整描述

2 回答

?
梵蒂岡之花

TA貢獻1900條經驗 獲得超5個贊

請使用 setTimeout(function() {}, Time in Milli seconds)。它是一個原生的 javascript 函數,用于在一定時間后觸發一個函數。


查看完整回答
反對 回復 2021-10-21
  • 2 回答
  • 0 關注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號