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
cddf06cf
Commit
cddf06cf
authored
May 03, 2017
by
Hans Muller
Committed by
GitHub
May 03, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added scroll snapping to the gallery animation demo (#9710)
parent
6a4b08be
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
1 deletion
+60
-1
home.dart
examples/flutter_gallery/lib/demo/animation/home.dart
+59
-0
scroll_physics.dart
packages/flutter/lib/src/widgets/scroll_physics.dart
+1
-1
No files found.
examples/flutter_gallery/lib/demo/animation/home.dart
View file @
cddf06cf
...
@@ -365,6 +365,64 @@ class _AllSectionsView extends AnimatedWidget {
...
@@ -365,6 +365,64 @@ class _AllSectionsView extends AnimatedWidget {
}
}
}
}
// Support snapping scrolls to the midScrollOffset: the point at which the
// app bar's height is _kAppBarMidHeight and only one section heading is
// visible.
class
_SnappingScrollPhysics
extends
ClampingScrollPhysics
{
_SnappingScrollPhysics
({
ScrollPhysics
parent
,
this
.
midScrollOffset
})
:
super
(
parent:
parent
);
final
double
midScrollOffset
;
@override
_SnappingScrollPhysics
applyTo
(
ScrollPhysics
parent
)
{
return
new
_SnappingScrollPhysics
(
parent:
parent
,
midScrollOffset:
midScrollOffset
);
}
Simulation
_toMidScrollOffsetSimulation
(
double
offset
,
double
dragVelocity
)
{
final
double
velocity
=
math
.
max
(
dragVelocity
,
minFlingVelocity
);
return
new
ScrollSpringSimulation
(
spring
,
offset
,
midScrollOffset
,
velocity
,
tolerance:
tolerance
);
}
Simulation
_toZeroScrollOffsetSimulation
(
double
offset
,
double
dragVelocity
)
{
final
double
velocity
=
math
.
max
(
dragVelocity
,
minFlingVelocity
);
return
new
ScrollSpringSimulation
(
spring
,
offset
,
0.0
,
velocity
,
tolerance:
tolerance
);
}
@override
Simulation
createBallisticSimulation
(
ScrollMetrics
position
,
double
dragVelocity
)
{
final
Simulation
simulation
=
super
.
createBallisticSimulation
(
position
,
dragVelocity
);
final
double
offset
=
position
.
pixels
;
if
(
simulation
!=
null
)
{
// The drag ended with sufficient velocity to trigger creating a simulation.
// If the simulation is headed up towards midScrollOffset but will not reach it,
// then snap it there. Similarly if the simulation is headed down past
// midScrollOffset but will not reach zero, then snap it to zero.
final
double
simulationEnd
=
simulation
.
x
(
double
.
INFINITY
);
if
(
simulationEnd
>=
midScrollOffset
)
return
simulation
;
if
(
dragVelocity
>
0.0
)
return
_toMidScrollOffsetSimulation
(
offset
,
dragVelocity
);
if
(
dragVelocity
<
0.0
)
return
_toZeroScrollOffsetSimulation
(
offset
,
dragVelocity
);
}
else
{
// The user ended the drag with little or no velocity. If they
// didn't leave the the offset above midScrollOffset, then
// snap to midScrollOffset if they're more than halfway there,
// otherwise snap to zero.
final
double
snapThreshold
=
midScrollOffset
/
2.0
;
if
(
offset
>=
snapThreshold
&&
offset
<
midScrollOffset
)
return
_toMidScrollOffsetSimulation
(
offset
,
dragVelocity
);
if
(
offset
>
0.0
&&
offset
<
snapThreshold
)
return
_toZeroScrollOffsetSimulation
(
offset
,
dragVelocity
);
}
return
simulation
;
}
}
class
AnimationDemoHome
extends
StatefulWidget
{
class
AnimationDemoHome
extends
StatefulWidget
{
const
AnimationDemoHome
({
Key
key
})
:
super
(
key:
key
);
const
AnimationDemoHome
({
Key
key
})
:
super
(
key:
key
);
...
@@ -478,6 +536,7 @@ class _AnimationDemoHomeState extends State<AnimationDemoHome> {
...
@@ -478,6 +536,7 @@ class _AnimationDemoHomeState extends State<AnimationDemoHome> {
children:
<
Widget
>[
children:
<
Widget
>[
new
CustomScrollView
(
new
CustomScrollView
(
controller:
_scrollController
,
controller:
_scrollController
,
physics:
new
_SnappingScrollPhysics
(
midScrollOffset:
appBarMidScrollOffset
),
slivers:
<
Widget
>[
slivers:
<
Widget
>[
// Start out below the status bar, gradually move to the top of the screen.
// Start out below the status bar, gradually move to the top of the screen.
new
_StatusBarPaddingSliver
(
new
_StatusBarPaddingSliver
(
...
...
packages/flutter/lib/src/widgets/scroll_physics.dart
View file @
cddf06cf
...
@@ -13,7 +13,7 @@ import 'overscroll_indicator.dart';
...
@@ -13,7 +13,7 @@ import 'overscroll_indicator.dart';
import
'scroll_metrics.dart'
;
import
'scroll_metrics.dart'
;
import
'scroll_simulation.dart'
;
import
'scroll_simulation.dart'
;
export
'package:flutter/physics.dart'
show
Tolerance
;
export
'package:flutter/physics.dart'
show
Simulation
,
ScrollSpringSimulation
,
Tolerance
;
/// Determines the physics of a [Scrollable] widget.
/// Determines the physics of a [Scrollable] widget.
///
///
...
...
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