• Michael Goderbauer's avatar
    Reapply "Dynamic view sizing" (#140165) (#140918) · 4534a24c
    Michael Goderbauer authored
    This reverts commit
    https://github.com/flutter/flutter/commit/d24c01bd0c41331bd17165e0173b24c5d05d7c0a.
    
    The original change was reverted because it caused some apps to get
    stuck on the splash screen on some phones.
    
    An investigation determined that this was due to a rounding error.
    Example: The device reports a physical size of 1008.0 x 2198.0 with a
    dpr of 1.912500023841858. Flutter would translate that to a logical size
    of 527.0588169589221 x 1149.2810314243163 and use that as the input for
    its layout algorithm. Since the constraints here are tight, the layout
    algorithm would determine that the resulting logical size of the root
    render object must be 527.0588169589221 x 1149.2810314243163.
    Translating this back to physical pixels by applying the dpr resulted in
    a physical size of 1007.9999999999999 x 2198.0 for the frame. Android
    now rejected that frame because it didn't match the expected size of
    1008.0 x 2198.0 and since no frame had been rendered would never take
    down the splash screen.
    
    Prior to dynamically sized views, this wasn't an issue because we would
    hard-code the frame size to whatever the requested size was.
    
    Changes in this PR over the original PR:
    
    * The issue has been fixed now by constraining the calculated physical
    size to the input physical constraints which makes sure that we always
    end up with a size that is acceptable to the operating system.
    * The `ViewConfiguration` was refactored to use the slightly more
    convenient `BoxConstraints` over the `ViewConstraints` to represent
    constraints. Both essentially represent the same thing, but
    `BoxConstraints` are more powerful and we avoid a couple of translations
    between the two by translating the` ViewConstraints` from the
    `FlutterView` to `BoxConstraints` directly when the `ViewConfiguration`
    is created.
    
    All changes over the original PR are contained in the second commit of
    this PR.
    
    Fixes b/316813075
    Part of https://github.com/flutter/flutter/issues/134501.
    4534a24c
box.dart 121 KB