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 {
}());
assert(_startTime == null);
_future = new TickerFuture._();
if (shouldScheduleTick)
if (shouldScheduleTick) {
scheduleTick();
}
if (SchedulerBinding.instance.schedulerPhase.index > SchedulerPhase.idle.index &&
SchedulerBinding.instance.schedulerPhase.index < SchedulerPhase.postFrameCallbacks.index)
_startTime = SchedulerBinding.instance.currentFrameTimeStamp;
......@@ -216,7 +217,7 @@ class Ticker {
/// * The ticker is not active ([start] has not been called).
/// * The ticker is not ticking, e.g. because it is [muted] (see [isTicking]).
@protected
bool get shouldScheduleTick => isTicking && !scheduled;
bool get shouldScheduleTick => !muted && isActive && !scheduled;
void _tick(Duration timeStamp) {
assert(isTicking);
......@@ -238,7 +239,6 @@ class Ticker {
/// This should only be called if [shouldScheduleTick] is true.
@protected
void scheduleTick({ bool rescheduling: false }) {
assert(isTicking);
assert(!scheduled);
assert(shouldScheduleTick);
_animationId = SchedulerBinding.instance.scheduleFrameCallback(_tick, rescheduling: rescheduling);
......
......@@ -103,4 +103,35 @@ void main() {
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