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
ec9ab324
Commit
ec9ab324
authored
Feb 10, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ScrollBehavior should support negative min scroll offset
Fixes #1730
parent
96405fb4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
6 deletions
+66
-6
scroll_behavior.dart
packages/flutter/lib/src/widgets/scroll_behavior.dart
+29
-6
scroll_behavior_test.dart
packages/flutter/test/widget/scroll_behavior_test.dart
+37
-0
No files found.
packages/flutter/lib/src/widgets/scroll_behavior.dart
View file @
ec9ab324
...
...
@@ -21,7 +21,6 @@ abstract class ScrollBehavior {
/// This function is called when a drag gesture ends and toSnapOffset is specified.
Simulation
createSnapScrollSimulation
(
double
startOffset
,
double
endOffset
,
double
startVelocity
,
double
endVelocity
)
=>
null
;
/// Returns the scroll offset to use when the user attempts to scroll
/// from the given offset by the given delta.
double
applyCurve
(
double
scrollOffset
,
double
scrollDelta
);
...
...
@@ -70,10 +69,31 @@ abstract class ExtentScrollBehavior extends ScrollBehavior {
/// A scroll behavior that prevents the user from exceeding scroll bounds.
class
BoundedBehavior
extends
ExtentScrollBehavior
{
BoundedBehavior
({
double
contentExtent:
0.0
,
double
containerExtent:
0.0
})
:
super
(
contentExtent:
contentExtent
,
containerExtent:
containerExtent
);
BoundedBehavior
({
double
contentExtent:
0.0
,
double
containerExtent:
0.0
,
double
minScrollOffset:
0.0
})
:
_minScrollOffset
=
minScrollOffset
,
super
(
contentExtent:
contentExtent
,
containerExtent:
containerExtent
);
double
minScrollOffset
=
0.0
;
double
_minScrollOffset
;
double
updateExtents
({
double
contentExtent
,
double
containerExtent
,
double
minScrollOffset
,
double
scrollOffset:
0.0
})
{
if
(
minScrollOffset
!=
null
)
_minScrollOffset
=
minScrollOffset
;
return
super
.
updateExtents
(
contentExtent:
contentExtent
,
containerExtent:
containerExtent
,
scrollOffset:
scrollOffset
);
}
double
get
minScrollOffset
=>
_minScrollOffset
;
double
get
maxScrollOffset
=>
math
.
max
(
minScrollOffset
,
minScrollOffset
+
_contentExtent
-
_containerExtent
);
double
applyCurve
(
double
scrollOffset
,
double
scrollDelta
)
{
...
...
@@ -118,8 +138,8 @@ class UnboundedBehavior extends ExtentScrollBehavior {
/// A scroll behavior that lets the user scroll beyond the scroll bounds with some resistance.
class
OverscrollBehavior
extends
BoundedBehavior
{
OverscrollBehavior
({
double
contentExtent:
0.0
,
double
containerExtent:
0.0
})
:
super
(
contentExtent:
contentExtent
,
containerExtent:
containerExtent
);
OverscrollBehavior
({
double
contentExtent:
0.0
,
double
containerExtent:
0.0
,
double
minScrollOffset:
0.0
})
:
super
(
contentExtent:
contentExtent
,
containerExtent:
containerExtent
,
minScrollOffset:
minScrollOffset
);
Simulation
createFlingScrollSimulation
(
double
position
,
double
velocity
)
{
return
_createFlingScrollSimulation
(
position
,
velocity
,
minScrollOffset
,
maxScrollOffset
);
...
...
@@ -148,6 +168,9 @@ class OverscrollBehavior extends BoundedBehavior {
/// A scroll behavior that lets the user scroll beyond the scroll bounds only when the bounds are disjoint.
class
OverscrollWhenScrollableBehavior
extends
OverscrollBehavior
{
OverscrollWhenScrollableBehavior
({
double
contentExtent:
0.0
,
double
containerExtent:
0.0
,
double
minScrollOffset:
0.0
})
:
super
(
contentExtent:
contentExtent
,
containerExtent:
containerExtent
,
minScrollOffset:
minScrollOffset
);
bool
get
isScrollable
=>
contentExtent
>
containerExtent
;
Simulation
createFlingScrollSimulation
(
double
position
,
double
velocity
)
{
...
...
packages/flutter/test/widget/scroll_behavior_test.dart
0 → 100644
View file @
ec9ab324
// 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:flutter/widgets.dart'
;
import
'package:test/test.dart'
;
void
main
(
)
{
test
(
'BoundedBehavior min scroll offset'
,
()
{
BoundedBehavior
behavior
=
new
BoundedBehavior
(
contentExtent:
150.0
,
containerExtent:
75.0
,
minScrollOffset:
-
100.0
);
expect
(
behavior
.
minScrollOffset
,
equals
(-
100.0
));
expect
(
behavior
.
maxScrollOffset
,
equals
(-
25.0
));
double
scrollOffset
=
behavior
.
updateExtents
(
contentExtent:
125.0
,
containerExtent:
50.0
,
scrollOffset:
-
80.0
);
expect
(
behavior
.
minScrollOffset
,
equals
(-
100.0
));
expect
(
behavior
.
maxScrollOffset
,
equals
(-
25.0
));
expect
(
scrollOffset
,
equals
(-
80.0
));
scrollOffset
=
behavior
.
updateExtents
(
minScrollOffset:
50.0
,
scrollOffset:
scrollOffset
);
expect
(
behavior
.
minScrollOffset
,
equals
(
50.0
));
expect
(
behavior
.
maxScrollOffset
,
equals
(
125.0
));
expect
(
scrollOffset
,
equals
(
50.0
));
});
}
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