reland add lifecycle enum and remove workaround (#48460)

This commit is contained in:
chunhtai
2020-01-15 16:33:01 -08:00
committed by Flutter GitHub Bot
parent 1be332eb8b
commit d372814f78
46 changed files with 1657 additions and 14 deletions

View File

@@ -335,19 +335,13 @@ mixin SchedulerBinding on BindingBase, ServicesBinding {
_setFramesEnabledState(true);
break;
case AppLifecycleState.paused:
case AppLifecycleState.detached:
_setFramesEnabledState(false);
break;
default:
break;
}
}
Future<String> _handleLifecycleMessage(String message) async {
// TODO(chunhtai): remove the workaround once the issue is fixed
// https://github.com/flutter/flutter/issues/39832
if (message == 'AppLifecycleState.detached')
return null;
handleAppLifecycleStateChanged(_parseAppLifecycleMessage(message));
return null;
}
@@ -360,6 +354,8 @@ mixin SchedulerBinding on BindingBase, ServicesBinding {
return AppLifecycleState.resumed;
case 'AppLifecycleState.inactive':
return AppLifecycleState.inactive;
case 'AppLifecycleState.detached':
return AppLifecycleState.detached;
}
return null;
}
@@ -811,6 +807,11 @@ mixin SchedulerBinding on BindingBase, ServicesBinding {
/// Consider using [scheduleWarmUpFrame] instead if the goal is to update the
/// rendering as soon as possible (e.g. at application startup).
void scheduleForcedFrame() {
// TODO(chunhtai): Removes the if case once the issue is fixed
// https://github.com/flutter/flutter/issues/45131
if (!_framesEnabled)
return;
if (_hasScheduledFrame)
return;
assert(() {

View File

@@ -68,13 +68,9 @@ void main() {
await defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', message, (_) { });
expect(observer.lifecycleState, AppLifecycleState.inactive);
message = const StringCodec().encodeMessage('AppLifecycleState.detached');
await defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', message, (_) { });
// TODO(chunhtai): this should be detached once the issue is fixed
// https://github.com/flutter/flutter/issues/39832
// The binding drops detached message for now.
expect(observer.lifecycleState, AppLifecycleState.inactive);
expect(observer.lifecycleState, AppLifecycleState.detached);
});
testWidgets('didPushRoute callback', (WidgetTester tester) async {
@@ -109,6 +105,16 @@ void main() {
await defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', message, (_) { });
expect(tester.binding.hasScheduledFrame, isFalse);
message = const StringCodec().encodeMessage('AppLifecycleState.detached');
await defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', message, (_) { });
expect(tester.binding.hasScheduledFrame, isFalse);
message = const StringCodec().encodeMessage('AppLifecycleState.inactive');
await defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', message, (_) { });
expect(tester.binding.hasScheduledFrame, isTrue);
await tester.pump();
expect(tester.binding.hasScheduledFrame, isFalse);
message = const StringCodec().encodeMessage('AppLifecycleState.paused');
await defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', message, (_) { });
expect(tester.binding.hasScheduledFrame, isFalse);
@@ -116,9 +122,9 @@ void main() {
tester.binding.scheduleFrame();
expect(tester.binding.hasScheduledFrame, isFalse);
// TODO(chunhtai): fix this test after workaround is removed
// https://github.com/flutter/flutter/issues/45131
tester.binding.scheduleForcedFrame();
expect(tester.binding.hasScheduledFrame, isTrue);
await tester.pump();
expect(tester.binding.hasScheduledFrame, isFalse);
int frameCount = 0;