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
68acd261
Commit
68acd261
authored
Oct 08, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The Drawer should animate out when popped off the navigator
Now with more clear ownership over the Performance.
parent
d45bf145
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
70 deletions
+64
-70
drawer.dart
packages/flutter/lib/src/widgets/drawer.dart
+64
-70
No files found.
packages/flutter/lib/src/widgets/drawer.dart
View file @
68acd261
...
...
@@ -34,63 +34,45 @@ const Duration _kThemeChangeDuration = const Duration(milliseconds: 200);
const
Point
_kOpenPosition
=
Point
.
origin
;
const
Point
_kClosedPosition
=
const
Point
(-
_kWidth
,
0.0
);
class
Drawer
extends
Stateful
Component
{
Drawer
({
class
_Drawer
extends
Stateless
Component
{
_
Drawer
({
Key
key
,
this
.
child
,
this
.
level
:
3
,
this
.
navigator
this
.
performance
,
this
.
route
})
:
super
(
key:
key
);
final
Widget
child
;
final
int
level
;
final
NavigatorState
navigator
;
DrawerState
createState
()
=>
new
DrawerState
();
}
class
DrawerState
extends
State
<
Drawer
>
{
void
initState
()
{
super
.
initState
();
_performance
=
new
Performance
(
duration:
_kBaseSettleDuration
)
..
addStatusListener
((
PerformanceStatus
status
)
{
if
(
status
==
PerformanceStatus
.
dismissed
)
config
.
navigator
.
pop
();
});
_open
();
}
Performance
_performance
;
final
PerformanceView
performance
;
final
_DrawerRoute
route
;
Widget
build
(
BuildContext
context
)
{
Widget
mask
=
new
GestureDetector
(
onTap:
_
close
,
onTap:
route
.
close
,
child:
new
ColorTransition
(
performance:
_performance
.
view
,
performance:
performance
,
color:
new
AnimatedColorValue
(
Colors
.
transparent
,
end:
Colors
.
black54
),
child:
new
Container
()
)
);
Widget
content
=
new
SlideTransition
(
performance:
_performance
.
view
,
performance:
performance
,
position:
new
AnimatedValue
<
Point
>(
_kClosedPosition
,
end:
_kOpenPosition
),
child:
new
AnimatedContainer
(
curve:
ease
,
duration:
_kThemeChangeDuration
,
decoration:
new
BoxDecoration
(
backgroundColor:
Theme
.
of
(
context
).
canvasColor
,
boxShadow:
shadows
[
config
.
level
]),
boxShadow:
shadows
[
level
]),
width:
_kWidth
,
child:
c
onfig
.
c
hild
child:
child
)
);
return
new
GestureDetector
(
onHorizontalDragStart:
_performance
.
stop
,
onHorizontalDragUpdate:
_handleDragUpdate
,
onHorizontalDragEnd:
_handleDragEnd
,
child:
new
Stack
([
return
new
Stack
([
mask
,
new
Positioned
(
top:
0.0
,
...
...
@@ -98,56 +80,68 @@ class DrawerState extends State<Drawer> {
bottom:
0.0
,
child:
content
)
])
);
}
bool
get
_isMostlyClosed
=>
_performance
.
progress
<
0.5
;
void
_handleDragUpdate
(
double
delta
)
{
_performance
.
progress
+=
delta
/
_kWidth
;
}
void
_open
()
{
_performance
.
fling
(
velocity:
1.0
);
}
void
_close
()
{
_performance
.
fling
(
velocity:
-
1.0
);
}
void
_handleDragEnd
(
Offset
velocity
)
{
if
(
velocity
.
dx
.
abs
()
>=
_kMinFlingVelocity
)
{
_performance
.
fling
(
velocity:
velocity
.
dx
*
_kFlingVelocityScale
);
}
else
if
(
_isMostlyClosed
)
{
_close
();
}
else
{
_open
();
}
]);
}
}
class
DrawerRoute
extends
Route
{
DrawerRoute
({
this
.
child
,
this
.
level
});
class
_
DrawerRoute
extends
Route
{
_
DrawerRoute
({
this
.
child
,
this
.
level
});
final
Widget
child
;
final
int
level
;
PerformanceView
get
performance
=>
_performance
?.
view
;
Performance
_performance
=
new
Performance
(
duration:
_kBaseSettleDuration
);
bool
get
opaque
=>
false
;
Widget
build
(
NavigatorState
navigator
,
PerformanceView
nextRoutePerformance
)
{
return
new
Focus
(
key:
new
GlobalObjectKey
(
this
),
autofocus:
true
,
child:
new
Drawer
(
child:
new
GestureDetector
(
onHorizontalDragStart:
()
{
_performance
?.
stop
();
},
onHorizontalDragUpdate:
(
double
delta
)
{
_performance
?.
progress
=
delta
/
_kWidth
;
},
onHorizontalDragEnd:
_settle
,
child:
new
_Drawer
(
child:
child
,
level:
level
,
navigator:
navigator
performance:
performance
)
)
);
}
void
didPush
(
NavigatorState
navigator
)
{
super
.
didPush
(
navigator
);
_performance
.
forward
();
}
void
didPop
([
dynamic
result
])
{
super
.
didPop
(
result
);
_performance
.
reverse
();
_performance
=
null
;
}
void
_settle
(
Offset
velocity
)
{
if
(
velocity
.
dx
.
abs
()
>=
_kMinFlingVelocity
)
{
_performance
?.
fling
(
velocity:
velocity
.
dx
*
_kFlingVelocityScale
);
}
else
if
(
_performance
?.
progress
<
0.5
)
{
close
();
}
else
{
_performance
?.
fling
(
velocity:
1.0
);
}
}
void
close
()
{
_performance
?.
fling
(
velocity:
-
1.0
);
}
}
void
showDrawer
(
{
NavigatorState
navigator
,
Widget
child
,
int
level:
3
})
{
navigator
.
push
(
new
DrawerRoute
(
child:
child
,
level:
level
));
navigator
.
push
(
new
_
DrawerRoute
(
child:
child
,
level:
level
));
}
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