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
839e997e
Commit
839e997e
authored
Jul 22, 2015
by
Matt Perry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rebase
parent
136b2709
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
106 additions
and
154 deletions
+106
-154
BUILD.gn
packages/flutter/BUILD.gn
+0
-1
stock_home.dart
packages/flutter/example/stocks/lib/stock_home.dart
+15
-22
animation_builder.dart
packages/flutter/lib/widgets/animation_builder.dart
+0
-115
drawer.dart
packages/flutter/lib/widgets/drawer.dart
+12
-0
snack_bar.dart
packages/flutter/lib/widgets/snack_bar.dart
+79
-16
No files found.
packages/flutter/BUILD.gn
View file @
839e997e
...
...
@@ -52,7 +52,6 @@ dart_pkg("sky") {
"lib/theme/view_configuration.dart",
"lib/widgets/animated_component.dart",
"lib/widgets/animated_container.dart",
"lib/widgets/animation_builder.dart",
"lib/widgets/basic.dart",
"lib/widgets/block_viewport.dart",
"lib/widgets/button_base.dart",
...
...
packages/flutter/example/stocks/lib/stock_home.dart
View file @
839e997e
...
...
@@ -3,9 +3,6 @@
// found in the LICENSE file.
import
'package:sky/editing/input.dart'
;
import
'package:sky/animation/animated_value.dart'
;
import
'package:sky/widgets/animated_component.dart'
;
import
'package:sky/widgets/animation_builder.dart'
;
import
'package:sky/theme/colors.dart'
as
colors
;
import
'package:sky/widgets/basic.dart'
;
import
'package:sky/widgets/drawer.dart'
;
...
...
@@ -35,7 +32,7 @@ typedef void ModeUpdater(StockMode mode);
const
Duration
_kSnackbarSlideDuration
=
const
Duration
(
milliseconds:
200
);
class
StockHome
extends
Animated
Component
{
class
StockHome
extends
Stateful
Component
{
StockHome
(
this
.
navigator
,
this
.
stocks
,
this
.
stockMode
,
this
.
modeUpdater
);
...
...
@@ -54,7 +51,8 @@ class StockHome extends AnimatedComponent {
bool
_isSearching
=
false
;
String
_searchQuery
;
AnimationBuilder
_snackbarTransform
;
SnackBarStatus
_snackBarStatus
;
bool
_isSnackBarShowing
=
false
;
// Should it be showing?
void
_handleSearchBegin
()
{
navigator
.
pushState
(
this
,
(
_
)
{
...
...
@@ -140,6 +138,7 @@ class StockHome extends AnimatedComponent {
Drawer
buildDrawer
()
{
if
(
_drawerStatus
==
DrawerStatus
.
inactive
)
return
null
;
assert
(
_drawerShowing
);
// TODO(mpcomplete): this is always true
return
new
Drawer
(
level:
3
,
showing:
_drawerShowing
,
...
...
@@ -264,40 +263,34 @@ class StockHome extends AnimatedComponent {
void
_handleUndo
()
{
setState
(()
{
_
snackbarTransform
=
null
;
_
isSnackBarShowing
=
false
;
});
}
Widget
buildSnackBar
()
{
if
(
_snack
barTransform
==
null
)
if
(
_snack
BarStatus
==
SnackBarStatus
.
inactive
)
return
null
;
return
_snackbarTransform
.
build
(
new
SnackBar
(
content:
new
Text
(
"Stock purchased!"
),
actions:
[
new
SnackBarAction
(
label:
"UNDO"
,
onPressed:
_handleUndo
)]
));
return
new
SnackBar
(
showing:
_isSnackBarShowing
,
content:
new
Text
(
"Stock purchased!"
),
actions:
[
new
SnackBarAction
(
label:
"UNDO"
,
onPressed:
_handleUndo
)],
onStatusChanged:
(
status
)
{
setState
(()
{
_snackBarStatus
=
status
;
});
}
);
}
void
_handleStockPurchased
()
{
setState
(()
{
_snackbarTransform
=
new
AnimationBuilder
()
..
position
=
new
AnimatedValue
<
Point
>(
const
Point
(
0.0
,
45.0
),
end:
Point
.
origin
);
var
performance
=
_snackbarTransform
.
createPerformance
(
[
_snackbarTransform
.
position
],
duration:
_kSnackbarSlideDuration
);
watch
(
performance
);
// TODO(mpcomplete): need to unwatch
performance
.
play
();
_isSnackBarShowing
=
true
;
_snackBarStatus
=
SnackBarStatus
.
active
;
});
}
Widget
buildFloatingActionButton
()
{
var
widget
=
new
FloatingActionButton
(
return
new
FloatingActionButton
(
child:
new
Icon
(
type:
'content/add'
,
size:
24
),
backgroundColor:
colors
.
RedAccent
[
200
],
onPressed:
_handleStockPurchased
);
if
(
_snackbarTransform
!=
null
)
widget
=
_snackbarTransform
.
build
(
widget
);
return
widget
;
}
void
addMenuToOverlays
(
List
<
Widget
>
overlays
)
{
...
...
packages/flutter/lib/widgets/animation_builder.dart
deleted
100644 → 0
View file @
136b2709
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:vector_math/vector_math.dart'
;
import
'package:sky/animation/animated_value.dart'
;
import
'package:sky/animation/animation_performance.dart'
;
import
'package:sky/painting/box_painter.dart'
;
import
'package:sky/theme/shadows.dart'
;
import
'package:sky/widgets/basic.dart'
;
// This class builds a Container object from a collection of optionally-
// animated properties. Use syncFields to update the Container's properties,
// which will optionally animate them using an AnimationPerformance.
class
AnimationBuilder
{
AnimationBuilder
();
AnimatedValue
<
double
>
opacity
;
AnimatedValue
<
Point
>
position
;
AnimatedValue
<
double
>
shadow
;
AnimatedColor
backgroundColor
;
// These don't animate, but are used to build the AnimationBuilder anyway.
double
borderRadius
;
Shape
shape
;
Map
<
AnimatedVariable
,
AnimationPerformance
>
_variableToPerformance
=
new
Map
<
AnimatedVariable
,
AnimationPerformance
>();
AnimationPerformance
createPerformance
(
List
<
AnimatedValue
>
variables
,
{
Duration
duration
})
{
AnimationPerformance
performance
=
new
AnimationPerformance
()
..
duration
=
duration
..
variable
=
new
AnimatedList
(
variables
);
for
(
AnimatedVariable
variable
in
variables
)
_variableToPerformance
[
variable
]
=
performance
;
return
performance
;
}
Widget
build
(
Widget
child
)
{
Widget
current
=
child
;
if
(
shadow
!=
null
||
backgroundColor
!=
null
||
borderRadius
!=
null
||
shape
!=
null
)
{
current
=
new
DecoratedBox
(
decoration:
new
BoxDecoration
(
borderRadius:
borderRadius
,
shape:
shape
,
boxShadow:
shadow
!=
null
?
_computeShadow
(
shadow
.
value
)
:
null
,
backgroundColor:
backgroundColor
!=
null
?
backgroundColor
.
value
:
null
),
child:
current
);
}
if
(
position
!=
null
)
{
Matrix4
transform
=
new
Matrix4
.
identity
();
transform
.
translate
(
position
.
value
.
x
,
position
.
value
.
y
);
current
=
new
Transform
(
transform:
transform
,
child:
current
);
}
if
(
opacity
!=
null
)
{
current
=
new
Opacity
(
opacity:
opacity
.
value
,
child:
current
);
}
return
current
;
}
void
updateFields
({
AnimatedValue
<
double
>
shadow
,
AnimatedColor
backgroundColor
,
double
borderRadius
,
Shape
shape
})
{
_updateField
(
this
.
shadow
,
shadow
);
_updateField
(
this
.
backgroundColor
,
backgroundColor
);
this
.
borderRadius
=
borderRadius
;
this
.
shape
=
shape
;
}
void
_updateField
(
AnimatedValue
variable
,
AnimatedValue
sourceVariable
)
{
if
(
variable
==
null
)
return
;
// TODO(mpcomplete): Should we handle transition from null?
AnimationPerformance
performance
=
_variableToPerformance
[
variable
];
if
(
performance
==
null
)
{
// If there's no performance, no need to animate.
if
(
sourceVariable
!=
null
)
variable
.
value
=
sourceVariable
.
value
;
return
;
}
if
(
variable
.
value
!=
sourceVariable
.
value
)
{
variable
..
begin
=
variable
.
value
..
end
=
sourceVariable
.
value
;
performance
..
progress
=
0.0
..
play
();
}
}
}
List
<
BoxShadow
>
_computeShadow
(
double
level
)
{
if
(
level
<
1.0
)
// shadows[1] is the first shadow
return
null
;
int
level1
=
level
.
floor
();
int
level2
=
level
.
ceil
();
double
t
=
level
-
level1
.
toDouble
();
List
<
BoxShadow
>
shadow
=
new
List
<
BoxShadow
>();
for
(
int
i
=
0
;
i
<
shadows
[
level1
].
length
;
++
i
)
shadow
.
add
(
lerpBoxShadow
(
shadows
[
level1
][
i
],
shadows
[
level2
][
i
],
t
));
return
shadow
;
}
packages/flutter/lib/widgets/drawer.dart
View file @
839e997e
...
...
@@ -6,6 +6,8 @@ import 'dart:sky' as sky;
import
'package:sky/animation/animated_value.dart'
;
import
'package:sky/animation/animation_performance.dart'
;
import
'package:sky/animation/curves.dart'
;
import
'package:sky/base/lerp.dart'
;
import
'package:sky/theme/shadows.dart'
;
import
'package:sky/theme/colors.dart'
as
colors
;
import
'package:sky/widgets/animated_component.dart'
;
...
...
@@ -44,6 +46,16 @@ enum DrawerStatus {
typedef
void
DrawerStatusChangedCallback
(
DrawerStatus
status
);
// TODO(mpcomplete): find a better place for this.
class
AnimatedColor
extends
AnimatedType
<
Color
>
{
AnimatedColor
(
Color
begin
,
{
Color
end
,
Curve
curve:
linear
})
:
super
(
begin
,
end:
end
,
curve:
curve
);
void
setFraction
(
double
t
)
{
value
=
lerpColor
(
begin
,
end
,
t
);
}
}
class
Drawer
extends
AnimatedComponent
{
Drawer
({
String
key
,
...
...
packages/flutter/lib/widgets/snack_bar.dart
View file @
839e997e
...
...
@@ -2,13 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:sky/animation/animation_performance.dart'
;
import
'package:sky/painting/text_style.dart'
;
import
'package:sky/theme/typography.dart'
as
typography
;
import
'package:sky/widgets/animated_component.dart'
;
import
'package:sky/widgets/basic.dart'
;
import
'package:sky/widgets/default_text_style.dart'
;
import
'package:sky/widgets/material.dart'
;
import
'package:sky/widgets/theme.dart'
;
import
'package:vector_math/vector_math.dart'
;
enum
SnackBarStatus
{
active
,
inactive
,
}
typedef
void
SnackBarStatusChangedCallback
(
SnackBarStatus
status
);
const
Duration
_kSlideInDuration
=
const
Duration
(
milliseconds:
200
);
class
SnackBarAction
extends
Component
{
SnackBarAction
({
String
key
,
this
.
label
,
this
.
onPressed
})
:
super
(
key:
key
)
{
assert
(
label
!=
null
);
...
...
@@ -29,18 +42,64 @@ class SnackBarAction extends Component {
}
}
class
SnackBar
extends
Component
{
class
SnackBar
extends
Animated
Component
{
SnackBar
({
String
key
,
this
.
content
,
this
.
actions
this
.
actions
,
this
.
showing
,
this
.
onStatusChanged
})
:
super
(
key:
key
)
{
assert
(
content
!=
null
);
}
final
Widget
content
;
final
List
<
SnackBarAction
>
actions
;
Widget
content
;
List
<
SnackBarAction
>
actions
;
bool
showing
;
SnackBarStatusChangedCallback
onStatusChanged
;
void
syncFields
(
SnackBar
source
)
{
content
=
source
.
content
;
actions
=
source
.
actions
;
onStatusChanged
=
source
.
onStatusChanged
;
if
(
showing
!=
source
.
showing
)
{
showing
=
source
.
showing
;
showing
?
_show
()
:
_hide
();
}
}
AnimatedType
<
Point
>
_position
;
AnimationPerformance
_performance
;
void
initState
()
{
_position
=
new
AnimatedType
<
Point
>(
new
Point
(
0.0
,
50.0
),
end:
Point
.
origin
);
_performance
=
new
AnimationPerformance
()
..
duration
=
_kSlideInDuration
..
variable
=
_position
..
addListener
(
_checkStatusChanged
);
watch
(
_performance
);
if
(
showing
)
_show
();
}
void
_show
()
{
_performance
.
play
();
}
void
_hide
()
{
_performance
.
reverse
();
}
SnackBarStatus
_lastStatus
;
void
_checkStatusChanged
()
{
SnackBarStatus
status
=
_status
;
if
(
_lastStatus
!=
null
&&
status
!=
_lastStatus
&&
onStatusChanged
!=
null
)
onStatusChanged
(
status
);
_lastStatus
=
status
;
}
SnackBarStatus
get
_status
=>
_performance
.
isDismissed
?
SnackBarStatus
.
inactive
:
SnackBarStatus
.
active
;
Widget
build
()
{
List
<
Widget
>
children
=
[
...
...
@@ -53,18 +112,22 @@ class SnackBar extends Component {
)
)
)
];
if
(
actions
!=
null
)
children
.
addAll
(
actions
);
return
new
Material
(
level:
2
,
color:
const
Color
(
0xFF323232
),
type:
MaterialType
.
canvas
,
child:
new
Container
(
margin:
const
EdgeDims
.
symmetric
(
horizontal:
24.0
),
child:
new
DefaultTextStyle
(
style:
new
TextStyle
(
color:
Theme
.
of
(
this
).
accentColor
),
child:
new
Flex
(
children
)
]..
addAll
(
actions
);
Matrix4
transform
=
new
Matrix4
.
identity
();
transform
.
translate
(
_position
.
value
.
x
,
_position
.
value
.
y
);
return
new
Transform
(
transform:
transform
,
child:
new
Material
(
level:
2
,
color:
const
Color
(
0xFF323232
),
type:
MaterialType
.
canvas
,
child:
new
Container
(
margin:
const
EdgeDims
.
symmetric
(
horizontal:
24.0
),
child:
new
DefaultTextStyle
(
style:
new
TextStyle
(
color:
Theme
.
of
(
this
).
accentColor
),
child:
new
Flex
(
children
)
)
)
)
);
...
...
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