requestAnimationFrame returns Unix timestamp instead of elapsed time
See original GitHub issueIs 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.
Actual Behavior
The time parameter resolves to the current Unix timestamp (i.e. Date.now()
).
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:
- Created 6 years ago
- Reactions:1
- Comments:9 (2 by maintainers)
Top GitHub Comments
I’ve send fix to
fbjs
, but I wonder if it is better to fix it by addingperformance
polyfill inhttps://github.com/facebook/react-native/tree/master/Libraries/polyfills
@TakaGoto go ahead. Feel free to open a PR to fix this 😃