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
cc29757e
Commit
cc29757e
authored
Jul 17, 2015
by
Collin Jackson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Navigator improvements, avoid building invisible routes
parent
fd744a12
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
4 deletions
+37
-4
navigation.dart
packages/flutter/example/widgets/navigation.dart
+10
-0
navigator.dart
packages/flutter/lib/widgets/navigator.dart
+27
-4
No files found.
packages/flutter/example/widgets/navigation.dart
View file @
cc29757e
...
@@ -68,6 +68,16 @@ List<Route> routes = [
...
@@ -68,6 +68,16 @@ List<Route> routes = [
class
NavigationExampleApp
extends
App
{
class
NavigationExampleApp
extends
App
{
NavigationState
_navState
=
new
NavigationState
(
routes
);
NavigationState
_navState
=
new
NavigationState
(
routes
);
void
onBack
()
{
if
(
_navState
.
hasPrevious
())
{
setState
(()
{
_navState
.
pop
();
});
}
else
{
super
.
onBack
();
}
}
Widget
build
()
{
Widget
build
()
{
return
new
Flex
([
new
Navigator
(
_navState
)]);
return
new
Flex
([
new
Navigator
(
_navState
)]);
}
}
...
...
packages/flutter/lib/widgets/navigator.dart
View file @
cc29757e
...
@@ -42,8 +42,8 @@ class RouteState extends RouteBase {
...
@@ -42,8 +42,8 @@ class RouteState extends RouteBase {
// TODO(jackson): Refactor this into its own file
// TODO(jackson): Refactor this into its own file
// and support multiple transition types
// and support multiple transition types
const
Duration
_kTransitionDuration
=
const
Duration
(
milliseconds:
20
0
);
const
Duration
_kTransitionDuration
=
const
Duration
(
milliseconds:
15
0
);
const
Point
_kTransitionStartPoint
=
const
Point
(
0.0
,
100
.0
);
const
Point
_kTransitionStartPoint
=
const
Point
(
0.0
,
75
.0
);
enum
TransitionDirection
{
forward
,
reverse
}
enum
TransitionDirection
{
forward
,
reverse
}
class
Transition
extends
AnimatedComponent
{
class
Transition
extends
AnimatedComponent
{
Transition
({
Transition
({
...
@@ -51,12 +51,14 @@ class Transition extends AnimatedComponent {
...
@@ -51,12 +51,14 @@ class Transition extends AnimatedComponent {
this
.
content
,
this
.
content
,
this
.
direction
,
this
.
direction
,
this
.
onDismissed
,
this
.
onDismissed
,
this
.
onCompleted
,
this
.
interactive
this
.
interactive
})
:
super
(
key:
key
);
})
:
super
(
key:
key
);
Widget
content
;
Widget
content
;
TransitionDirection
direction
;
TransitionDirection
direction
;
bool
interactive
;
bool
interactive
;
Function
onDismissed
;
Function
onDismissed
;
Function
onCompleted
;
AnimatedType
<
Point
>
_position
;
AnimatedType
<
Point
>
_position
;
AnimatedType
<
double
>
_opacity
;
AnimatedType
<
double
>
_opacity
;
...
@@ -73,7 +75,8 @@ class Transition extends AnimatedComponent {
...
@@ -73,7 +75,8 @@ class Transition extends AnimatedComponent {
_performance
=
new
AnimationPerformance
()
_performance
=
new
AnimationPerformance
()
..
duration
=
_kTransitionDuration
..
duration
=
_kTransitionDuration
..
variable
=
new
AnimatedList
([
_position
,
_opacity
])
..
variable
=
new
AnimatedList
([
_position
,
_opacity
])
..
addListener
(
_checkDismissed
);
..
addListener
(
_checkDismissed
)
..
addListener
(
_checkCompleted
);
if
(
direction
==
TransitionDirection
.
reverse
)
if
(
direction
==
TransitionDirection
.
reverse
)
_performance
.
progress
=
1.0
;
_performance
.
progress
=
1.0
;
watch
(
_performance
);
watch
(
_performance
);
...
@@ -114,6 +117,17 @@ class Transition extends AnimatedComponent {
...
@@ -114,6 +117,17 @@ class Transition extends AnimatedComponent {
}
}
}
}
bool
_completed
=
false
;
void
_checkCompleted
()
{
if
(!
_completed
&&
direction
==
TransitionDirection
.
forward
&&
_performance
.
isCompleted
)
{
if
(
onCompleted
!=
null
)
onCompleted
();
_completed
=
true
;
}
}
Widget
build
()
{
Widget
build
()
{
Matrix4
transform
=
new
Matrix4
.
identity
()
Matrix4
transform
=
new
Matrix4
.
identity
()
..
translate
(
_position
.
value
.
x
,
_position
.
value
.
y
);
..
translate
(
_position
.
value
.
x
,
_position
.
value
.
y
);
...
@@ -133,6 +147,7 @@ class HistoryEntry {
...
@@ -133,6 +147,7 @@ class HistoryEntry {
HistoryEntry
({
this
.
route
,
this
.
key
});
HistoryEntry
({
this
.
route
,
this
.
key
});
final
RouteBase
route
;
final
RouteBase
route
;
final
int
key
;
final
int
key
;
bool
transitionFinished
=
false
;
// TODO(jackson): Keep track of the requested transition
// TODO(jackson): Keep track of the requested transition
}
}
...
@@ -170,6 +185,7 @@ class NavigationState {
...
@@ -170,6 +185,7 @@ class NavigationState {
if
(
historyIndex
>
0
)
{
if
(
historyIndex
>
0
)
{
HistoryEntry
entry
=
history
[
historyIndex
];
HistoryEntry
entry
=
history
[
historyIndex
];
entry
.
route
.
popState
();
entry
.
route
.
popState
();
entry
.
transitionFinished
=
false
;
historyIndex
--;
historyIndex
--;
}
}
}
}
...
@@ -217,7 +233,9 @@ class Navigator extends StatefulComponent {
...
@@ -217,7 +233,9 @@ class Navigator extends StatefulComponent {
Widget
build
()
{
Widget
build
()
{
List
<
Widget
>
visibleRoutes
=
new
List
<
Widget
>();
List
<
Widget
>
visibleRoutes
=
new
List
<
Widget
>();
for
(
int
i
=
0
;
i
<
state
.
history
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
state
.
history
.
length
;
i
++)
{
// TODO(jackson): Avoid building routes that are not visible
// Avoid building routes that are not visible
if
(
i
+
1
<
state
.
history
.
length
&&
state
.
history
[
i
+
1
].
transitionFinished
)
continue
;
HistoryEntry
historyEntry
=
state
.
history
[
i
];
HistoryEntry
historyEntry
=
state
.
history
[
i
];
Widget
content
=
historyEntry
.
route
.
build
(
this
,
historyEntry
.
route
);
Widget
content
=
historyEntry
.
route
.
build
(
this
,
historyEntry
.
route
);
if
(
i
==
0
)
{
if
(
i
==
0
)
{
...
@@ -235,6 +253,11 @@ class Navigator extends StatefulComponent {
...
@@ -235,6 +253,11 @@ class Navigator extends StatefulComponent {
setState
(()
{
setState
(()
{
state
.
history
.
remove
(
historyEntry
);
state
.
history
.
remove
(
historyEntry
);
});
});
},
onCompleted:
()
{
setState
(()
{
historyEntry
.
transitionFinished
=
true
;
});
}
}
);
);
visibleRoutes
.
add
(
transition
);
visibleRoutes
.
add
(
transition
);
...
...
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