前提・実現したいこと
現在、業務用の試作のコーヒーマシンの操作をReactNativeで実装しているのですが、
タイマーの設定について質問です。*ソースコードは省略しております.
<やりたい事>
ポイント(price 1 or2 ごとにカウントダウンの時間を変更したい>
Stateで現在、price 1、timeout150と設定されていますが、
下記、handleSelectCoffee = (lastScreen) => 以下で、price1とprice2の場合で
resettime(150)をprice2なら150秒と、price1なら60秒と設定したいですが、
追記のソースのアドバイスを頂きたいです。
発生している問題・エラーメッセージ
if文やcase文を追加するとデバックがうまくかないorソースが認識されない
該当のソースコード
index.js
1import PropTypes from 'prop-types'; 2import React, { Component } from 'react'; 3import { DeviceEventEmitter } from 'react-native' 4import SelectMenu from './SelectMenu'; 5state = { 6currentScreen: null, 7 8buttonTrouble: false, 9 10price: 1, 11 12checkingStatus: true, 13 14timeoutTimeNow: 150, 15} 16handleSelectCoffee = (lastScreen) => { 17const { onCompleted, resetTime, startNotify, countDown, pay, bleWrite, receiveData, lastReceiveData } = this.props; 18 19let currentScreen = lastScreen 20 21switch (currentScreen) { 22 23 case null: 24 25 console.log('receiveData', receiveData); 26 27 if (receiveData == machine.commands.find(v => v.name === 'inhibit-high').command) { 28 29 pay() 30 31 if (this.state.price > 1) setTimeout(() => pay(), 100); 32 33 startNotify() 34 35 setTimeout(() => { 36 37 bleWrite(this.writeData) 38 39 }, 200); 40 41 onCompleted() 42 43 resetTime(150) 44 45 currentScreen = SCREEN_WAITING 46 47 this.setState({ currentScreen }) 48 49 this.setButtonTrouble(DIALOG_ERROR)
試したこと
<試したこと>
case文をまるごと書き処理を追加→デバックがうまくいかない
if、if else 文で処理を追加→2つの処理(150秒、60秒のうち片方しか認識されず、
price1のときも2の時も60秒でカウントされる。
補足情報(FW/ツールのバージョンなど)
Android studio
Lenobo TAB
Mac OSX
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。