Skip to content

Extend drawing and rendering in lifecycles in iOS #71051

Closed

Description

@AdeolaKOD

Use case

To keep it short, applications built with flutter do not continue to render whilst out of view or in IOS's app switcher.
This is a bad behaviour from mobile apps imo . Might be a limitation from the framework, not sure.

It also causes an unpleasant UI/UX when scrolling through a ListView and the the application is removed from view. When
the application is brought back into view it jumps suddenly depending on the scroll extent.

Here is a gif description comparing Instagram and a mock flutter application.

ezgif-3-922462fb71be

Proposal

According to #5449 and #11421 , this was fixed. Although this was as far back 2017/2018 and Flutter has had many updates since then. Maybe a revision of what was changed could be implemented once more.

Environment

A minimal code snippet that would reproduce this issue.

import 'package:flutter/material.dart';

void main() {
  runApp(App());
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Issue(),
    );
  }
}

class Issue extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Issue'),
      ),
      body: ListView.builder(
        itemBuilder: (context, index) {
          return Padding(
            padding: const EdgeInsets.all(16.0),
            child: Text('Issue test'),
          );
        },
        itemCount: 350,
      ),
    );
  }
}
flutter doctor -v
[✓] Flutter (Channel stable, 1.22.0, on Mac OS X 10.15.7 19H15, locale en-GB)
    • Flutter version 1.22.0 at /Users/adeola/Downloads/flutter
    • Framework revision d408d302e2 (8 weeks ago), 2020-09-29 11:49:17 -0700
    • Engine revision 5babba6c4d
    • Dart version 2.10.0


