Unverified Commit 037a4aef authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Un(less)conditionally schedule first callback frame when creating ticker (#16261)

* always schedule first frame when creating ticker, regardless of phase or frame
parent 06ed3622
...@@ -155,8 +155,9 @@ class Ticker { ...@@ -155,8 +155,9 @@ class Ticker {
}()); }());
assert(_startTime == null); assert(_startTime == null);
_future = new TickerFuture._(); _future = new TickerFuture._();
if (shouldScheduleTick) if (shouldScheduleTick) {
scheduleTick(); scheduleTick();
}
if (SchedulerBinding.instance.schedulerPhase.index > SchedulerPhase.idle.index && if (SchedulerBinding.instance.schedulerPhase.index > SchedulerPhase.idle.index &&
SchedulerBinding.instance.schedulerPhase.index < SchedulerPhase.postFrameCallbacks.index) SchedulerBinding.instance.schedulerPhase.index < SchedulerPhase.postFrameCallbacks.index)
_startTime = SchedulerBinding.instance.currentFrameTimeStamp; _startTime = SchedulerBinding.instance.currentFrameTimeStamp;
...@@ -216,7 +217,7 @@ class Ticker { ...@@ -216,7 +217,7 @@ class Ticker {
/// * The ticker is not active ([start] has not been called). /// * The ticker is not active ([start] has not been called).
/// * The ticker is not ticking, e.g. because it is [muted] (see [isTicking]). /// * The ticker is not ticking, e.g. because it is [muted] (see [isTicking]).
@protected @protected
bool get shouldScheduleTick => isTicking && !scheduled; bool get shouldScheduleTick => !muted && isActive && !scheduled;
void _tick(Duration timeStamp) { void _tick(Duration timeStamp) {
assert(isTicking); assert(isTicking);
...@@ -238,7 +239,6 @@ class Ticker { ...@@ -238,7 +239,6 @@ class Ticker {
/// This should only be called if [shouldScheduleTick] is true. /// This should only be called if [shouldScheduleTick] is true.
@protected @protected
void scheduleTick({ bool rescheduling: false }) { void scheduleTick({ bool rescheduling: false }) {
assert(isTicking);
assert(!scheduled); assert(!scheduled);
assert(shouldScheduleTick); assert(shouldScheduleTick);
_animationId = SchedulerBinding.instance.scheduleFrameCallback(_tick, rescheduling: rescheduling); _animationId = SchedulerBinding.instance.scheduleFrameCallback(_tick, rescheduling: rescheduling);
......
...@@ -103,4 +103,35 @@ void main() { ...@@ -103,4 +103,35 @@ void main() {
ticker.stop(); ticker.stop();
}); });
testWidgets('Ticker can be created before application unpauses', (WidgetTester tester) async {
final ByteData pausedMessage = const StringCodec().encodeMessage('AppLifecycleState.paused');
await BinaryMessages.handlePlatformMessage('flutter/lifecycle', pausedMessage, (_) {});
int tickCount = 0;
void handleTick(Duration duration) {
tickCount += 1;
}
final Ticker ticker = new Ticker(handleTick);
ticker.start();
expect(tickCount, equals(0));
expect(ticker.isTicking, isFalse);
await tester.pump(const Duration(milliseconds: 10));
expect(tickCount, equals(0));
expect(ticker.isTicking, isFalse);
final ByteData resumedMessage = const StringCodec().encodeMessage('AppLifecycleState.resumed');
await BinaryMessages.handlePlatformMessage('flutter/lifecycle', resumedMessage, (_) {});
await tester.pump(const Duration(milliseconds: 10));
expect(tickCount, equals(1));
expect(ticker.isTicking, isTrue);
ticker.stop();
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment