Description
Environment
Provide version numbers for the following components (information can be retrieved by running tns info
in your project folder or by inspecting the package.json
of the project):
- CLI: 8.0.2
- Cross-platform modules: 8.0.7
- Android Runtime: 8.0.0
- iOS Runtime: 8.0.0
- XCode Version: 12.4
- Plugin(s): Many but not relevant here
Describe the bug
When using requestAnimationFrame
, the callback passed as a parameter receives a currentTimeInMilliseconds
parameter but the first callback call shows a weird (milli) timestamp.
I use this parameter to get an elapsed time in seconds for a specific task in my app. I then draw something with a canvas, based on the elapsed time.
To Reproduce
Use requestAnimationFrame
in any app with this code:
let animationStartTime = null
console.log('LOG 1 ~ Date.now', Date.now)
console.log('LOG 2 ~ global.__time', global.__time)
function updateCountdown(time) {
console.log('LOG 4 ~ updateCountdown ~ time', time)
if (animationStartTime === null) {
animationStartTime = time
}
const elapsedTime = time - animationStartTime
const secondsElapsed = elapsedTime / 1000
console.log('LOG 5 ~ updateCountdown ~ secondsElapsed', secondsElapsed)
// secondsElapsed is then processed in this function but it is not relevant for the bug
}
requestAnimationFrame(updateCountdown)
Current behavior
Here is the console log:
LOG 1 ~ Date.now 1623168227533
LOG 2 ~ global.__time 975129038.602083
LOG 3 ~ animation-frame/index.js:doCurrentFrame ~ lastFrameTime 975129234.583333
LOG 4 ~ updateCountdown ~ time 975129234.583333
LOG 5 ~ updateCountdown ~ secondsElapsed 0
LOG 4 ~ updateCountdown ~ time 193298084.68591672
LOG 5 ~ updateCountdown ~ secondsElapsed -781831.1498974164
LOG 4 ~ updateCountdown ~ time 193298134.6899584
LOG 5 ~ updateCountdown ~ secondsElapsed -781831.0998933747
...
The index.js log has been added here:
Expected behavior
The first call of my callback should have a time
argument similar to the following calls.
Suggestions for a resolution
I digged a little to see if I could find a solution for this problem but I don't know Swift nor Objective-C. Anyway I found the problematic function call:
This function (getTimeInFrameBase
) is basically another function which is also another function: global.__time
or Date.now
.
It seems that both of these functions won't return the expected timestamp (see my logs).
The following calls of my callback will use a timestamp from FPSCallback which uses a native object to get timestamp. Here is where I need assistance to find a solution!
I'm ready to make a PR if you have any hint for a fix. Thanks for your help!