Skip to content

Commit

Permalink
Fixed new bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Salby committed Aug 26, 2019
1 parent b1ea0ed commit 2fc77cf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [1.2.0+2] - 2019-08-26

### Fixes
- Fixed a rendering error caused by the last fix :)

## [1.2.0+1] - 2019-08-26

### Fixes
Expand Down
3 changes: 2 additions & 1 deletion lib/page_routes/morpheus_page_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ class MorpheusPageRoute<T> extends PageRoute<T> {

// Return page transition.
return MorpheusPageTransition(
renderBox: _getRenderBox(),
size: _getRenderBox().size,
offset: _getRenderBox().localToGlobal(Offset.zero),
context: context,
animation: animation,
secondaryAnimation: secondaryAnimation,
Expand Down
46 changes: 19 additions & 27 deletions lib/page_routes/morpheus_page_transition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import 'package:morpheus/tweens/page_transition_opacity_tween.dart';
/// Builds a parent-child material design navigation transition.
class MorpheusPageTransition extends StatelessWidget {
MorpheusPageTransition({
this.renderBox,
@required this.size,
@required this.offset,
@required BuildContext context,
@required this.animation,
@required this.secondaryAnimation,
Expand All @@ -19,38 +20,31 @@ class MorpheusPageTransition extends StatelessWidget {
assert(child != null),
assert(settings != null),
transitionContext = context,
renderBoxSize = renderBox?.size,
renderBoxOffset = renderBox?.localToGlobal(Offset.zero);
hasRenderBox = size == null || offset == null;

/// The [RenderBox] used to calculate the origin of the parent-child
/// transition.
final RenderBox renderBox;
/// Defines the initial [Size] of a parent-child transition.
final Size size;

/// Defines the initial [Offset] of a parent-child transition.
final Offset offset;

final bool hasRenderBox;

final BuildContext transitionContext;
final Animation<double> animation;
final Animation<double> secondaryAnimation;
final Widget child;
final MorpheusRouteArguments settings;

/// The size of [renderBox].
///
/// Returns null if [renderBox] is null.
final Size renderBoxSize;

/// The calculated [Offset] of [renderBox].
///
/// Returns null if [renderBox] is null.
final Offset renderBoxOffset;

/// Returns true if the parent widget spans the entire width of the screen.
///
/// returns false if [renderBox] is null.
bool get useVerticalTransition {
// Return null if [renderBox] is null.
if (renderBox == null) return false;
if (!hasRenderBox) return false;

final screenWidth = MediaQuery.of(transitionContext).size.width;
return renderBoxSize.width == screenWidth && renderBoxOffset.dx == 0.0;
return size.width == screenWidth && offset.dx == 0.0;
}

/// Returns an [Animation] used to animate the transition from the parent widget
Expand Down Expand Up @@ -110,7 +104,7 @@ class MorpheusPageTransition extends StatelessWidget {
/// Returns a [RelativeRectTween] that is used to animate from the origin
/// of [renderBox] to the size of the screen.
RelativeRectTween positionTween(BoxConstraints constraints) {
final origin = renderBoxOffset & renderBoxSize;
final origin = offset & size;
return RelativeRectTween(
begin: RelativeRect.fromLTRB(
origin.left,
Expand Down Expand Up @@ -152,7 +146,7 @@ class MorpheusPageTransition extends StatelessWidget {
),
));

if (renderBox == null) {
if (!hasRenderBox) {
return buildDefaultTransition();
}

Expand Down Expand Up @@ -237,10 +231,10 @@ class MorpheusPageTransition extends StatelessWidget {
Widget buildBidirectionalTransition(Widget childScreen) {
final Animation<double> scaleParentAnimation = Tween<double>(
begin: 1.0,
end: MediaQuery.of(transitionContext).size.width / renderBoxSize.width,
end: MediaQuery.of(transitionContext).size.width / size.width,
).animate(positionAnimationCurve);
final Animation<double> scaleChildAnimation = Tween<double>(
begin: renderBoxSize.width / MediaQuery.of(transitionContext).size.width,
begin: size.width / MediaQuery.of(transitionContext).size.width,
end: 1.0,
).animate(positionAnimationCurve);
final parentWidget = transitionWidget != null
Expand All @@ -267,9 +261,7 @@ class MorpheusPageTransition extends StatelessWidget {
: ConstantTween<double>(1.0).animate(animation),
child: childScreen,
),
)
.animate(positionAnimationCurve)
.value,
).animate(positionAnimationCurve).value,
);
}

Expand Down Expand Up @@ -346,8 +338,8 @@ class MorpheusPageTransition extends StatelessWidget {
padding: widget.padding,
decoration: widget.decoration,
foregroundDecoration: widget.foregroundDecoration,
width: renderBoxSize.width,
height: renderBoxSize.height,
width: size.width,
height: size.height,
constraints: widget.constraints,
margin: widget.margin,
transform: widget.transform,
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: morpheus
description: A Flutter package for easily implementing Material Design navigation transitions.
version: 1.2.0+1
version: 1.2.0+2
author: Sander Dalby Larsen <[email protected]>
homepage: https://github.com/salby/morpheus

Expand Down

0 comments on commit 2fc77cf

Please sign in to comment.