Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_34031325
engine
提交
52fcac5f
E
engine
项目概览
qq_34031325
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,体验更适合开发者的 AI 搜索 >>
提交
52fcac5f
编写于
9月 18, 2015
作者:
I
Ian Hickson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1239 from Hixie/routes2
Allow route transitions to be more flexible
上级
6888a2cf
e56f8322
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
68 addition
and
98 deletion
+68
-98
sky/packages/sky/lib/src/animation/animated_value.dart
sky/packages/sky/lib/src/animation/animated_value.dart
+2
-2
sky/packages/sky/lib/src/animation/curves.dart
sky/packages/sky/lib/src/animation/curves.dart
+6
-7
sky/packages/sky/lib/src/widgets/dialog.dart
sky/packages/sky/lib/src/widgets/dialog.dart
+7
-9
sky/packages/sky/lib/src/widgets/navigator.dart
sky/packages/sky/lib/src/widgets/navigator.dart
+52
-79
sky/packages/sky/lib/src/widgets/popup_menu.dart
sky/packages/sky/lib/src/widgets/popup_menu.dart
+1
-1
未找到文件。
sky/packages/sky/lib/src/animation/animated_value.dart
浏览文件 @
52fcac5f
...
...
@@ -30,9 +30,9 @@ abstract class AnimatedVariable {
/// can be made to take longer in one direction that the other.
class
AnimationTiming
{
AnimationTiming
({
this
.
interval
,
this
.
interval
:
const
Interval
(
0.0
,
1.0
)
,
this
.
reverseInterval
,
this
.
curve
,
this
.
curve
:
linear
,
this
.
reverseCurve
});
...
...
sky/packages/sky/lib/src/animation/curves.dart
浏览文件 @
52fcac5f
...
...
@@ -27,14 +27,9 @@ class Linear implements Curve {
double
transform
(
double
t
)
=>
t
;
}
/// A curve that is
initially 0.0, then linear
, then 1.0
/// A curve that is
0.0 until start, then linear from 0.0 to 1.0 at end
, then 1.0
class
Interval
implements
Curve
{
Interval
(
this
.
start
,
this
.
end
)
{
assert
(
start
>=
0.0
);
assert
(
start
<=
1.0
);
assert
(
end
>=
0.0
);
assert
(
end
<=
1.0
);
}
const
Interval
(
this
.
start
,
this
.
end
);
/// The smallest value for which this interval is 0.0
final
double
start
;
...
...
@@ -43,6 +38,10 @@ class Interval implements Curve {
final
double
end
;
double
transform
(
double
t
)
{
assert
(
start
>=
0.0
);
assert
(
start
<=
1.0
);
assert
(
end
>=
0.0
);
assert
(
end
<=
1.0
);
return
((
t
-
start
)
/
(
end
-
start
)).
clamp
(
0.0
,
1.0
);
}
}
...
...
sky/packages/sky/lib/src/widgets/dialog.dart
浏览文件 @
52fcac5f
...
...
@@ -139,21 +139,19 @@ class DialogRoute extends RouteBase {
final
Completer
completer
;
final
RouteBuilder
builder
;
Widget
build
(
Navigator
navigator
,
RouteBase
route
)
=>
builder
(
navigator
,
route
);
bool
get
isOpaque
=>
false
;
void
popState
([
dynamic
result
])
{
completer
.
complete
(
result
);
}
Duration
get
transitionDuration
=>
_kTransitionDuration
;
TransitionBase
buildTransition
({
Key
key
,
Widget
child
,
WatchableAnimationPerformance
performance
})
{
bool
get
isOpaque
=>
false
;
Widget
build
(
Key
key
,
Navigator
navigator
,
RouteBase
route
,
WatchableAnimationPerformance
performance
)
{
return
new
FadeTransition
(
performance:
performance
,
opacity:
new
AnimatedValue
<
double
>(
0.0
,
end:
1.0
,
curve:
easeOut
),
child:
child
child:
builder
(
navigator
,
route
)
);
}
void
popState
([
dynamic
result
])
{
completer
.
complete
(
result
);
}
}
Future
showDialog
(
Navigator
navigator
,
DialogBuilder
builder
)
{
...
...
sky/packages/sky/lib/src/widgets/navigator.dart
浏览文件 @
52fcac5f
...
...
@@ -13,40 +13,44 @@ typedef Widget RouteBuilder(Navigator navigator, RouteBase route);
typedef
void
NotificationCallback
(
);
abstract
class
RouteBase
{
Widget
build
(
Navigator
navigator
,
RouteBase
route
);
bool
get
isOpaque
;
void
popState
([
dynamic
result
])
{
assert
(
result
==
null
);
}
AnimationPerformance
_performance
;
NotificationCallback
onDismissed
;
NotificationCallback
onCompleted
;
AnimationPerformance
createPerformance
()
{
AnimationPerformance
result
=
new
AnimationPerformance
(
duration:
transitionDuration
);
result
.
addStatusListener
((
AnimationStatus
status
)
{
switch
(
status
)
{
case
AnimationStatus
.
dismissed
:
if
(
onDismissed
!=
null
)
onDismissed
();
break
;
case
AnimationStatus
.
completed
:
if
(
onCompleted
!=
null
)
onCompleted
();
break
;
default
:
;
}
});
return
result
;
}
WatchableAnimationPerformance
ensurePerformance
({
Direction
direction
})
{
assert
(
direction
!=
null
);
if
(
_performance
==
null
)
{
_performance
=
new
AnimationPerformance
(
duration:
transitionDuration
);
_performance
.
addStatusListener
((
AnimationStatus
status
)
{
switch
(
status
)
{
case
AnimationStatus
.
dismissed
:
if
(
onDismissed
!=
null
)
onDismissed
();
break
;
case
AnimationStatus
.
completed
:
if
(
onCompleted
!=
null
)
onCompleted
();
break
;
default
:
;
}
});
}
if
(
_performance
==
null
)
_performance
=
createPerformance
();
AnimationStatus
desiredStatus
=
direction
==
Direction
.
forward
?
AnimationStatus
.
forward
:
AnimationStatus
.
reverse
;
if
(
_performance
.
status
!=
desiredStatus
)
_performance
.
play
(
direction
);
return
_performance
.
view
;
}
bool
get
isActuallyOpaque
=>
_performance
!=
null
&&
_performance
.
isCompleted
&&
isOpaque
;
bool
get
hasContent
=>
true
;
// set to false if you have nothing useful to return from build()
Duration
get
transitionDuration
;
TransitionBase
buildTransition
({
Key
key
,
Widget
child
,
WatchableAnimationPerformance
performance
});
bool
get
isOpaque
;
Widget
build
(
Key
key
,
Navigator
navigator
,
RouteBase
route
,
WatchableAnimationPerformance
performance
);
void
popState
([
dynamic
result
])
{
assert
(
result
==
null
);
}
String
toString
()
=>
'
$runtimeType
()'
;
}
...
...
@@ -59,11 +63,11 @@ class Route extends RouteBase {
final
String
name
;
final
RouteBuilder
builder
;
Widget
build
(
Navigator
navigator
,
RouteBase
route
)
=>
builder
(
navigator
,
route
);
bool
get
isOpaque
=>
true
;
Duration
get
transitionDuration
=>
_kTransitionDuration
;
TransitionBase
buildTransition
({
Key
key
,
Widget
child
,
WatchableAnimationPerformance
performance
})
{
Widget
build
(
Key
key
,
Navigator
navigator
,
RouteBase
route
,
WatchableAnimationPerformance
performance
)
{
// TODO(jackson): Hit testing should ignore transform
// TODO(jackson): Block input unless content is interactive
return
new
SlideTransition
(
...
...
@@ -73,7 +77,7 @@ class Route extends RouteBase {
child:
new
FadeTransition
(
performance:
performance
,
opacity:
new
AnimatedValue
<
double
>(
0.0
,
end:
1.0
,
curve:
easeOut
),
child:
child
child:
builder
(
navigator
,
route
)
)
);
}
...
...
@@ -88,7 +92,6 @@ class RouteState extends RouteBase {
RouteBase
route
;
StatefulComponent
owner
;
Widget
build
(
Navigator
navigator
,
RouteBase
route
)
=>
null
;
bool
get
isOpaque
=>
false
;
void
popState
([
dynamic
result
])
{
...
...
@@ -97,23 +100,9 @@ class RouteState extends RouteBase {
callback
(
this
);
}
// Custom state routes shouldn't be asked to construct a transition
Duration
get
transitionDuration
{
assert
(
false
);
return
const
Duration
();
}
TransitionBase
buildTransition
({
Key
key
,
Widget
child
,
WatchableAnimationPerformance
performance
})
{
assert
(
false
);
return
null
;
}
}
class
HistoryEntry
{
HistoryEntry
({
this
.
route
});
final
RouteBase
route
;
bool
fullyOpaque
=
false
;
// TODO(jackson): Keep track of the requested transition
String
toString
()
=>
"HistoryEntry(
$route
, hashCode=
$hashCode
)"
;
bool
get
hasContent
=>
false
;
Duration
get
transitionDuration
=>
const
Duration
();
Widget
build
(
Key
key
,
Navigator
navigator
,
RouteBase
route
,
WatchableAnimationPerformance
performance
)
=>
null
;
}
class
NavigationState
{
...
...
@@ -123,14 +112,14 @@ class NavigationState {
if
(
route
.
name
!=
null
)
namedRoutes
[
route
.
name
]
=
route
;
}
history
.
add
(
new
HistoryEntry
(
route:
routes
[
0
])
);
history
.
add
(
routes
[
0
]
);
}
List
<
HistoryEntry
>
history
=
new
List
<
HistoryEntry
>();
List
<
RouteBase
>
history
=
new
List
<
RouteBase
>();
int
historyIndex
=
0
;
Map
<
String
,
RouteBase
>
namedRoutes
=
new
Map
<
String
,
RouteBase
>();
RouteBase
get
currentRoute
=>
history
[
historyIndex
]
.
route
;
RouteBase
get
currentRoute
=>
history
[
historyIndex
];
bool
hasPrevious
()
=>
historyIndex
>
0
;
void
pushNamed
(
String
name
)
{
...
...
@@ -141,22 +130,20 @@ class NavigationState {
void
push
(
RouteBase
route
)
{
assert
(!
_debugCurrentlyHaveRoute
(
route
));
HistoryEntry
historyEntry
=
new
HistoryEntry
(
route:
route
);
history
.
insert
(
historyIndex
+
1
,
historyEntry
);
history
.
insert
(
historyIndex
+
1
,
route
);
historyIndex
++;
}
void
pop
([
dynamic
result
])
{
if
(
historyIndex
>
0
)
{
HistoryEntry
entry
=
history
[
historyIndex
];
entry
.
route
.
popState
(
result
);
entry
.
fullyOpaque
=
false
;
RouteBase
route
=
history
[
historyIndex
];
route
.
popState
(
result
);
historyIndex
--;
}
}
bool
_debugCurrentlyHaveRoute
(
RouteBase
route
)
{
return
history
.
any
((
entry
)
=>
entry
.
rou
te
==
route
);
return
history
.
any
((
candidate
)
=>
candida
te
==
route
);
}
}
...
...
@@ -201,39 +188,25 @@ class Navigator extends StatefulComponent {
Widget
build
()
{
List
<
Widget
>
visibleRoutes
=
new
List
<
Widget
>();
for
(
int
i
=
0
;
i
<
state
.
history
.
length
;
i
++)
{
// Avoid building routes that are not visible
if
(
i
+
1
<
state
.
history
.
length
&&
state
.
history
[
i
+
1
].
fullyOpaque
)
continue
;
HistoryEntry
historyEntry
=
state
.
history
[
i
];
Widget
child
=
historyEntry
.
route
.
build
(
this
,
historyEntry
.
route
);
if
(
i
==
0
)
{
visibleRoutes
.
add
(
child
);
for
(
int
i
=
state
.
history
.
length
-
1
;
i
>=
0
;
i
-=
1
)
{
RouteBase
route
=
state
.
history
[
i
];
if
(!
route
.
hasContent
)
continue
;
}
if
(
child
==
null
)
continue
;
WatchableAnimationPerformance
performance
=
historyEntry
.
route
.
ensurePerformance
(
WatchableAnimationPerformance
performance
=
route
.
ensurePerformance
(
direction:
(
i
<=
state
.
historyIndex
)
?
Direction
.
forward
:
Direction
.
reverse
);
historyEntry
.
route
.
onDismissed
=
()
{
route
.
onDismissed
=
()
{
setState
(()
{
assert
(
state
.
history
.
contains
(
historyEntry
));
state
.
history
.
remove
(
historyEntry
);
assert
(
state
.
history
.
contains
(
route
));
state
.
history
.
remove
(
route
);
});
};
historyEntry
.
route
.
onCompleted
=
()
{
setState
(()
{
historyEntry
.
fullyOpaque
=
historyEntry
.
route
.
isOpaque
;
});
};
TransitionBase
transition
=
historyEntry
.
route
.
buildTransition
(
key:
new
ObjectKey
(
historyEntry
),
child:
child
,
performance:
performance
);
visibleRoutes
.
add
(
transition
);
Key
key
=
new
ObjectKey
(
route
);
Widget
widget
=
route
.
build
(
key
,
this
,
route
,
performance
);
visibleRoutes
.
add
(
widget
);
if
(
route
.
isActuallyOpaque
)
break
;
}
return
new
Focus
(
child:
new
Stack
(
visibleRoutes
));
return
new
Focus
(
child:
new
Stack
(
visibleRoutes
.
reversed
.
toList
()
));
}
}
sky/packages/sky/lib/src/widgets/popup_menu.dart
浏览文件 @
52fcac5f
...
...
@@ -15,7 +15,7 @@ import 'package:sky/src/widgets/scrollable.dart';
import
'package:sky/src/widgets/transitions.dart'
;
const
Duration
_kMenuDuration
=
const
Duration
(
milliseconds:
300
);
double
_kMenuCloseIntervalEnd
=
2.0
/
3.0
;
const
double
_kMenuCloseIntervalEnd
=
2.0
/
3.0
;
const
double
_kMenuWidthStep
=
56.0
;
const
double
_kMenuMargin
=
16.0
;
// 24.0 on tablet
const
double
_kMenuMinWidth
=
2.0
*
_kMenuWidthStep
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录