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
f6bd20ff
Commit
f6bd20ff
authored
Feb 27, 2016
by
Ian Hickson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2241 from Hixie/size-obs-8
SizeObserver crusade: Mimcable
parents
0dd7285d
157ac752
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
46 deletions
+50
-46
mimic.dart
packages/flutter/lib/src/widgets/mimic.dart
+50
-46
No files found.
packages/flutter/lib/src/widgets/mimic.dart
View file @
f6bd20ff
...
...
@@ -27,14 +27,14 @@ class MimicableHandle {
/// An overlay entry that is mimicking another widget.
class
MimicOverlayEntry
{
MimicOverlayEntry
.
_
(
this
.
_
key
)
{
MimicOverlayEntry
.
_
(
this
.
_
handle
)
{
_overlayEntry
=
new
OverlayEntry
(
builder:
_build
);
_initialGlobalBounds
=
_
key
.
globalBounds
;
_initialGlobalBounds
=
_
handle
.
globalBounds
;
}
Rect
_initialGlobalBounds
;
MimicableHandle
_
key
;
MimicableHandle
_
handle
;
OverlayEntry
_overlayEntry
;
// Animation state
...
...
@@ -53,7 +53,7 @@ class MimicOverlayEntry {
Duration
duration
,
Curve
curve:
Curves
.
linear
})
{
assert
(
_
key
!=
null
);
assert
(
_
handle
!=
null
);
assert
(
_overlayEntry
!=
null
);
assert
(
targetKey
!=
null
);
assert
(
duration
!=
null
);
...
...
@@ -84,14 +84,14 @@ class MimicOverlayEntry {
_curve
=
null
;
_controller
?.
stop
();
_controller
=
null
;
_
key
.
stopMimic
();
_
key
=
null
;
_
handle
.
stopMimic
();
_
handle
=
null
;
_overlayEntry
.
remove
();
_overlayEntry
=
null
;
}
Widget
_build
(
BuildContext
context
)
{
assert
(
_
key
!=
null
);
assert
(
_
handle
!=
null
);
assert
(
_overlayEntry
!=
null
);
Rect
globalBounds
=
_initialGlobalBounds
;
Point
globalPosition
=
globalBounds
.
topLeft
;
...
...
@@ -117,7 +117,7 @@ class MimicOverlayEntry {
top:
localPosition
.
y
,
width:
globalBounds
.
width
,
height:
globalBounds
.
height
,
child:
new
Mimic
(
original:
_
key
)
child:
new
Mimic
(
original:
_
handle
)
);
}
}
...
...
@@ -130,7 +130,7 @@ class Mimic extends StatelessComponent {
final
MimicableHandle
original
;
Widget
build
(
BuildContext
context
)
{
if
(
original
!=
null
&&
original
.
_state
.
_beingMimicked
)
if
(
original
!=
null
&&
original
.
_state
.
mounted
&&
original
.
_state
.
_placeholderSize
!=
null
)
return
original
.
_state
.
config
.
child
;
return
new
Container
();
}
...
...
@@ -149,29 +149,49 @@ class Mimicable extends StatefulComponent {
///
/// Exposes an API for starting and stopping mimicking.
class
MimicableState
extends
State
<
Mimicable
>
{
Size
_size
;
bool
_beingMimicked
=
false
;
Size
_placeholderSize
;
Rect
get
_globalBounds
{
assert
(
mounted
);
RenderBox
box
=
context
.
findRenderObject
();
assert
(
box
!=
null
);
assert
(
box
.
hasSize
);
assert
(!
box
.
needsLayout
);
// TODO(abarth): The bounds will be wrong if there's a scale or rotation transform involved
return
box
.
localToGlobal
(
Point
.
origin
)
&
box
.
size
;
}
/// Start the mimicking process.
///
/// The child of this object will no longer be built at this location in the
/// tree. Instead, this widget will build a transparent placeholder with the
/// same dimensions as the widget had when the mimicking process started.
/// The child of this object will no longer be built at this
/// location in the tree. Instead, this widget will build a
/// transparent placeholder with the same dimensions as the widget
/// had when the mimicking process started.
///
/// If you use startMimic(), it is your responsibility to do
/// something with the returned [MimicableHandle]; typically,
/// passing it to a [Mimic] widget. To mimic the child in the
/// [Overlay], consider using [liftToOverlay()] instead.
MimicableHandle
startMimic
()
{
assert
(!
_beingMimicked
);
assert
(
_size
!=
null
);
assert
(
_placeholderSize
==
null
);
RenderBox
box
=
context
.
findRenderObject
();
assert
(
box
!=
null
);
assert
(
box
.
hasSize
);
assert
(!
box
.
needsLayout
);
setState
(()
{
_
beingMimicked
=
tru
e
;
_
placeholderSize
=
box
.
siz
e
;
});
return
new
MimicableHandle
.
_
(
this
);
}
/// Mimic this object in the enclosing overlay.
/// Start the mimicking process and mimic this object in the
/// enclosing [Overlay].
///
/// The child of this object will no longer be built at this location in the
/// tree. Instead, (1) this widget will build a transparent placeholder with
/// the same dimensions as the widget had when the mimicking process started
/// and (2) the child will be placed in the enclosing overlay.
/// The child of this object will no longer be built at this
/// location in the tree. Instead, (1) this widget will build a
/// transparent placeholder with the same dimensions as the widget
/// had when the mimicking process started and (2) the child will be
/// placed in the enclosing overlay.
MimicOverlayEntry
liftToOverlay
()
{
OverlayState
overlay
=
Overlay
.
of
(
context
);
assert
(
overlay
!=
null
);
// You need an overlay to lift into.
...
...
@@ -181,36 +201,20 @@ class MimicableState extends State<Mimicable> {
}
void
_stopMimic
()
{
assert
(
_beingMimicked
);
if
(!
mounted
)
{
_beingMimicked
=
false
;
return
;
assert
(
_placeholderSize
!=
null
);
if
(
mounted
)
{
setState
(()
{
_placeholderSize
=
null
;
});
}
setState
(()
{
_beingMimicked
=
false
;
});
}
Rect
get
_globalBounds
{
RenderBox
box
=
context
.
findRenderObject
();
return
box
.
localToGlobal
(
Point
.
origin
)
&
box
.
size
;
}
void
_handleSizeChanged
(
Size
size
)
{
setState
(()
{
_size
=
size
;
});
}
Widget
build
(
BuildContext
context
)
{
if
(
_
beingMimicked
)
{
if
(
_
placeholderSize
!=
null
)
{
return
new
ConstrainedBox
(
constraints:
new
BoxConstraints
.
tight
(
_
s
ize
)
constraints:
new
BoxConstraints
.
tight
(
_
placeholderS
ize
)
);
}
return
new
SizeObserver
(
onSizeChanged:
_handleSizeChanged
,
child:
config
.
child
);
return
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