Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
cbcb1db9
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cbcb1db9
编写于
10月 07, 2015
作者:
A
Adam Barth
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
The Drawer should animate out when popped off the navigator
Now with more clear ownership over the Performance.
上级
10525372
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
64 addition
and
70 deletion
+64
-70
sky/packages/sky/lib/src/widgets/drawer.dart
sky/packages/sky/lib/src/widgets/drawer.dart
+64
-70
未找到文件。
sky/packages/sky/lib/src/widgets/drawer.dart
浏览文件 @
cbcb1db9
...
...
@@ -34,120 +34,114 @@ 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
([
mask
,
new
Positioned
(
top:
0.0
,
left:
0.0
,
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
();
}
return
new
Stack
([
mask
,
new
Positioned
(
top:
0.0
,
left:
0.0
,
bottom:
0.0
,
child:
content
)
]);
}
}
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:
child
,
level:
level
,
navigator:
navigator
child:
new
GestureDetector
(
onHorizontalDragStart:
()
{
_performance
?.
stop
();
},
onHorizontalDragUpdate:
(
double
delta
)
{
_performance
?.
progress
=
delta
/
_kWidth
;
},
onHorizontalDragEnd:
_settle
,
child:
new
_Drawer
(
child:
child
,
level:
level
,
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
));
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录