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
13b8777f
Commit
13b8777f
authored
Feb 26, 2016
by
Ian Hickson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2230 from Hixie/size-obs-7
SizeObserver crusade: Heroes
parents
6ecbd548
8f2ef237
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
58 deletions
+35
-58
heroes.dart
packages/flutter/lib/src/widgets/heroes.dart
+35
-58
No files found.
packages/flutter/lib/src/widgets/heroes.dart
View file @
13b8777f
...
...
@@ -111,14 +111,13 @@ class Hero extends StatefulComponent {
final
Map
<
Key
,
HeroState
>
tagHeroes
=
heroes
.
putIfAbsent
(
tag
,
()
=>
<
Key
,
HeroState
>{});
assert
(()
{
if
(
tagHeroes
.
containsKey
(
key
))
{
debugPrint
(
'Tag:
$tag
Key:
$key
'
);
assert
(()
{
'There are multiple heroes that share the same key within the same subtree. '
'Within each subtree for which heroes are to be animated (typically a PageRoute subtree), '
'either each Hero must have a unique tag, or, all the heroes with a particular tag must '
'have different keys. The relevant tag and key were dumped above. '
;
return
false
;
});
new
WidgetError
(
'There are multiple heroes that share the same key within the same subtree.
\n
'
'Within each subtree for which heroes are to be animated (typically a PageRoute subtree),
\n
'
'either each Hero must have a unique tag, or, all the heroes with a particular tag must
\n
'
'have different keys.
\n
'
'In this case, the tag "
$tag
" had multiple heroes with the key "
$key
".'
);
}
return
true
;
});
...
...
@@ -149,86 +148,64 @@ class Hero extends StatefulComponent {
HeroState
createState
()
=>
new
HeroState
();
}
enum
_HeroMode
{
constructing
,
initialized
,
measured
,
taken
}
class
HeroState
extends
State
<
Hero
>
implements
HeroHandle
{
void
initState
()
{
assert
(
_mode
==
_HeroMode
.
constructing
);
super
.
initState
();
_key
=
new
GlobalKey
();
_mode
=
_HeroMode
.
initialized
;
}
GlobalKey
_key
;
_HeroMode
_mode
=
_HeroMode
.
constructing
;
Size
_size
;
GlobalKey
_key
=
new
GlobalKey
();
Size
_placeholderSize
;
bool
get
alwaysAnimate
=>
config
.
alwaysAnimate
;
_HeroManifest
_takeChild
(
Rect
animationArea
,
Animation
<
double
>
currentAnimation
)
{
assert
(
_mode
==
_HeroMode
.
measured
||
_mode
==
_HeroMode
.
taken
);
assert
(
mounted
);
final
RenderBox
renderObject
=
context
.
findRenderObject
();
assert
(
renderObject
!=
null
);
assert
(!
renderObject
.
needsLayout
);
assert
(
renderObject
.
hasSize
);
if
(
_placeholderSize
==
null
)
{
// We are a "from" hero, about to depart on a quest.
// Remember our size so that we can leave a placeholder.
_placeholderSize
=
renderObject
.
size
;
}
final
Point
heroTopLeft
=
renderObject
.
localToGlobal
(
Point
.
origin
);
final
Point
heroBottomRight
=
renderObject
.
localToGlobal
(
renderObject
.
size
.
bottomRight
(
Point
.
origin
));
final
Rect
heroArea
=
new
Rect
.
fromLTRB
(
heroTopLeft
.
x
,
heroTopLeft
.
y
,
heroBottomRight
.
x
,
heroBottomRight
.
y
);
final
RelativeRect
startRect
=
new
RelativeRect
.
fromRect
(
heroArea
,
animationArea
);
_HeroManifest
result
=
new
_HeroManifest
(
key:
_key
,
key:
_key
,
// might be null, e.g. if the hero is returning to us
config:
config
,
sourceStates:
new
HashSet
<
HeroState
>.
from
(<
HeroState
>[
this
]),
currentRect:
startRect
,
currentTurns:
config
.
turns
.
toDouble
()
);
setState
(()
{
_key
=
null
;
_mode
=
_HeroMode
.
taken
;
});
if
(
_key
!=
null
)
setState
(()
{
_key
=
null
;
});
return
result
;
}
void
_setChild
(
GlobalKey
value
)
{
assert
(
_mode
==
_HeroMode
.
taken
);
assert
(
_key
==
null
);
assert
(
_size
!=
null
);
if
(
mounted
)
setState
(()
{
_key
=
value
;
});
_size
=
null
;
_mode
=
_HeroMode
.
initialized
;
assert
(
_placeholderSize
!=
null
);
assert
(
mounted
);
setState
(()
{
_key
=
value
;
_placeholderSize
=
null
;
});
}
void
_resetChild
()
{
assert
(
_mode
==
_HeroMode
.
taken
);
assert
(
_key
==
null
);
assert
(
_size
!=
null
);
if
(
mounted
)
setState
(()
{
_key
=
new
GlobalKey
();
});
_size
=
null
;
_mode
=
_HeroMode
.
initialized
;
_setChild
(
null
);
}
Widget
build
(
BuildContext
context
)
{
switch
(
_mode
)
{
case
_HeroMode
.
constructing
:
assert
(
false
);
return
null
;
case
_HeroMode
.
initialized
:
case
_HeroMode
.
measured
:
return
new
SizeObserver
(
onSizeChanged:
(
Size
size
)
{
assert
(
_mode
==
_HeroMode
.
initialized
||
_mode
==
_HeroMode
.
measured
);
_size
=
size
;
_mode
=
_HeroMode
.
measured
;
},
child:
new
KeyedSubtree
(
key:
_key
,
child:
config
.
child
)
);
case
_HeroMode
.
taken
:
return
new
SizedBox
(
width:
_size
.
width
,
height:
_size
.
height
);
if
(
_placeholderSize
!=
null
)
{
assert
(
_key
==
null
);
return
new
SizedBox
(
width:
_placeholderSize
.
width
,
height:
_placeholderSize
.
height
);
}
return
new
KeyedSubtree
(
key:
_key
,
child:
config
.
child
);
}
}
...
...
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