Skip to content

Removed ClipRect from AnimatedCrossFade#152027

Closed
kaaninel wants to merge 3 commits into
flutter:mainfrom
kaaninel:patch-1
Closed

Removed ClipRect from AnimatedCrossFade#152027
kaaninel wants to merge 3 commits into
flutter:mainfrom
kaaninel:patch-1

Conversation

@kaaninel

Copy link
Copy Markdown

This PR is a possible solution for #152025. Current implementation of AnimatedCrossFade includes ClipRect without any option to configure it. Removing this widget from build function seems to not cause any issues with my test cases. In case clipping behavior is needed developer can clip the child widget before passing it to AnimatedCrossFade.

Screenshot 2024-07-19 at 15 45 59

As you can see shadow is clipped and causing a weird look.

Screenshot 2024-07-19 at 15 46 17

Removing ClipRect results with expected/desired behavior.

#152025

@github-actions github-actions Bot added the framework flutter/packages/flutter repository. See also f: labels. label Jul 19, 2024

@chunhtai chunhtai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pr also needs a test

curve: widget.sizeCurve,
child: widget.layoutBuilder(topChild, topKey, bottomChild, bottomKey),
),
return AnimatedSize(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems dangerous. If the content is indeed bigger, this may cause a regression

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this ClipRect here is undesired behavior but i would understand concerns about changing default behaviour. Making this optional while leaving default behavior as is may be a better idea. Let me prepare a commit for it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to expose clipBehavior as a property so folks can disable/enable/configure as they like.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClipRect is 100% the wrong behavior IMO since the defaultLayoutBuilder purposely sets clipBehavior: Clip.none one would assume that overriding the builder would solve the clipping issue (in the case where people do not want to clip) but nope!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems dangerous. If the content is indeed bigger, this may cause a regression

The content should be contained inside of the stack which itself has a clipping behavior

@goderbauer

Copy link
Copy Markdown
Member

(triage) @kaaninel Do you still have plans to come back to this one and address the feedback given above?

@kaaninel

kaaninel commented Sep 3, 2024

Copy link
Copy Markdown
Author

(triage) @kaaninel Do you still have plans to come back to this one and address the feedback given above?

I just returned from my holiday. I can continue on this topic now.

@Piinks

Piinks commented Sep 24, 2024

Copy link
Copy Markdown
Contributor

Hey @kaaninel do you have plans to address the feedback above? Thanks!

@Piinks

Piinks commented Oct 22, 2024

Copy link
Copy Markdown
Contributor

Thank you for your contribution. I'm going to close this PR for now since there are outstanding comments, just to get this off our PR review queue. Please don't hesitate to re-open or submit a new PR if you have the time to address the review comments. Thanks!

@Piinks Piinks closed this Oct 22, 2024
pull Bot pushed a commit to TheRakeshPurohit/flutter that referenced this pull request Apr 23, 2026
`AnimatedCrossFade` wraps its content in a hardcoded `ClipRect` with no
way to change or disable the clipping behavior. This causes widgets with
shadows, overflowing content (e.g. `CircularProgressIndicator` stroke),
or other visual effects to be unintentionally clipped.

This PR adds a `clipBehavior` parameter to `AnimatedCrossFade` (defaults
to `Clip.hardEdge` for backwards compatibility) and forwards it to the
internal `ClipRect` in `_AnimatedCrossFadeState.build()`. This follows
the same pattern used by `Stack`, `AnimatedSize`, `ListView`, and other
Flutter widgets that expose `clipBehavior`.

PR flutter#152027 attempted to fix this by removing `ClipRect` entirely, but
was closed after reviewers recommended exposing `clipBehavior` as a
configurable parameter instead.

Fixes flutter#152025
Fixes flutter#25950

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: Victor Sanni <victorsanniay@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants