Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
6dc9bf0a
Unverified
Commit
6dc9bf0a
authored
Sep 11, 2019
by
Michael Goderbauer
Committed by
GitHub
Sep 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix curve for popping hero (#39844)
parent
0de6fc82
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
7 deletions
+91
-7
heroes.dart
packages/flutter/lib/src/widgets/heroes.dart
+6
-1
heroes_test.dart
packages/flutter/test/widgets/heroes_test.dart
+85
-6
No files found.
packages/flutter/lib/src/widgets/heroes.dart
View file @
6dc9bf0a
...
...
@@ -413,6 +413,7 @@ class _HeroFlightManifest {
@required
this
.
createRectTween
,
@required
this
.
shuttleBuilder
,
@required
this
.
isUserGestureTransition
,
@required
this
.
isDiverted
,
})
:
assert
(
fromHero
.
widget
.
tag
==
toHero
.
widget
.
tag
);
final
HeroFlightDirection
type
;
...
...
@@ -425,6 +426,7 @@ class _HeroFlightManifest {
final
CreateRectTween
createRectTween
;
final
HeroFlightShuttleBuilder
shuttleBuilder
;
final
bool
isUserGestureTransition
;
final
bool
isDiverted
;
Object
get
tag
=>
fromHero
.
widget
.
tag
;
...
...
@@ -432,6 +434,7 @@ class _HeroFlightManifest {
return
CurvedAnimation
(
parent:
(
type
==
HeroFlightDirection
.
push
)
?
toRoute
.
animation
:
fromRoute
.
animation
,
curve:
Curves
.
fastOutSlowIn
,
reverseCurve:
isDiverted
?
null
:
Curves
.
fastOutSlowIn
.
flipped
,
);
}
...
...
@@ -805,6 +808,7 @@ class HeroController extends NavigatorObserver {
if
(
toHeroes
[
tag
]
!=
null
)
{
final
HeroFlightShuttleBuilder
fromShuttleBuilder
=
fromHeroes
[
tag
].
widget
.
flightShuttleBuilder
;
final
HeroFlightShuttleBuilder
toShuttleBuilder
=
toHeroes
[
tag
].
widget
.
flightShuttleBuilder
;
final
bool
isDiverted
=
_flights
[
tag
]
!=
null
;
final
_HeroFlightManifest
manifest
=
_HeroFlightManifest
(
type:
flightType
,
...
...
@@ -818,9 +822,10 @@ class HeroController extends NavigatorObserver {
shuttleBuilder:
toShuttleBuilder
??
fromShuttleBuilder
??
_defaultHeroFlightShuttleBuilder
,
isUserGestureTransition:
isUserGestureTransition
,
isDiverted:
isDiverted
,
);
if
(
_flights
[
tag
]
!=
null
)
if
(
isDiverted
)
_flights
[
tag
].
divert
(
manifest
);
else
_flights
[
tag
]
=
_HeroFlight
(
_handleFlightEnded
)..
start
(
manifest
);
...
...
packages/flutter/test/widgets/heroes_test.dart
View file @
6dc9bf0a
...
...
@@ -1254,17 +1254,17 @@ Future<void> main() async {
await
tester
.
pump
(
duration
*
0.25
);
actualHeroCenter
=
tester
.
getCenter
(
find
.
byKey
(
firstKey
));
predictedHeroCenter
=
popCenterTween
.
lerp
(
curve
.
flipped
.
transform
(
0.25
));
predictedHeroCenter
=
popCenterTween
.
lerp
(
curve
.
transform
(
0.25
));
expect
(
actualHeroCenter
,
within
<
Offset
>(
distance:
epsilon
,
from:
predictedHeroCenter
));
await
tester
.
pump
(
duration
*
0.25
);
actualHeroCenter
=
tester
.
getCenter
(
find
.
byKey
(
firstKey
));
predictedHeroCenter
=
popCenterTween
.
lerp
(
curve
.
flipped
.
transform
(
0.5
));
predictedHeroCenter
=
popCenterTween
.
lerp
(
curve
.
transform
(
0.5
));
expect
(
actualHeroCenter
,
within
<
Offset
>(
distance:
epsilon
,
from:
predictedHeroCenter
));
await
tester
.
pump
(
duration
*
0.25
);
actualHeroCenter
=
tester
.
getCenter
(
find
.
byKey
(
firstKey
));
predictedHeroCenter
=
popCenterTween
.
lerp
(
curve
.
flipped
.
transform
(
0.75
));
predictedHeroCenter
=
popCenterTween
.
lerp
(
curve
.
transform
(
0.75
));
expect
(
actualHeroCenter
,
within
<
Offset
>(
distance:
epsilon
,
from:
predictedHeroCenter
));
await
tester
.
pumpAndSettle
();
...
...
@@ -1375,17 +1375,17 @@ Future<void> main() async {
await
tester
.
pump
(
duration
*
0.25
);
actualHeroRect
=
tester
.
getRect
(
find
.
byKey
(
firstKey
));
predictedHeroRect
=
popRectTween
.
lerp
(
curve
.
flipped
.
transform
(
0.25
));
predictedHeroRect
=
popRectTween
.
lerp
(
curve
.
transform
(
0.25
));
expect
(
actualHeroRect
,
within
<
Rect
>(
distance:
epsilon
,
from:
predictedHeroRect
));
await
tester
.
pump
(
duration
*
0.25
);
actualHeroRect
=
tester
.
getRect
(
find
.
byKey
(
firstKey
));
predictedHeroRect
=
popRectTween
.
lerp
(
curve
.
flipped
.
transform
(
0.5
));
predictedHeroRect
=
popRectTween
.
lerp
(
curve
.
transform
(
0.5
));
expect
(
actualHeroRect
,
within
<
Rect
>(
distance:
epsilon
,
from:
predictedHeroRect
));
await
tester
.
pump
(
duration
*
0.25
);
actualHeroRect
=
tester
.
getRect
(
find
.
byKey
(
firstKey
));
predictedHeroRect
=
popRectTween
.
lerp
(
curve
.
flipped
.
transform
(
0.75
));
predictedHeroRect
=
popRectTween
.
lerp
(
curve
.
transform
(
0.75
));
expect
(
actualHeroRect
,
within
<
Rect
>(
distance:
epsilon
,
from:
predictedHeroRect
));
await
tester
.
pumpAndSettle
();
...
...
@@ -2255,4 +2255,83 @@ Future<void> main() async {
moreOrLessEquals
(
tester
.
getTopLeft
(
find
.
text
(
'1'
)).
dx
,
epsilon:
0.01
)
);
});
testWidgets
(
'popped hero uses fastOutSlowIn curve'
,
(
WidgetTester
tester
)
async
{
final
Key
container1
=
UniqueKey
();
final
Key
container2
=
UniqueKey
();
final
GlobalKey
<
NavigatorState
>
navigator
=
GlobalKey
<
NavigatorState
>();
final
Animatable
<
Size
>
tween
=
SizeTween
(
begin:
const
Size
(
200
,
200
),
end:
const
Size
(
100
,
100
),
).
chain
(
CurveTween
(
curve:
Curves
.
fastOutSlowIn
));
await
tester
.
pumpWidget
(
MaterialApp
(
navigatorKey:
navigator
,
home:
Scaffold
(
body:
Center
(
child:
Hero
(
tag:
'test'
,
createRectTween:
(
Rect
begin
,
Rect
end
)
{
return
RectTween
(
begin:
begin
,
end:
end
);
},
child:
Container
(
key:
container1
,
height:
100
,
width:
100
,
),
),
),
),
),
);
final
Size
originalSize
=
tester
.
getSize
(
find
.
byKey
(
container1
));
expect
(
originalSize
,
const
Size
(
100
,
100
));
navigator
.
currentState
.
push
(
MaterialPageRoute
<
void
>(
builder:
(
BuildContext
context
)
{
return
Scaffold
(
body:
Center
(
child:
Hero
(
tag:
'test'
,
createRectTween:
(
Rect
begin
,
Rect
end
)
{
return
RectTween
(
begin:
begin
,
end:
end
);
},
child:
Container
(
key:
container2
,
height:
200
,
width:
200
,
),
),
),
);
}));
await
tester
.
pumpAndSettle
();
final
Size
newSize
=
tester
.
getSize
(
find
.
byKey
(
container2
));
expect
(
newSize
,
const
Size
(
200
,
200
));
navigator
.
currentState
.
pop
();
await
tester
.
pump
();
// Jump 25% into the transition (total length = 300ms)
await
tester
.
pump
(
const
Duration
(
milliseconds:
75
));
// 25% of 300ms
Size
heroSize
=
tester
.
getSize
(
find
.
byKey
(
container1
));
expect
(
heroSize
,
tween
.
transform
(
0.25
));
// Jump to 50% into the transition.
await
tester
.
pump
(
const
Duration
(
milliseconds:
75
));
// 25% of 300ms
heroSize
=
tester
.
getSize
(
find
.
byKey
(
container1
));
expect
(
heroSize
,
tween
.
transform
(
0.50
));
// Jump to 75% into the transition.
await
tester
.
pump
(
const
Duration
(
milliseconds:
75
));
// 25% of 300ms
heroSize
=
tester
.
getSize
(
find
.
byKey
(
container1
));
expect
(
heroSize
,
tween
.
transform
(
0.75
));
// Jump to 100% into the transition.
await
tester
.
pump
(
const
Duration
(
milliseconds:
75
));
// 25% of 300ms
heroSize
=
tester
.
getSize
(
find
.
byKey
(
container1
));
expect
(
heroSize
,
tween
.
transform
(
1.0
));
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment