Skip to content

requestAnimationFrame returns Unix timestamp instead of elapsed time #16151

@jamesseanwright

Description

@jamesseanwright

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

Metadata

Metadata

Labels

Good first issueInterested in collaborating? Take a stab at fixing one of these issues.Help Wanted :octocat:Issues ideal for external contributors.Issue: Author Provided ReproThis issue can be reproduced in Snack or an attached project.Resolution: LockedThis issue was locked by the bot.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions