From 5340d6cc2c78e7bce9ad929942d81fa523f694c9 Mon Sep 17 00:00:00 2001 From: Felipe Imperio Date: Thu, 26 Dec 2024 16:58:53 -0800 Subject: [PATCH] fixing time mismatch --- ios/FlankerNativeComponents/GameManager.swift | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/ios/FlankerNativeComponents/GameManager.swift b/ios/FlankerNativeComponents/GameManager.swift index ed88d0687..8e1880d99 100644 --- a/ios/FlankerNativeComponents/GameManager.swift +++ b/ios/FlankerNativeComponents/GameManager.swift @@ -110,7 +110,10 @@ class GameManager { func startLogicTimer() { invalidateTimers() - setDefaultText(isFirst: true) + let transitionDelay: TimeInterval = 0.3 + DispatchQueue.main.asyncAfter(deadline: .now() + transitionDelay) { + self.setDefaultText(isFirst: true) + } } func setEndTimeViewingImage(time: Double, isStart: Bool, type: TypeTimeStamps) { @@ -150,7 +153,7 @@ class GameManager { guard let gameParameters = gameParameters else { return } guard countTest >= 0 && countTest < gameParameters.trials.count else { return } - var resultTime = (respondTouchButton! - startTrialTimestamp) * 1000 + let resultTime = (respondTouchButton! - startTrialTimestamp) * 1000 arrayTimes.append(Int(resultTime)) delegate?.updateTime(time: String(format: "%.3f", resultTime)) @@ -247,8 +250,6 @@ class GameManager { } endFixationsTimestamp = bootTime + CACurrentMediaTime() - startTrialTimestamp = bootTime + CACurrentMediaTime() - hasRespondedInCurrentTrial = false text = gameParameters.trials[countTest].stimulus.en @@ -260,15 +261,20 @@ class GameManager { text: text, color: .black, font: Constants.bigFont, isStart: true, typeTime: .trial) } - delegate?.setEnableButton(isEnable: true) - - timeResponse = Timer( - timeInterval: gameParameters.trialDuration / 1000, - target: self, - selector: #selector(timeResponseFailed), - userInfo: nil, - repeats: false) - RunLoop.main.add(timeResponse!, forMode: .common) + let slightDelay = 0.016 + DispatchQueue.main.asyncAfter(deadline: .now() + slightDelay) { [weak self] in + guard let self = self else { return } + self.startTrialTimestamp = self.bootTime + CACurrentMediaTime() + self.delegate?.setEnableButton(isEnable: true) + + self.timeResponse = Timer( + timeInterval: gameParameters.trialDuration / 1000, + target: self, + selector: #selector(self.timeResponseFailed), + userInfo: nil, + repeats: false) + RunLoop.main.add(self.timeResponse!, forMode: .common) + } } @objc func timeResponseFailed() {