Skip to content

Android timers (setTimoout and animation delay) are missbehaving ! #14639

@fabien-h

Description

@fabien-h

Description

When I :

setTimeout(
	e => this.props.selfClose(),
	5000
);

It happens with immediately. Same with :

Animated.timing(
	this.state.opacity, {
		toValue: 1,
		duration: 250,
		easing: Easing.out( Easing.back( 2 ) ),
		useNativeDriver: true,
		delay: 5000,
	}
).start();

There is an almost zero delay before the animation is played.

iOs works fine.

Reproduction Steps & Sample Code

Steps :

  • react-native init testreactnative
  • plug android device
  • add code in /index.android.js
  • run in device with the react native debugger
  • see the log

Code to add :

componentDidMount() {
	let initTime = new Date().getTime();
	console.log( new Date().getTime() - initTime, 'foo' );
	setTimeout(
		e => {
			console.log( new Date().getTime() - initTime, 'bar' );
		},
		5000
	);
	console.log( new Date().getTime() - initTime, 'baz' );
};

Logs :

0 "foo"
0 "baz"
64 "bar"

So technically, there is a delay. But 64ms is not what I asked.

Now the weird part. If I set the delay to 10.000 instead of 5.000, it logs 4672 "bar". Not even linear. And if I go up to 100.000, I get this warning :

YellowBox.js:76 Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info.

Additional Information

  • React Native version: 0.45.1
  • Platform: Android ; I run on device (shitty tablet)
  • Development Operating System: macOS
  • Build tools: [FILL THIS OUT: Xcode or Android Studio version, iOS or Android SDK version, if applicable]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions