mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-29 07:34:13 +01:00
fix(motion): only a transition's first frames are waited for
A late frame near a transition's start counts as one frame, so the transition plays whole. The rule held for the first 150 ms shown, and that window only moves on by what is shown: on a device whose frames stay slow through a transition every frame counted as late, each added one frame to the window, and the transition played in slow motion. Only a run's first three frames can be late now. Frames that stay slow after them are the device's pace and keep their time.
This commit is contained in:
1 parent
2aa62d4cf7
commit
5b169edcd5
2 files changed
+19
-6
No files matched your search
@@ -111,7 +111,7 @@ double curveTimeFor(Curve curve, double value) {
|
||||
///
|
||||
/// A new page's first frames are its heaviest, and a ticker counts the time
|
||||
/// they took: the next frame would show the transition already well under
|
||||
/// way. Here a late frame near the start counts as one frame, so the
|
||||
/// way. Here a late frame among a run's first counts as one frame, so the
|
||||
/// transition starts late and plays whole.
|
||||
class SteadyStartTicks implements TickerProvider {
|
||||
const SteadyStartTicks(this.vsync);
|
||||
@@ -121,9 +121,9 @@ class SteadyStartTicks implements TickerProvider {
|
||||
/// A frame is late when it brings more than this many frames at once.
|
||||
static const double _late = 2.5;
|
||||
|
||||
/// Late frames are left out only this far into a run; a later one barely
|
||||
/// shows, and the run keeps its time.
|
||||
static const Duration _window = Duration(milliseconds: 150);
|
||||
/// Only this many frames of a run can be late. Frames that stay slow
|
||||
/// after them are the device's pace, and waiting for each would drag.
|
||||
static const int _first = 3;
|
||||
|
||||
static Duration get _frame {
|
||||
final views = WidgetsBinding.instance.platformDispatcher.views;
|
||||
@@ -135,17 +135,19 @@ class SteadyStartTicks implements TickerProvider {
|
||||
Ticker createTicker(TickerCallback onTick) {
|
||||
var last = Duration.zero;
|
||||
var leftOut = Duration.zero;
|
||||
var frames = 0;
|
||||
return vsync.createTicker((elapsed) {
|
||||
// A run that starts again counts from zero.
|
||||
if (elapsed < last) {
|
||||
last = Duration.zero;
|
||||
leftOut = Duration.zero;
|
||||
frames = 0;
|
||||
}
|
||||
final frame = _frame;
|
||||
final step = elapsed - last;
|
||||
final shown = last - leftOut;
|
||||
last = elapsed;
|
||||
if (step > frame * _late && shown < _window) leftOut += step - frame;
|
||||
if (step > Duration.zero) frames++;
|
||||
if (frames <= _first && step > frame * _late) leftOut += step - frame;
|
||||
onTick(elapsed - leftOut);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -193,6 +193,17 @@ void main() {
|
||||
controller.dispose();
|
||||
});
|
||||
|
||||
testWidgets('frames that stay slow are not waited for', (tester) async {
|
||||
final controller = run(tester)..forward();
|
||||
await tester.pump();
|
||||
// A device at 20 frames a second: only the first three count as late.
|
||||
for (var i = 0; i < 10; i++) {
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
}
|
||||
expect(controller.value, near(frame * 3 + 0.05 * 7));
|
||||
controller.dispose();
|
||||
});
|
||||
|
||||
testWidgets('each run counts from its own start', (tester) async {
|
||||
final controller = run(tester)..forward();
|
||||
await tester.pump();
|
||||
|
||||
Reference in new issue
Block a user