Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.4
* Fix coordinate system for non-fullscreen overlays;
* Ensure _SidekickFlight objects get removed from the overlay if controller is disposed mid-flight.

## 0.1.3
### Modified
* Make source sidekick disappear at end.
Expand Down
27 changes: 18 additions & 9 deletions lib/src/widgets/sidekick.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ enum SidekickFlightDirection {
toSource,
}

// The bounding box for context in global coordinates.
Rect _globalBoundingBoxFor(BuildContext context) {
// The bounding box for context in ancestorContext coordinate system, or in the global
// coordinate system when null.
Rect _boundingBoxFor(BuildContext context, [BuildContext ancestorContext]) {
final RenderBox box = context.findRenderObject();
assert(box != null && box.hasSize);
return MatrixUtils.transformRect(
box.getTransformTo(null), Offset.zero & box.size);
box.getTransformTo(ancestorContext?.findRenderObject()),
Offset.zero & box.size,
);
}

/// A widget that marks its child as being a candidate for sidekick animations.
Expand Down Expand Up @@ -316,8 +319,9 @@ class _SidekickFlight {
} else if (toSidekickBox.hasSize) {
// The toSidekick has been laid out. If it's no longer where the sidekick animation is
// supposed to end up then recreate the sidekickRect tween.
final RenderBox overlayBox = manifest.overlay.context?.findRenderObject();
final Offset toSidekickOrigin =
toSidekickBox.localToGlobal(Offset.zero);
toSidekickBox.localToGlobal(Offset.zero, ancestor: overlayBox);
if (toSidekickOrigin != sidekickRectTween.end.topLeft) {
final Rect sidekickRectEnd =
toSidekickOrigin & sidekickRectTween.end.size;
Expand Down Expand Up @@ -376,8 +380,8 @@ class _SidekickFlight {
manifest.toSidekick.startFlight();

sidekickRectTween = _doCreateRectTween(
_globalBoundingBoxFor(manifest.fromSidekick.context),
_globalBoundingBoxFor(manifest.toSidekick.context),
_boundingBoxFor(manifest.fromSidekick.context, manifest.overlay.context),
_boundingBoxFor(manifest.toSidekick.context, manifest.overlay.context),
);

overlayEntry = OverlayEntry(builder: _buildOverlay);
Expand Down Expand Up @@ -418,7 +422,7 @@ class _SidekickFlight {
manifest.fromSidekick.endFlight();
newManifest.toSidekick.startFlight();
sidekickRectTween = _doCreateRectTween(sidekickRectTween.end,
_globalBoundingBoxFor(newManifest.toSidekick.context));
_boundingBoxFor(newManifest.toSidekick.context, newManifest.overlay.context));
} else {
// TODO(hansmuller): Use ReverseTween here per github.com/flutter/flutter/pull/12203.
sidekickRectTween =
Expand All @@ -430,7 +434,7 @@ class _SidekickFlight {

sidekickRectTween = _doCreateRectTween(
sidekickRectTween.evaluate(_proxyAnimation),
_globalBoundingBoxFor(newManifest.toSidekick.context));
_boundingBoxFor(newManifest.toSidekick.context, newManifest.overlay.context));
shuttle = null;

if (newManifest.type == SidekickFlightDirection.toSource)
Expand Down Expand Up @@ -519,6 +523,11 @@ class SidekickController extends Animation<double> {

@mustCallSuper
void dispose() {
if (_controller?.status == AnimationStatus.forward) {
_controller.value = 1;
} else if (_controller?.status == AnimationStatus.reverse) {
_controller.value = 0;
}
_controller?.dispose();
}

Expand Down Expand Up @@ -588,7 +597,7 @@ class SidekickController extends Animation<double> {
SidekickFlightDirection flightType,
List<Object> tags,
) {
final Rect rect = _globalBoundingBoxFor(context);
final Rect rect = _boundingBoxFor(context);

final Map<Object, _SidekickState> sidekicks =
Sidekick._allSidekicksFor(context);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_sidekick
description: Widgets for creating Hero-like animations between two widgets within the same screen
version: 0.1.3
version: 0.1.4
author: Romain Rastel <lets4r@gmail.com>
homepage: https://github.com/letsar/flutter_sidekick

Expand Down