nextFrame property
A future that completes with an animation frame.
Unlike the browser's animation frame, if there is one already scheduled, it reuses that one, avoiding creating multiple frames across components.
Implementation
Future<num>? get nextFrame {
if (_nextFrameFuture == null) {
assert(_nextFrameCompleter == null);
final completer = Completer<num>.sync();
_nextFrameCompleter = completer;
_ngZone.runOutsideAngular(() {
// Delayed initialization of the cross-app event sending.
// TODO(google): figure out a better way to initialize this earlier
init();
_nextFrameId = _window.requestAnimationFrame((highResTimer) {
// Protect against window implementation that does not
// cancel the frame.
if (completer.isCompleted) return;
if (completer == _nextFrameCompleter) {
_nextFrameFuture = null;
_nextFrameCompleter = null;
}
completer.complete(highResTimer);
});
});
_nextFrameFuture =
ZonedFuture(completer.future, _ngZone.runOutsideAngular);
}
return _nextFrameFuture;
}