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

feat: add optional useRepaintBoundary to Animate #47

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/src/animate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class Animate extends StatefulWidget with AnimateManager<Animate> {
this.controller,
this.adapter,
this.target,
this.useRepaintBoundary = false,
}) : super(key: key) {
_entries = [];
if (effects != null) addEffects(effects);
Expand Down Expand Up @@ -176,6 +177,9 @@ class Animate extends StatefulWidget with AnimateManager<Animate> {
/// ```
final double? target;

// TODO: add documentation
Copy link
Owner

Choose a reason for hiding this comment

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

Appreciate if you take a first stab at this.

Copy link
Author

Choose a reason for hiding this comment

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

Will gladly do this tomorrow :)

final bool useRepaintBoundary;

late final List<EffectEntry> _entries;
Duration _duration = Duration.zero;
EffectEntry? _lastEntry;
Expand Down Expand Up @@ -320,7 +324,9 @@ class _AnimateState extends State<Animate> with SingleTickerProviderStateMixin {
for (EffectEntry entry in widget._entries) {
child = entry.effect.build(context, child, _controller, entry);
}
return reparent?.call(parent, child) ?? child;
Widget returnWidget = reparent?.call(parent, child) ?? child;
if (widget.useRepaintBoundary) return RepaintBoundary(child: returnWidget);
Copy link
Owner

Choose a reason for hiding this comment

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

instead of an additional return, I'd just add to returnWidget. I wonder if there's a better name than returnWidget also.

return returnWidget;
}
}

Expand All @@ -336,6 +342,7 @@ extension AnimateWidgetExtensions on Widget {
AnimationController? controller,
Adapter? adapter,
double? target,
bool? useRepaintBoundary,
}) =>
Animate(
key: key,
Expand All @@ -346,6 +353,7 @@ extension AnimateWidgetExtensions on Widget {
controller: controller,
adapter: adapter,
target: target,
useRepaintBoundary: useRepaintBoundary ?? false,
Copy link
Owner

Choose a reason for hiding this comment

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

I try really hard to not duplicate defaults in extension methods, since it creates fragility when changing them (easy to forget to update in all locations). Take a look at any of the extension methods on various effects for examples.

Copy link
Author

Choose a reason for hiding this comment

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

Really good point, pulled it out of the constructors!

child: this,
);
}
Expand Down