[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at /Users/adeola/Library/Android/sdk • Platform android-30, build-tools 30.0.2 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.0.1, Build version 12A7300 • CocoaPods version 1.10.0.rc.1

[!] Android Studio (version 4.1) • Android Studio at /Applications/Android Studio.app/Contents ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.51.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.16.0

[✓] Connected device (1 available) • iPhone (mobile) • 7301a50cae9aaf2e903ef313e632bfed64bb3704 • ios • iOS 14.0

Activity

  1. pedromassangocode commented on Nov 23, 2020

    @pedromassangocode

    Hi @adeolaex
    What you want to achieve is called State Restoration, there is not issue here. Even on native Android/iOS app the system may stop your app's process to release resources for the app in foreground, See https://developer.apple.com/documentation/uikit/view_controllers/preserving_your_app_s_ui_across_launches.

    Flutter has recently introduce this however there is no support for iOS currently #62915. See for more info #62916.

    The announcement was made in https://medium.com/flutter/announcing-flutter-1-22-44f146009e5f.

  2. AdeolaKOD commented on Nov 23, 2020

    @AdeolaKOD
    Author

    HEY @pedromassangocode

    This issue has nothing to deal with State Restoration. If the text explaining the issue wasn't clear enough, at least look at the Gif provided.
    Both the native app ( Instagram ) and the Flutter app never make it to the background. They are both either in foreground or in the app switcher.

    What I am describing has to deal with the Flutter app not rendering whilst in the app switcher. On the native app, it continues to scroll whilst in the app switcher. Please look at #5449 !

  3. AdeolaKOD commented on Nov 23, 2020

    @AdeolaKOD
    Author

    In fact, to put it into perspective, we don't even have to go as far as the app switcher. Simply scrolling a list, then immediately dragging up the Control Centre will have the same results.

  4. pedromassangocode commented on Nov 23, 2020

    @pedromassangocode

    Thanks for making this clear, I was able to reproduce this on master channel.

    Seems to be a regression since this was confirmed to be fixed #5449 (comment).
    Cc @xster @Hixie

    flutter doctor -v
    [✓] Flutter (Channel master, 1.24.0-8.0.pre.344, on Mac OS X 10.15.7 19H2 darwin-x64, locale en)
        • Flutter version 1.24.0-8.0.pre.344 at /Users/pedromassango/dev/SDKs/flutter_master
        • Framework revision de56c6ad72 (18 hours ago), 2020-11-23 05:28:06 +0900
        • Engine revision 23a8e027db
        • Dart version 2.12.0 (build 2.12.0-62.0.dev)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
        • Android SDK at /Users/pedromassango/Library/Android/sdk
        • Platform android-30, build-tools 30.0.2
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 12.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 12.1, Build version 12A7403
        • CocoaPods version 1.9.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.1)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    
    [✓] IntelliJ IDEA Community Edition (version 2020.2.3)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 51.0.3
        • Dart plugin version 202.8070
    
    [✓] VS Code (version 1.51.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.16.0
    
    [✓] Connected device (4 available)
        • iPhone 11 Pro Max (mobile) • 7A82F29E-E49E-4B3C-8609-1570361DBC17 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-0 (simulator)
        • macOS (desktop)            • macos                                • darwin-x64     • Mac OS X 10.15.7 19H2 darwin-x64
        • Web Server (web)           • web-server                           • web-javascript • Flutter Tools
        • Chrome (web)               • chrome                               • web-javascript • Google Chrome 86.0.4240.198
    
    • No issues found!
    
    
  5. AdeolaKOD commented on Nov 23, 2020

    @AdeolaKOD
    Author

    @pedromassangocode Thank you very much !

    I'm glad you reopened the issue.

  6. AdeolaKOD commented on Nov 25, 2020

    @AdeolaKOD
    Author

    Hey @pedromassangocode , any update on this ?

  7. pedromassangocode commented on Nov 26, 2020

    @pedromassangocode

    Hi @adeolaex
    No, you will receive notifications once this get closed!

  8. 5 remaining items

  9. AdeolaKOD commented on Dec 13, 2020

    @AdeolaKOD
    Author
  10. pedromassangocode commented on Dec 15, 2020

    @pedromassangocode
  11. added
    P1High-priority issues at the top of the work list
    c: regressionIt was better in the past than it is now
    and removed
    P3Issues that are less important to the Flutter project
    on Dec 15, 2020
  12. zanderso commented on Mar 10, 2021

    @zanderso
    Member

    /cc @xster Do you know if this is an issue in the iOS embedder or the engine?

  13. xster commented on Mar 22, 2021

    @xster
    Contributor

    Since we had the rendering while in the app switcher behavior in #11421, we've made a number of tweaks in this area. Mainly to reduce the likelihood of issuing OpenGL commands while the app isn't in the foreground since it's prohibited in iOS and lead to crashes. But we may have not correctly preserved any special casing needed to support the app switcher.

    @gaaclarke may know more from looking at it more recently. It's also possible that OpenGL/Metal based apps conceptually need to be narrower in the supported lifecycle span than UiKit apps. Would be good to test via apps like games or Google Earth.

  14. gaaclarke commented on Mar 23, 2021

    @gaaclarke
    Member

    Yep, it is possible the disabling of the GPU is too conservative. Here is a PR that is purporting this very thing and addressing it: flutter-team-archive/engine#17396

    Edit: I tried out that PR and it didn't DID address the issue.

  15. Kavantix commented on Mar 23, 2021

    @Kavantix
    Contributor

    Yep, it is possible the disabling of the GPU is too conservative. Here is a PR that is purporting this very thing and addressing it: flutter/engine#17396

    Edit: I tried out that PR and it didn't address the issue.

    The PR is quite old by now, probably there are now other places in the engine that disable the rendering in the inactive state.
    When I made the PR these changes were enough to get it rendering in the app switcher

    Edit: turns out the PR worked after correctly merging, the current PR is now: flutter-team-archive/engine#25196

  16. gaaclarke commented on Mar 29, 2021

    @gaaclarke
    Member
  17. github-actions commented on Aug 3, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  18. locked as resolved and limited conversation to collaborators on Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues at the top of the work lista: fidelityMatching the OEM platforms bettera: qualityA truly polished experiencec: new featureNothing broken; request for a new capabilityc: regressionIt was better in the past than it is nowc: renderingUI glitches reported at the engine/skia or impeller rendering levelengineflutter/engine related. See also e: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions