question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

requestAnimationFrame returns Unix timestamp instead of elapsed time

See original GitHub issue

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

OS: Linux 4.4
Node: 6.9.4
Yarn: Not Found
npm: 3.10.10
Watchman: Not Found

Packages: (wanted => installed) react-native: 0.48.4 => 0.48.4 react: 16.0.0-alpha.12 => 16.0.0-alpha.12

Target Platform: Android 7 (SDK version 25)

Steps to Reproduce

Create a simple React component that invokes requestAnimationFrame once, stores the time parameter in state, and renders the result:

import React from 'react';

import {
    AppRegistry,
    StyleSheet,
    View,
    Text
} from 'react-native';


const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
    },
})

class App extends React.Component {
    constructor() {
        super();

        this.state = {
            time: 0,
        };

        requestAnimationFrame(time => (
            this.setState({
                time,
            })
        ));
    }

    render() {
        const { showProgressBar } = this.state;

        return (
            <View style={styles.container}>
                <Text>{this.state.time}</Text>
            </View>
        );
    }
}

AppRegistry.registerComponent('App', () => App);

Expected Behavior

The time parameter should be the time elapsed since the “page” “loaded” (navigated to current view or activity?) as is the case in Chrome and Firefox (this value should be performance.now(), according to MDN.

Expected

Actual Behavior

The time parameter resolves to the current Unix timestamp (i.e. Date.now()).

Actual

Reproducible Demo

https://github.com/jamesseanwright/react-native-requestanimationframe-bug

I’d be happy to submit a PR to fix this, but I’m unsure of how this project versions breaking changes. I can work around this issue, but it would be great to achieve parity with the browser API so that I can avoid platform-specific hacks.

Let me know your thoughts.

Cheers, James

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Esemesekcommented, Oct 11, 2018

I’ve send fix to fbjs, but I wonder if it is better to fix it by adding performance polyfill in https://github.com/facebook/react-native/tree/master/Libraries/polyfills

0reactions
patrickkempffcommented, Jul 3, 2018

@TakaGoto go ahead. Feel free to open a PR to fix this 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

requestAnimationFrame timestamp limit - javascript
When building a game loop I have an assumption that with each call to requestAnimationFrame the timestamp value always goes up, based on...
Read more >
requestAnimationFrame for smart animating - Paul Irish
The requestAnimationFrame API​​ window. requestAnimationFrame(function(/* time */ time){ // time ~= +new Date // the unix time });
Read more >
html5.h — Emscripten 3.1.26-git (dev) documentation
Most functions in this API return a result of type EMSCRIPTEN_RESULT . ... the value EMSCRIPTEN_RESULT_NOT_SUPPORTED will be returned at the time the ......
Read more >
JS Tip of the Day: Time-based requestAnimationFrame
Callbacks used with requestAnimationFrame get a timestamp argument, a high-precision value in milliseconds representing the time since the ...
Read more >
DOMHighResTimeStamp - Web APIs - MDN Web Docs
The time, given in milliseconds, should be accurate to 5 µs ... You can get the current timestamp value—the time that has elapsed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found