Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portal refactor & Anchor implementation #1

Conversation

creativecreatorormaybenot
Copy link

@creativecreatorormaybenot creativecreatorormaybenot commented Oct 24, 2021

Description

  • Implements passing the root bounds to portal anchors, i.e. passing the portalRect (renamed from overlayRect) to getFollowerOffset (renamed from getSourceOffset).
  • Implements handling of off-screen cut-off with a dedicated example.
  • Refactors the library to clean up all concepts to use only Portal, PortalTarget, PortalFollower, and Anchor.
  • Updates all documentation and examples.

Implementation details

The passing of root bounds is achieved using a custom FollowerLayer implementation that takes a callback for computing the linkedOffset. This allows making the linkedOffset depend on the offset of the leader layer (via CompositedTransformTarget). And this in turn allows to make the linkedOffset depend on the theaterRect, which requires only the relative top-left offset to the targetRect and the size of the theater, which we can obtain via the _RenderPortalTheater render box.

Tests

This PR only contains two unit test cases, but I did not feel the need to add more test cases since these are already the cases that cover the "most possible" edge cases, i.e. a portal that is not the root of the app and portal entry sizes that differ from the portal and child sizes.

Fragility

Doing this with TDD really helped me to come to a non-fragile implementation. Initially, I thought it would be enough to call localToGlobal with Offset.zero and the theater render box ancestor. However, this does not work because it does not respect the offset of the LayerLink. After that, I thought that I could access the link.leader in paint directly. Using a non-null assertion worked fine in my example app case, however, the unit tests revealed that this was actually not safe to do on the first paint call. This is because the layer link leader only attaches itself after the painting phase. And this is how I finally arrived at creating a custom FollowerLayer, which allows to access the leader layer offset in the composition phase.

This is why I believe that the new implementation is non-fragile and solid.

We can of course add more test cases - it cannot hurt :)

@creativecreatorormaybenot creativecreatorormaybenot changed the title Portal anchor refactor Implement root bounds for portal anchor refactor Oct 25, 2021
@creativecreatorormaybenot creativecreatorormaybenot changed the title Implement root bounds for portal anchor refactor Portal refactor & Anchor implementation Feb 7, 2022
@creativecreatorormaybenot
Copy link
Author

Current state: the new concepts are introduced and applied everywhere. I have touched all of the docs and examples to use the new concepts and it all seems coherent to me.

What is still open is handling the off-screen cut-off.

README.md Show resolved Hide resolved
…warning: 'top_level_function_literal_block' isn't a recognized error code. (unrecognized_error_code at [flutter_portal] analysis_options.yaml:16)`
…eld is no longer used and can be removed. (deprecated_field at [flutter_portal] pubspec.yaml:5)`; and doc says `Deprecated. Use a verified publisher instead. ... The pub.dev site no longer displays package authors`
@creativecreatorormaybenot
Copy link
Author

Closing this here as the changes have been merged upstream in fzyzcjy#44.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants