Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing time mismatch #922

Open
wants to merge 1 commit into
base: release/2.7.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions ios/FlankerNativeComponents/GameManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -247,8 +250,6 @@ class GameManager {
}

endFixationsTimestamp = bootTime + CACurrentMediaTime()
startTrialTimestamp = bootTime + CACurrentMediaTime()

hasRespondedInCurrentTrial = false

text = gameParameters.trials[countTest].stimulus.en
Expand All @@ -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() {
Expand Down
Loading